2b_rgb_synthdefs.scd 942 B

1234567891011121314151617181920212223242526272829303132333435
  1. (
  2. // RGB-controlled synthesizer with amplitude envelope
  3. SynthDef(\rgbSynth, { |out=0, freq=440, amp=1, ampAttack=0.01, ampRelease=1,
  4. pitchAttack=0, pitchRelease=0, pitchRatio=2,
  5. redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
  6. var env, gate, pitchEnv, red, green, blue, sig;
  7. gate = \gate.kr(0);
  8. // Amplitude envelope
  9. env = EnvGen.kr(Env.adsr(ampAttack, 0, 1, ampRelease), gate);
  10. // Pitch envelope
  11. pitchEnv = EnvGen.kr(Env.adsr(pitchAttack, 0, 1, pitchRelease), gate);
  12. // Calculate modulated frequency
  13. freq = freq * (1 + (pitchEnv * (pitchRatio - 1)));
  14. // Different waveforms for RGB components
  15. red = SinOsc.ar(freq) * redAmt;
  16. green = Saw.ar(freq) * greenAmt;
  17. blue = Pulse.ar(freq, 0.5) * blueAmt;
  18. // Mix the waveforms
  19. sig = (red + green + blue) / 3;
  20. // Apply envelope and output
  21. sig = sig * env * amp;
  22. Out.ar(out, sig!2);
  23. }).add;
  24. "RGB-controlled synthesizer loaded".postln;
  25. )