peteproducer ·
Hello everyone, I am a new SynthMaker user and am currently trying to understand how the ADSR code works. I have some pretty basic doubts like what exactly is the streamin and streamout, hop, etc. If there is a part in the manual or a tutorial explaining this, please send me the link. I appreciate any help.
ADSR code:
streamin env; streamboolin fastRelease; streamin a; streamin d; streamin s; streamin r; streamboolin smoothRetrig; streamboolout done; streamout out;
float cnt,val,oldVal,tmp,inc; float adLen; float aStep,dStep,rStep; float stage,off;
hop(16) { // Make A,D & R at least 16 samples a = (a < 16)&16 + (a >= 16)&a; d = (d < 16)&16 + (d >= 16)&d; r = (r < 16)&16 + (r >= 16)&r;
// Force A,D,R to be multiples of 16 tmp = 0.0625*a - 0.4999; a = 16*rndint(tmp); tmp = 0.0625*d - 0.4999; d = 16*rndint(tmp); tmp = 0.0625*r - 0.4999; r = 16*rndint(tmp);
// Get Attack/Decay step sizes aStep = 16/a; dStep = 16/d * (1-s);
// Length of attack + decay adLen = a + d; }
// Reset on retrigger or if no gate cnt = cnt&((env==0)|(env>1)); off = off&((env==0)|(env>1)); val = val&((env==0)|(env>1)) + val&(env==1)&smoothRetrig; val = val&(cnt>0 | smoothRetrig);
// Only calculate every 16 samples hop(16) { out = val;
// Find out which stage we're in stage = (cnt >= a)&1 + (cnt >= adLen)&1; stage = (env!=4.0)&stage + (env>=4)&4;
// Save old value oldVal = val;
// Get new value val = val + (stage==0)&aStep - (stage==1)&dStep - (stage==4)&rStep; val = (stage==2)&s + (stage!=2)&val; val = min(val,1);
// Need to calc rstep from new val but not after we'e in release rStep = (16/r * val)&(stage<4) + rStep&(stage>=4) + (0.001*val)&(fastRelease);
// Calculate interpolation increment inc = 0.0625*(val - oldVal)&(env>=0); }
// Increment envelope out = max(out + inc,0);
// Remember the last value val = out;
// Increment sample counter and check done cnt = cnt + (stage<2)&1; done = (out<=0)&(env>3)&(off==0);
// Record whether env is on or off now off = done&1 + off;