Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/SynthDesign2.ck
Created December 1, 2013 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/7727414 to your computer and use it in GitHub Desktop.
Save zeffii/7727414 to your computer and use it in GitHub Desktop.
[43,43,41-12,46, 42,45-12,47+12,47] @=> int note_array[];
repeat(6){
for(0 => int i; i<note_array.cap(); i++){
note_array[i] => int mnote;
Math.random2f(-.6, .6) => float rpan;
generate_osc("saw", mnote, rpan, 0.14, [2, 130, 12, 120]);
120::ms => now;
}
}
4::second => now;
fun void s_generate_osc(
string osc_type,
int note,
float pan,
float vgain,
int adsr[])
{
int mode;
if (osc_type=="saw") 0 => mode;
else if (osc_type=="sin") 1 => mode;
else if (osc_type=="tri") 2 => mode;
else if (osc_type=="sqr") 3 => mode;
else if (osc_type=="pls") 4 => mode;
ADSR voiceEnv;
LPF filt;
note => Std.mtof => float frequency;
SawOsc vocOscSW => filt => voiceEnv; vocOscSW.gain(0.0); frequency => vocOscSW.freq;
SinOsc vocOscSI => filt => voiceEnv; vocOscSI.gain(0.0); frequency => vocOscSI.freq;
TriOsc vocOscTR => filt => voiceEnv; vocOscTR.gain(0.0); frequency => vocOscTR.freq;
SqrOsc vocOscSQ => filt => voiceEnv; vocOscSQ.gain(0.0); frequency => vocOscSQ.freq;
PulseOsc vocOscPS => filt => voiceEnv; vocOscPS.gain(0.0); frequency => vocOscPS.freq;
adsr[0] => int a;
adsr[1] => int d;
adsr[2] => int s;
adsr[3] => int r;
voiceEnv.set( a::ms, d::ms, 0.12, r::ms );
voiceEnv => Pan2 panObj => dac;
pan => panObj.pan;
if (mode==0) vgain => vocOscSW.gain;
if (mode==1) vgain => vocOscSI.gain;
if (mode==2) vgain => vocOscTR.gain;
if (mode==3) vgain => vocOscSQ.gain;
if (mode==4) vgain => vocOscPS.gain;
// filter function taken from William Dilworth
44100/frequency => float grain;
Step s5 => ADSR filtEnv => blackhole;
filtEnv.set(3::ms, 130::ms, .1, 50::ms);
filtEnv.keyOn(1);
voiceEnv.keyOn();
(a+d)::ms + now => time later;
while(now < later)
{
filtEnv.last()*3200 => filt.freq;
grain::samp => now;
if( now > later){
(a+d)::ms => now;
voiceEnv.keyOff();
filtEnv.keyOff(1);
}
}
r*2::ms => now; // wait for tail to finish.
vocOscSW =< panObj; // disconnect to clean up
vocOscSI =< panObj; // disconnect to clean up
vocOscTR =< panObj; // disconnect to clean up
vocOscSQ =< panObj; // disconnect to clean up
vocOscPS =< panObj; // disconnect to clean up
panObj =< dac;
}
fun void generate_osc(
string osc_type,
int note,
float pan,
float vgain,
int adsr[])
{
spork ~ s_generate_osc(osc_type, note, pan, vgain, adsr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment