SynthMaker

new user, questions about ADSR code

Archive · 2011 4 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

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;

trogluddite ·

Welcome to the forum,

A description of the commands can be found in section 8 of the user guide PDF.

You'll probably also find this tutorial from the Wiki useful too - it explains how the '&' operator is used to make If..Then type statements (there are lots of those in that code!). You may find the mention of 'channels' confusing at first - but they are really nothing more than a simple form of parallel processing. When you look at a synth design, you only see one of each component, but when you play more than one note, extra 'channels' are invisibly added to each component to process the extra notes. The SSE part of your CPU can process 4 channels at the same time, so it saves lots of CPU power.

One other important point. You may want to have a play with making some simple code blocks, so that you can learn more about how they work. But note that code blocks will not work unless... 1) The code module output must have a route (however indirect) to the soundcard output (ASIO or DirectX), OR connect it to a 'Readout' module or scope. This is another cool way that SM saves CPU - by putting components to 'sleep' when disconnected. 2) The soundcard output component must be turned on (highlight one of the soundcard names). If you don't do those two things, code components will stay silent (just zero's come out).

peteproducer ·

thanks for the help.

infuzion ·

Welcome to SM peteproducer! Troggie had some good instructions. I'd like to add: [old link] [old link]

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.