Source code and result:
Simple frequency modulation
The synthesis of sounds by means of frequency modulation was invented and described by John Chowning in 1973 in a famous paper: "The synthesis of complex audio spectra by means of frequency modulation", Journal of the Audio Engeneering Society 21(7): 526-534. A comprehensive description for the musician is given in The Computer Music Tutorial by Curtis Roads, MIT Press.
There are two ways of realizing Chowning's process: frequency modulation and phase modulation. Simple frequency modulation and simple phase modulation are equivalent. But as soon as one chains modulations or uses feedback, there are important differences in the results of the two processes.
Simple frequency modulation is realized with sinusoid waves as carrier wave and modulator wave. The instantaneous pulsation of the modulated signal is (the "c" subscript means carrier and the "m" subscript means "modulator"). The phase angle of the signal is then given by the integral of the instantaneous phase: . The ratio defines the modulation index. The instantaneous pulsation is then written as:
So the modulated signal frequency is . It is this formula that is used in our Csound example.
Realization with Csound: the orchestra
The following intrument is used to implement the frequency modulation algorithm:
sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 idur = p3 iamp = p4 icarcps = cpspch(p5) iratio = p6 indxmul = p7 imodcps = icarcps / iratio kndx adsr 0.4, 0.5, 0.1, 0.05 ;in Frequency Modulation, modulation index depends upon modulator frequency kmod = kndx * indxmul * imodcps amod oscili 1, imodcps, 1 acar oscili 1, icarcps + kmod*amod, 1 kenv adsr 0.1, 0.2, 0.8, 0.1 out iamp * kenv * acar endin
The first ADSR envelope controls the evolution in time of the modulation index. The second ADSR envelope controls the modulated signal amplitude. Each note passes as parameters the duration, the amplitude, the pitch, the frequency ratio between carrier and modulator, and a modulation index multiplier (see next paragraph)
The simple BasicFM algorithm can be represented as a Music V style diagram. In this diagram, fixed inputs are drawn with a circle, while inputs from or outputs to an opcode are represented by semi-circles. A sinusoidal oscillator is drawn like this:
The parts specific to the frequency modulation are drawn in red. Compared to the formula, a modulation index multiplier has been added. This multiplier is in fact the modulator amplitude, but it is better to present it this way because it changes direcly the frequency displacement of the modulation by varying the modulation index:
Oscillators use a table filled with samples from one period of a sinusoid. This table is set in the score.
;single sinewave f1 0 16384 10 1 ; dur amp pch ratio mul i1 0 1 .33 8.00 1.414 1.0 i1 1 1 .33 8.04 2.0 2.0 i1 2 1 .33 8.02 4.0 2.0 i1 3 1 .33 7.07 4.0 4.0 e