1 title:: 18_Frequency_modulation
2 summary:: Mark Polishook tutorial
3 categories:: Tutorials>Mark_Polishook_tutorial
4 related:: Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial
6 section::Carriers and modulators
8 In its simplest form, frequency modulation (FM) synthesis - famous since the Yamaha DX7 of the 1980's - uses one oscillator to modulate the frequency of another. The modulating oscillator in FM synthesis usually runs at the audio rate and its amplitude often is shaped by an envelope or other controller, such as a low frequency oscillator.
12 SynthDef("fm1", { arg bus = 0, freq = 440, carPartial = 1, modPartial = 1, index = 3, mul = 0.05;
14 // index values usually are between 0 and 24
15 // carPartial :: modPartial => car/mod ratio
23 freq * index * LFNoise1.kr(5.reciprocal).abs
27 (freq * carPartial) + mod,
40 Synth("fm1", [\bus, 0, \freq, 440, \carPartial, 1, \modPartial, 2.4]);
41 Synth("fm1", [\bus, 1, \freq, 442, \carPartial, 1, \modPartial, 2.401]);
49 section::FM synthesis and reverb
52 // ... a reverb adapted from the "01 Why SuperCollider document" in the SC2 distribution
54 SynthDef("preDelay", { arg inbus = 2;
57 DelayN.ar(In.ar(inbus, 1), 0.048, 0.048)
64 Mix.arFill(7, { CombL.ar(In.ar(4, 1), 0.1, LFNoise1.kr(Rand(0, 0.1), 0.04, 0.05), 15) })
68 SynthDef("allpass", { arg gain = 0.2;
71 4.do({ source = AllpassN.ar(source, 0.050, [Rand(0, 0.05), Rand(0, 0.05)], 1) });
78 SynthDef("theMixer", { arg gain = 1;
81 Mix.ar([In.ar(2, 1), In.ar(8, 2)]) * gain
87 Synth("fm1", [\bus, 2, \freq, 440, \carPartial, 1, \modPartial, 1.99, \mul, 0.071]);
88 Synth("fm1", [\bus, 2, \freq, 442, \carPartial, 1, \modPartial, 2.401, \mul, 0.071]);
89 Synth.tail(s, "preDelay");
90 Synth.tail(s, "combs");
91 Synth.tail(s, "allpass");
92 Synth.tail(s, "theMixer", [\gain, 0.64]);
102 Dividing the "fm" synth def into two pieces, a synthdef for a modulator and a synthdef for the carrier, gives more functionality - carrier signals can shaped by two or more modulators.
106 SynthDef("carrier", { arg inbus = 2, outbus = 0, freq = 440, carPartial = 1, index = 3, mul = 0.2;
108 // index values usually are between 0 and 24
109 // carPartial :: modPartial => car/mod ratio
114 mod = In.ar(inbus, 1);
118 SinOsc.ar((freq * carPartial) + mod, 0, mul);
122 SynthDef("modulator", { arg outbus = 2, freq, modPartial = 1, index = 3;
125 SinOsc.ar(freq * modPartial, 0, freq)
127 LFNoise1.kr(Rand(3, 6).reciprocal).abs
136 // modulators for the left channel
137 Synth.head(s, "modulator", [\outbus, 2, \freq, freq, \modPartial, 0.649, \index, 2]);
138 Synth.head(s, "modulator", [\outbus, 2, \freq, freq, \modPartial, 1.683, \index, 2.31]);
140 // modulators for the right channel
141 Synth.head(s, "modulator", [\outbus, 4, \freq, freq, \modPartial, 0.729, \index, 1.43]);
142 Synth.head(s, "modulator", [\outbus, 4, \freq, freq, \modPartial, 2.19, \index, 1.76]);
144 // left and right channel carriers
145 Synth.tail(s, "carrier", [\inbus, 2, \outbus, 0, \freq, freq, \carPartial, 1]);
146 Synth.tail(s, "carrier", [\inbus, 4, \outbus, 1, \freq, freq, \carPartial, 0.97]);
154 section::Reverberation and frequency modulation
159 // generate a random base frequency for the carriers and the modulators
160 freq = 330.0.rrand(500);
162 // modulators for the left channel
163 Synth.head(s, "modulator", [\outbus, 60, \freq, freq, \modPartial, 0.649, \index, 2]);
164 Synth.head(s, "modulator", [\outbus, 60, \freq, freq, \modPartial, 1.683, \index, 2.31]);
166 // modulators for the right channel
167 Synth.head(s, "modulator", [\outbus, 62, \freq, freq, \modPartial, 1.11, \index, 1.43]);
168 Synth.head(s, "modulator", [\outbus, 62, \freq, freq, \modPartial, 0.729, \index, 1.76]);
170 // left and right channel carriers
171 Synth.tail(s, "carrier", [\inbus, 60, \outbus, 100, \freq, freq, \carPartial, 1]);
172 Synth.tail(s, "carrier", [\inbus, 62, \outbus, 100, \freq, freq+1, \carPartial, 2.91]);
174 Synth.tail(s, "preDelay", [\inbus, 100]);
175 Synth.tail(s, "combs");
176 Synth.tail(s, "allpass");
177 Synth.tail(s, "theMixer", [\gain, 0.2]);
185 ////////////////////////////////////////////////////////////////////////////////////////////////////
187 go to link::Tutorials/Mark_Polishook_tutorial/19_Scheduling::