| 1234567891011121314151617181920212223242526272829303132333435 |
- (
- // RGB-controlled synthesizer with amplitude envelope
- SynthDef(\rgbSynth, { |out=0, freq=440, amp=1, ampAttack=0.01, ampRelease=1,
- pitchAttack=0, pitchRelease=0, pitchRatio=2,
- redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
- var env, gate, pitchEnv, red, green, blue, sig;
- gate = \gate.kr(0);
- // Amplitude envelope
- env = EnvGen.kr(Env.adsr(ampAttack, 0, 1, ampRelease), gate);
- // Pitch envelope
- pitchEnv = EnvGen.kr(Env.adsr(pitchAttack, 0, 1, pitchRelease), gate);
- // Calculate modulated frequency
- freq = freq * (1 + (pitchEnv * (pitchRatio - 1)));
- // Different waveforms for RGB components
- red = SinOsc.ar(freq) * redAmt;
- green = Saw.ar(freq) * greenAmt;
- blue = Pulse.ar(freq, 0.5) * blueAmt;
- // Mix the waveforms
- sig = (red + green + blue) / 3;
- // Apply envelope and output
- sig = sig * env * amp;
- Out.ar(out, sig!2);
- }).add;
- "RGB-controlled synthesizer loaded".postln;
- )
|