About a Waveshaper in SNEX
-
Hello guys
I have 2 arrays that I measured before from a wave shaper function.
I need a wave shaper that analyses input sample and match/calculate to these lookup tables with interpolation.
For example if the input sample is between -1.0 and -0.7 (
SigInData[0] & SigInData[1]
), then the output will be calculated between -0.8 & -0.43 (SigOutData[0] & SigOutData[1]
).How can I integrate this to SNEX, please help?
const SigInData = [-1.0f, -0.7f, -0.65f, -0.5f, 0.0f, 0.5f, 0.89f, 0.96f, 1.0f]; const SigOutData = [-0.8f, -0.43f, -0.35f, -0.3f, 0.0f, 0.24f, 0.4f, 0.5f, 0.9f];
-
@harris-rosendahl The SNEX uses C++ language. For the arrays, use
span
with the corresponding variable precision. For more examples on SNEX you can compile Hise > Tools > snex_playground project and see the tons of examples.The below example will make a linear interpolation between the data. BTW, since you haven't defined any data for > 1.0 and < -1.0 statements in your lookup table, this will shape between -1.0 & 1.0. Here you go ;)
span<float, 9> SigInData = { -10.0f, -0.7f, -0.65f, -0.5f, 0.0f, 0.5f, 0.89f, 0.96f, 10.0f}; span<float, 9> SigOutData = { -0.8f, -0.43f, -0.35f, -0.3f, 0.0f, 0.24f, 0.4f, 0.5f, 0.9f}; float getSamples(float input) { for(int i = 0; i < 9; i++) { if(input >= SigOutData[i] && input < SigOutData[i+1]) { input = ((SigOutData[i+1] - SigOutData[i]) * (input - SigInData[i]) / (SigInData[i] - SigInData[i])) + SigOutData[i]; } } return input; }
-
From SNEX specific things aside, you shouldn't carry around two lookup tables, just transform them into one where you can just run the signal through. Mathematically there is no reason for two separate lookup tables and using one will heavily reduce the performance.
If you've done that, you can use a special index type in SNEX that already does the interpolation for you, but that's just syntactic sugar.
-
@Christoph-Hart said in About a Waveshaper in SNEX:
If you've done that, you can use a special index type in SNEX that already does the interpolation for you, but that's just syntactic sugar.
Interesting, is there any example for this interpolation for the above example?
-
@orange This test:
https://github.com/christophhart/HISE/blob/develop/tools/snex_playground/test_files/index/index11.h
And this C++ file has a pretty comprehensive documentation:
https://github.com/christophhart/HISE/blob/develop/hi_dsp_library/snex_basics/snex_IndexTypes.h
Although I haven't setup the doc building process to include it to the HISE docs yet.
-
@Christoph-Hart Looks very useful, thanks.
-
Thank you so much guys, really appreciate your help!