René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

FM (frequency modulated) synthesis with CSound

In frequency modulated synthesis, the 'instrument' doesn't play on a fixed frequency, rather, the frequency is changed (=modulated) over time. The frequency that is modulated is called the carrier frequency. The carrier frequency is modulated by the modulating frequency.
Two types of FM exist: sub-audio rate and audio rate. With sub-audio rate fm, the modulating frequency is below 16 Hz (+-), and the result is a hearable variation in the carrier frequency; this is commonly referred to as vibrato.
With audio rate fm, the modulating frequency cannot be heared anymore, but so called sidebands (additional tones) are created.
Three parameters are important for FM synthesis:
  • The carrier frequency
  • the modulation ratio
    Determines the perceived harmonicity of the sound
  • the fm index
    Controls the number of sidebands (density of spectrum)
It looks like this:
basic.orc
One signal (asig_l) is produced with the foscili opcode while the other signal (asig_r) is conventionally produced, that is, with two oscilators. It also demonstrates how the parameters for foscili are used to calculate the modulator frequency, the carrier frequency and the modulator amplitude.
fm_basic.orc
sr     = 44100
kr     = 44100
nchnls = 2

instr 1;

  ilen    = p3
  iamp    = p4

  icps    = p5
  icar    = p6
  imod    = p7
  indx    = p8

  kenv     linseg 0, 0.02, 1,ilen-0.02, 0

  asig_l     foscili iamp, icps, icar, imod, indx, 1

  ;----- FM without foscili ----------------
  icar_frq    = icps     * icar
  imod_frq    = icps     * imod
  imod_amp    = imod_frq * indx
  koscil      oscili imod_amp, imod_frq, 1  
  asig_r      oscili iamp   , icar_frq + koscil, 1  
  ;---------------------------------

  outs asig_l * kenv, asig_r* kenv
endin
fm_basic.sco
f1 0 2048 10 1      ; Sine Wave

;            amp      cps     mod    mod       indx   
;----------------------------------------------------
i1  0   1    10000    100       1    2.8       6.0;    Bell?
i1  +   1    10000    100       1    2.8         <
i1  +   1    10000    100       1    2.8         <
i1  +   1    10000    100       1    2.8       3.0

i1  +   1    10000    250       1    0.7       1.5;    Bass Clarinet
i1  +   1    10000    250       1    0.7         <
i1  +   1    10000    250       1    0.7         <
i1  +   1    10000    250       1    0.7       0.1

i1  +   1    10000    700       1    1.0       5.0;    Trumpet
i1  +   1    10000    700       1    1.0         <
i1  +   1    10000    700       1    1.0         <
i1  +   1    10000    700       1    1.0       0.1

i1  +   1    10000    500       1    1.0      10.0;    FM Sound
i1  +   1    10000    500       1      <         <
i1  +   1    10000    500       1      <         <
i1  +   1    10000    500       1   10.0      10.0

;i1  +   1    10000    130      1     182      20.0
;i1  +   1    10000    130      1     182         <
;i1  +   1    10000    130      1     182         <
;i1  +   1    10000    130      1     182      20.0

Because FM is very important, CSound has two opcodes that make it easier have FM: foscil and foscili. (The foscili shows how to generate the very same sound).

Ratio between carrier and modulating frequency

FM sounds produce sidebands, that is additional frequencies below and above the carrier frequency. The distance between the frequencies of the sidebands are equal and are the same as the modulating frequency. For example, the carrier frequency could be 440Hz and the sidebands could have ..360hz, 400hz, 480hz, 520hz.. This would indicate that the modulating frequency is 40hz.
The ratio between the carrier (c) and the modulating frequency (m) plays an important role as this ratio determines the frequencies of these sidebands. If the ratio of c:m is 1:n and n is an integer, we have harmonic sidebands. If the ratio of c:m is not 1:n, we get inharmonic sidebands.
A rule is: if m >= 2*c or m=c, then c is the fundamental frequency.

FM Instruments