1 declare name "envelop";
3 declare author "Grame";
5 declare copyright "(c)GRAME 2006";
9 //-------------------------------------------------
10 // ADSR Envelop Generator
11 // The 'state' of the envelop generator is
12 // defined by a phase signal p2 allowing to
13 // distinguish the attack and the decay-sustain
14 // phases, and the envelop signal y itself.
15 //-------------------------------------------------
17 envelop(a,d,s,r,t) = adsr ~ (_,_) : (!,_) // The 2 'state' signal are feedback
19 adsr (p2,y) = (t>0) & (p2|(y>=1)), // p2 = decay-sustain phase
20 y + p1*a - (p2&(y>s))*d*y - p3*r*y // y = envelop signal
22 p1 = (p2==0) & (t>0) & (y<1); // p1 = attack phase
23 p3 = (t<=0) & (y>0); // p3 = release phase
28 attack = 1.0/(SR*nentry("[1:]attack [unit:ms][style:knob]", 20, 1, 1000, 1)/1000);
29 decay = nentry("[2:]decay[style:knob]", 2, 1, 100, 0.1)/100000;
30 sustain = nentry("[3:]sustain [unit:pc][style:knob]", 10, 1, 100, 0.1)/100;
31 release = nentry("[4:]release[style:knob]", 10, 1, 100, 0.1)/100000;
34 process = button("play"): hgroup("", envelop(attack, decay, sustain, release) : *(noise));