How to build SNEX Playground?
-
@ustk I was trying to write it out and got this:
float getSample(float input, float a) { if(input < a) { return input; } else if(input > 1) { return (a + 1) / 2; } else { return a + (input - a) / (1 + ((input - a) / (1 - a))**2); } }
definitely wrong in all sorts of cases, I haven't ventured into dsp code, and this is by far the deepest, so thanks for helping! Have one more request, how in the world do I put this into the snex code editor? I tried reading the docs on snex, but was a bit stumped. I'm trying to build a saturation in a snex shaper node with one "Saturation" control. How do I continue?
Thanks a ton!
-
@Casmat The implementation of your function looks like this:
float getSample(float s) { //return your stuff here } template <typename ProcessDataType> void process(ProcessDataType& data) { auto f = data.toFrameData(); while (f.next()) { for (auto& s: f) s = getSample(s); } } template <int C> void processFrame(span<float, C>& data) { for(auto& s: data) s = getSample(s); }
-
@Casmat And as I wrote above, the constants should be float if you don't want to get casting errors
-
@Casmat And one other thing, have you tried to plot your formula to see what you get out from it? Because it's going over the -1/+1 gain factor so you either need to scale the output or rework the formula...
-
@ustk thanks for the info! I don’t think ive done anything with the formula, i found it on music dsp and I was clueless from the start on how to get it to be a simple saturator,
is the gain factor related to the gain matching on a saturator?Edit: so the gain factor is x?
-
@Casmat So I imagine
a
is your gain, right?
What do you get as a result? Is it at least sounding "something"?
Does the level need to be tamed a bit perhaps? -
@ustk as far as I know when looking at it, I thought that x was the input signal and a was the saturation amount
-
@Casmat said in How to build SNEX Playground?:
Edit: so the gain factor is x?
f(x) means the it's the output, so a should be the gain
-
@ustk ohh yeah! Polynomials (or maybe not)!
-
@Casmat At first, does it look the way you want?
![Screenshot 2023-08-18 at 20.47.17.png](Imgur is temporarily over capacity. Please try again later.)
EDIT @Christoph-Hart @Dominik-Mayer Apparently there's still this Imgur over capacity issue that prevents us to see images...
-
@ustk why was there an float s in the arguments? And I should be declaring a as a variable, right? I put the code you gave
if (x < a) out = x; else if (x > a) out = a + (x - a) / (1.0 + Math.sqr((x - a) / (1.0 - a))); else if (x > 1) out = (a + 1.0) / 2.0;
In the get sample func?
Edit: didn’t see your post yet, the img seems broken
-
-
@Casmat if imgur is over capacity then there‘s nothing we can do except for stop uploading images :)
-
@Christoph-Hart Yeah I though it was somehow related to the forum... Or use another provider
-
-
@Casmat You definitely need to declare
a
At first, make it0.0
Then add a parameter to control it -
@ustk shouldn’t the a be from 0-1? And there were some comments under that music dsp post, do we have to do normalization or am I yapping away at nothing?
-
@Casmat and as for the image, isn’t that how the saturation should look like
-
@ustk hmm, seems like im missing part of the picture, im not really understanding the whole use of the soft saturation function vs other common saturation functions like a tanh function, have you got any resources that can help me learn more about saturation dsp or dsp in general a bit more? I feel like getting a better understanding would help me ease my way into Snex cause I have little clue what all this dsp does. Thanks for your help so far, opened my eyes to the vastness amount of info I’m missing and I’m pretty eager to learn more! After taking some time to research, it may be right to jump back at this, right?
-
@Casmat A good sounding distortion unit is much more than just the saturation function. It needs clever filtering, oversampling to remove aliasing, etc... Tanh is a good starting point, but you need to understand if you want more or less of the odd or even harmonics, or asymmetric distortion. And this is only the beginning, as a "true analog sounding" algorithm is much more... You might find some literature about this in your fav search engine. The first steps you've made is a good start! Just go for a simpler equation until you know what it does