Last post I showed of my wonderfully entertaining Moog style synth. This time I'm going to go into some of it in more detail.
Envelopes have troubled me for a while and mental images of stationary have not helped me understand what they do. After much study I have learned they are in fact structures that control a particular aspect of a sound over time, usually the amplitude or volume, but also filters and effects.
I use two in this synth, one to control the amplitude of the oscillators and one to control the filter.
(
SynthDef("Moog",{
arg oscType =0, oscType2 = 1, pan = 0, level = 0.5, cutoff = 500, gain = 3.3, attack = 0.1, decay = 0.1, sust = 0.7, rel = 0.2, attackf = 0.1, decayf = 0.1, sustf = 0.9, relf = 0.2, gate = 1, freq =440;
var oscArray = [Saw.ar(freq ), SinOsc.ar(freq), Pulse.ar(freq)];
var oscArray2 = [Saw.ar(freq), SinOsc.ar(freq), Pulse.ar(freq)];
var ampEnv = EnvGen.ar(Env.adsr(attack, decay, sust, rel), gate, doneAction:2);
var filterEnv = EnvGen.ar(Env.adsr(attackf, decayf, sustf, relf), gate, doneAction:2);
var osc1 = Select.ar(oscType, oscArray);
var osc2 = Select.ar(oscType2, oscArray2);
var fade = XFade2.ar(osc1, osc2, pan , level * ampEnv);
var filter = MoogFF.ar(fade, cutoff * filterEnv, gain);
Out.ar(0,filter)
}).store
)
This here is the SynthDef. I've created two arrays of oscillators which are selected by the arg osc type being passed to the Select ugen.
The envelopes are created by these two lines,
var ampEnv = EnvGen.ar(Env.adsr(attack, decay, sust, rel), gate, doneAction:2);
var filterEnv = EnvGen.ar(Env.adsr(attackf, decayf, sustf, relf), gate, doneAction:2);
I create a new envelope generator object and pass it an adsr (attack, decay, sustain release) evelope specification. The variables attack, decay, sustain and release contain the time in seconds.
var fade = XFade2.ar(osc1, osc2, pan , level * ampEnv);
var filter = MoogFF.ar(fade, cutoff * filterEnv, gain);
Here I times the output of the evnvelopes by the level of the cross fade and the cuttoff frequency of the moog filter giving me a output which is changed over time by the envelope.
No comments:
Post a Comment