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.
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].