SynthMaker

returning absolute values

Archive · 2005 13 old posts

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

galaa ·

As I am fairly new to dsp coding and am still learning I was wondering if any of you dsp-heads would be able to help. Firstly can I just check my understanding of absolute values. If x is positive then its abs = x. If x is negative then its abs = +ve(x).

If i'm right so far. How would I go about creating abs values within the coding structure of SM

stefan ·

This checks if the value is negative and if it is we make it positive:

float val; val = -1.0; val = ((val <= 0.0) & -val) + ((val > 0.0) & val)

galaa ·

When I put this into the code component within SM the colouring stops halfway through. Does this mean that there is a problem with the syntax or will it still work?

stefan ·

Sorry, I thought the code module could handle negation of values, but it didn't. Should've tested my code before posting it, which I seldomly do. heh.

This ought to work:

float val; val = -1.0; val = ((val <= 0.0) & (0.0 - val)) + ((val > 0.0) & val)

stefan ·

malc wrote: Or did I?

[EDIT] is this thread getting confusing?

You should've never deleted your reply.

To let people know, this is what happened:

While I was writing my reply to galaa, malc also wrote a reply. He posted his before me. So after I posted mine, I replied to malcs and said "damn you, you beat me to it". When I had posted that reply, malc had removed his reply. So I removed mine, meanwhile, malc replied to my "beat me to it"-post (which I then had removed) and said "Or did I?"

And... Here we are.

edit: ok, malc removed his post....

malc ·

Like a soap opera 😉

I will refrain from deleting posts in future.

galaa ·

Cheers for that stefan. You've helped me make my first dsp component, its a waveshaper that produces pretty dark,moody overdrive and then once you get past a certain point it goes into major distortion.

polyin in; polyin drive; polyout out;

float k; k=(2*drive)/(1-drive);

float val; val=in; val = ((val <= 0.0) & (0.0 - val)) + ((val > 0.0) & val);

out=(1+k)*in/(1+k*val);

the value for drive should be in the range of 0-0.99.

Sorry if this a failry obvious piece of code but its my first so please be gentle

stefan ·

You don't need to use the "float val" btw, you could work directly on the in variable instead.

About "obvious piece of code". Most my own stuff is, imo, very basic. I prefer short simple code snippets / modules that are easily reused instead of big ones solving way too specific problems.

galaa ·

Thanks, I'll sort that now. Like you say, the shorter the better

malc ·

Great stuff 🙂

jorge ·

stefancrs wrote: You don't need to use the "float val" btw, you could work directly on the in variable instead.

That's true but if you assign straight to the "in" variable you'll be affecting any other module it is connected to. If the output connector linked to the In connector of the code component has only one link it should be no problem. I'd probably leave it using the "var" variable eventhough performance will be slightly affected.

galaa ·

Just thought, if I work on the 'in' value directly, how would this line work?

out=(1+k)*in/(1+k*val);

The 'in' for this line is not absolute so it could be negative, where as if i worked on 'in' directly then would all instances of 'in' become absolute?

stefan ·

@jorge&galaa: Oh. Yeah. Right! My bad 🙂

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.