SNEX and interpolation
-
@Christoph-Hart I'm trying to interpolate between values that are changing every 2000 samples.
But instead of the linear result, I only get spikes...float old = 0.0f; float newVal = 0.0f; int count = 0; // Sample counter float mu = 0.0f; // Sample interpolation between two values (0-1 based) /** Mono sample processing callback */ float processSample(float input) { if (count > 2000){ old = newVal; newVal = (Math.random() - 0.5f) * 2.0f; count = 0; } count++; mu = (float)(count / 2000); // Linear Interpolation val = old * (1.0f - mu) + newVal * mu; return val; }
If I just return
newVal
, it works. But As soon as I interpolate, shit happens...
I don't think the problem comes from the formula itself, but probably more the way I handle things with my poor coding...
Maybe aroundmu
orcount
... -
@ustk, have you tried it with else?
else { count++; mu = (float)(count / 2000); // Linear Interpolation val = old * (1.0f - mu) + newVal * mu; return val; }
-
@ustk Ok so the problem comes from the
old
variable that doesn't keep the value. It works on the first pass, then returns to 0,
which explains the "spikes"...
Any C++ guy to the rescue? :) -
@giftlift Oh we crossed! Thank mate I'm testing this :)
-
Ok I begin to understand. Instead of taking a reference (if it is the right term...) of a variable for the calculations, I change the variable itself so:
double thing = old * 2.0;
changes old, am I right?
Too hard form me damn C++... :)
-
No,
old
is not changed here (unless I messed something up and the compiler reused the register for the old variable). C++ behaves just like Javascript in that case :)But if I were you I wouldn't touch SNEX at the moment because it's currently rewritten from the ground up. The goal is to make it standard compliant enough so that it can compile the C++ code that is generated when you export a scriptnode patch, but that means that these
processXXX
functions will be deprecated and it will be replaced by the standard C++ API for scriptnode elements.This will lead to breaking changes also for exported nodes, but there will be a migration tool that smoothes this process (I have a lot of scriptnode FX in PercX that need to be ported too).
-
@Christoph-Hart Cool to know ;) but no worries it's good learning for me anyway regarding my level...
I'm pretty sure something wrong is happening then. Because if I just comment the line above (and '''thing''' is not used anywhere in the code) the '''old''' output is not the same so yes, the variable changed...
This will lead to breaking changes also for exported nodes, but there will be a migration tool that smoothes this process
Oh man, I hope so much!
My main project is 300 nodes and 100 parameters... If I can't reuse the graph, just give me a rope -
@Christoph-Hart I placed the interpolation process before the
if
statement and it works now. I don't understand why though...