home *** CD-ROM | disk | FTP | other *** search
/ Audio Version 4.94 / audioversion4.94knowledgemediaresourcelibraryoctober1994.iso / unix / midi_doc / pm_intro < prev    next >
Text File  |  1993-02-08  |  4KB  |  91 lines

  1. Article 3975 of rec.music.synth:
  2. Path: ulowell!m2c!husc6!cs.utexas.edu!ut-sally!utastro!james
  3. From: james@utastro.UUCP (James McCartney)
  4. Newsgroups: rec.music.synth
  5. Subject: Phase Modulation
  6. Keywords: synth
  7. Message-ID: <2773@utastro.UUCP>
  8. Date: 14 Jun 88 16:49:46 GMT
  9. Organization: U. Texas, Astronomy, Austin, TX
  10. Lines: 77
  11.  
  12.  
  13.    Several people have requested this. Besides, it's good fer ya!
  14.  
  15.    Despite the fact that Yamaha claims to be making FM synthesizers, the 
  16. implementation on their chips is actually Phase Modulation. I can testify to
  17. this because I have had a  chance to see the data books on these chips.
  18.    The difference between FM & PM in a digital oscillator is that FM is added
  19. to the frequency before the phase integration, while PM is added to the phase
  20. after the phase integration. Phase integration is when the old phase for the 
  21. oscillator is added to the current frequency (in radians per sample) to get
  22. the new phase for the oscillator. The equivalent PM modulator to obtain the
  23. same waveform as FM is the integral of the FM modulator. Since the integral
  24. of sine waves are inverted cosine waves this is no problem. In modulators
  25. with multiple partials, the equivalent PM modulator will have different 
  26. relative partial amplitudes. For example, the integral of a square wave is
  27. a triangle wave; they have the same harmonic content, but the relative partial
  28. amplitudes are different. These differences make no difference since we are
  29. not trying to exactly recreate FM, but real (or nonreal) instruments.
  30.    The reason PM is better
  31. is because in PM and FM there can be non-zero energy produced at 0 Hz,
  32. which in FM will produce a shift in pitch if the FM wave is used again as a
  33. modulator, however in PM the DC component will only produce a phase shift.
  34. Another reason PM is better is that the modulation index (which determines the
  35. number of sidebands produced and which in normal FM is calculated as the
  36. modulator amplitude divided by frequency of modulator) is not dependant on
  37. the frequency of the modulator, it is always equal to the amplitude of the
  38. modulator in radians. The benefit of solving the DC frequency shift problem,
  39. is that cascaded carrier-modulator pairs and feedback modulation are possible.
  40. The simpler calculation of modulation index makes it easier to have voices
  41. keep the same harmonic structure throughout all pitches.
  42.    The basic mathematics of phase modulation are available in any text on
  43. electronic communication theory.
  44.    Below is some C code for a digital oscillator that implements FM,PM,and AM.
  45. It illustrates the difference in implementation of FM & PM. It is only meant
  46. as an example, and not as an efficient implementation.
  47.  
  48.  
  49. /* Example implementation of digital oscillator with FM, PM, & AM */
  50.  
  51. #define PI 3.14159265358979
  52. #define RADIANS_TO_INDEX (512.0 / (2.0 * PI)) 
  53.  
  54. typedef struct {  /* oscillator data */
  55.    double freq;   /* oscillator frequency in radians per sample */
  56.    double phase;  /* accumulated oscillator phase in radians */
  57.    double wavetable[512]; /* waveform lookup table */
  58. } OscilRec;
  59.  
  60.  
  61. /* oscil - compute 1 sample of oscillator output whose freq. phase and 
  62.  *    wavetable are in the OscilRec structure pointed to by orec.
  63.  */
  64. double oscil(orec, fm, pm, am) 
  65.    OscilRec *orec;  /* pointer to the oscil's data */
  66.    double fm; /* frequency modulation input  in radians per sample */
  67.    double pm; /* phase modulation input      in radians */
  68.    double am; /* amplitude modulation input  in any units you want */
  69. {
  70.    long tableindex;            /* index into wavetable */
  71.    double instantaneous_freq;  /* oscillator freq  + freq  modulation */
  72.    double instantaneous_phase; /* oscillator phase + phase modulation */
  73.    double output;              /* oscillator output */
  74.  
  75.    instantaneous_freq  = orec->freq  + fm; /* get instantaneous freq */
  76.    orec->phase += instantaneous_freq;      /* accumulate phase */
  77.    instantaneous_phase = orec->phase + pm; /* get instantaneous phase */
  78.  
  79.       /* convert to lookup table index */
  80.    tableindex = RADIANS_TO_INDEX * instantaneous_phase; 
  81.    tableindex &= 511; /* make it mod 512 === eliminate multiples of 2*k*PI */
  82.  
  83.    output = orec->wavetable[tableindex] * am; /* lookup and mult by am input */
  84.  
  85.    return (output);  /* return oscillator output */
  86. }
  87.  
  88. --------------- James McCartney --- Austin, Tx 
  89.  
  90.  
  91.