«Simple Frequency Modulation SynthDef» by deusofnull

on 12 Apr'16 01:37 in fmbeginnerfrequency_modulation

This is a very basic example, I know, but I found it was hard to find basic synthdefs when I was getting started.

input args are mostly self explainatory:

freq controls pitch of carrier and modulator wave

modratio scales the freq of modulator wave carratio scalese the freq of carrier wave (useful for creating different ratios of FM - carrier:modulator - ex: 1:3, 3:5, 1:9, etc )

atk, delay, sustain, rel are enelope controls for a typical ADSR envelope

modindex controls the intensity of the modulation, bigger values for modindex create more numerous sidebands

amp is the amplitude (volume)

on the line with Out.ar(0, car ! 2) car ! 2 splits the signal in two in order to be stereo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// This is a very basic example, I know, but I found it was hard 
/// to find basic synthdefs when I was getting started.  


SynthDef(\fm, {
	|freq=200, atk=0.01, decay=0.3, sustain=0.4, rel=0.1
	carratio=1,modratio=1, modindex=1,
	amp=0.2, gate=1, outBus=0|
	var env = EnvGen.kr(Env.adsr(atk, decay, sustain, rel), gate, doneAction:2);
	var mod = SinOsc.ar(freq * modratio);
	var car = SinOsc.ar(freq * carratio + (1 + (mod *modindex)), 0) * amp * env;

	Out.ar(0, car ! 2);
}).add;
)


// how to start the synth with inital values
~fmSynth = Synth.new(\fm, [\freq, 220]);
// how to alter a synth in real time
~fmSynth.set(\freq, 260);
// how to liberate the synth
~fmSynth.free;

/* design notes 
input args are mostly self explainatory: 
 freq controls pitch of carrier and modulator wave
 modratio scales the freq of modulator wave 
 carratio scalese the freq of carrier wave 
 (useful for creating different ratios of FM - carrier:modulator - ex: 1:3, 3:5, 1:9, etc )
 atk, delay, sustain, rel are enelope controls for a typical ADSR envelope 
 modindex controls the intensity of the modulation, bigger values for modindex create more numerous sidebands 
 amp is the amplitude (volume) 
 
 on the line with Out.ar(0, car ! 2) 
   car ! 2 splits the signal in two in order to be stereo 
   
   */
raw 1338 chars (focus & ctrl+a+c to copy)
reception
comments