I have a very simple function that takes an input number and scales it, if it gets below or above a certain value.
I would like to have access to it in a SynthDef and was hoping maybe turning it into a method would be a kind of workaround. Is there any way to make this function on the server-side? Maybe there is already something that works like this?
It works as a fine non-linear “waveshaping” function:
{
var a = LFSaw.ar(51 + LFNoise1.kr(0.5!2));
var b = MouseX.kr(0.1, 2.0, 1);
var c = a * (2 ** ((log2(a.abs + 0.0001) * b).round / b * a.sign.neg));
SinOsc.ar(c.range(340, 770), 0, 0.1)
}.play;
{
var a = LFNoise1.ar(51!2);
var b = MouseX.kr(0.01, 2.0, 1);
var c = a * (2 ** ((log2(a.abs + 0.000001) * b).round / b * a.sign.neg));
SinOsc.ar(c.range(340, 770), 0, 0.1)
}.play;