SynthMaker

How to obtain a value for a variable in a codebox

Archive · 2012 7 old posts

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

distante ·

Is there a way to obtain a value in a code box?

I'm trying to make a hard limit module, something simple like IF X > Y then Z

Where Y is the threshold and Z the Limit.

Thanks!

oddson ·

streamin x; streamin y; streamin z; streamout out;

out = x>y & z;

Not sure what you mean by 'obtain a value in a code box'. But the above gives z as output when input x is greater than input y.

distante ·

I mean, if for example, I put 0.7 in a float box (that is obtained from a knob), so I want to use that 0.7 as a variable in the code box to do equations or so.

*Edit*

Oh! I see, I can use streamin, thanks 😀

Following your example, the ">" operator generate a mask don't? so, If x>y is false then out will be 0 ?? 😊

oddson ·

distante wrote: ...Following your example, the ">" operator generate a mask don't? so, If x>y is false then out will be 0 ?? 😊

Yes??

I first wrote it as if x>y then z and if x<=y then x but decided you weren't asking for that... if you were then

... out = x + (x>y) & (z - x);

distante ·

Great thanks again, Takes a little bit to understand the Mask thingy,

As I said, I'm trying to do a simple hard limiter, but I din't take in consideration that the signal is bipolar, so I pass from -1/ 1 to 0/- 1 and check if the signal vs my threshold, but I think is the wrong approach because when I go back to -1/1 the signal gets weird

streamin SignalIn; // señal de entrada streamout SignalOut; // señal de salida streamin Ceiling; float Temp;

//interpolo -1|1 to 0|1 // simplemente sumo uno y divido entre 2

Temp = (SignalIn + 1)/2;

Temp = Temp>Ceiling & Ceiling; Temp = Temp + (Temp>Ceiling) & (Ceiling - Temp); // vuelvo de 0|1 a -1|1 // Resto uno y multiplico por 2

Temp = (Temp *2) -1;

SignalOut = Temp;

trogluddite ·

distante wrote: Takes a little bit to understand the Mask thingy,

Yes - especially if, like I was, you are used to having 'If..Then..Else' type commands in other languages! The key is just to remember that... Value & False = 0; Value & True = Value; So in this case, if Size is within the celing, we get... Size = Size + (FALSE) & (Ceiling - Size) ---> Size = Size + 0 ---> Size = Size If Size is greater than the ceiling... Size = Size + (TRUE) & (Ceiling - Size) ---> Size = Size + Ceiling - Size ---> Size = Ceiling.

distante wrote: take in consideration that the signal is bipolar,

When it comes to an audio signal (+/-1), large negative numbers are equivalent to large positive numbers in terms of how 'loud' the signal is. So to find the signal level for a limiter (or compressor/overdrive etc.) what you really need is the 'size' of the peaks, regardless of whether they go up or down - the distance from zero, so to speak.

The code box has a couple of functions that are very useful for this... abs() - gets the 'absolute' value, i.e. it removes the minus sign from negative numbers. sign() - finds if a number is positive (returns 1) or negative (returns -1).

To use these for your comparator function, the code would look something like this...

streamin In; streamin Ceiling; streamout Out;

float Size; float Direction;

Size = abs(In); //Distance from zero Direction = sign(In); //Positive or Negative

Size = Size + (Size > Ceiling) & (Ceiling - Size); //Keep Size within the ceiling Out = Size * Direction; //Restore the sign so that the sample 'points' the right way.

Note that, currently, this is just a hard clipper, rather than a limiter - because there are not the attack and decay times that would even out the reaction time for a smoother sound. For those kind of functions, this little code snippet can provide the beginnings...

Size = abs(In); Direction = sign(In) Over = Size - Ceiling; //How far above ceiling Over = max(0,Over); //Over never less than zero (i.e. can be 'over' but not 'under') //NB: max(x,y) returns whichever is the biggest of two numbers Size = Size - Over; Out = Size * Direction;

This does exactly the same thing, but the 'Over' variable now tells you how far beyond the threshold the signal is - monkeying around with this number is then the key to all kinds of dynamics control.

distante ·

Thanks a lot oddson, following your tips and codes I have now a mono hard clipper, for now is all I need (protection for digital clipping).

I wrote down all the limiter/compressor considerations thought, I will need them later.

I'm on my way to pass this to a stereo Hard Clipper!

😀 thanks again ! 😀

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.