Scripnode 101
-
@crd I'm successfully exporting scriptnode plugins with compiled dll.
-
What's the best way to access L/R inputs to process them separately in SNEX?
Can we use arrays in SNEX?@Christoph-Hart is there an example showing how to use block?
block - a wrapper around a preallocated buffer of float numbers
When I try to initialize an index of a block with a number, I get an error saying statement cant be parsed.
-
@dustbro got it to work for the left channel only, it might be obvious why
data[1]
isn't working but I can't find...// Process the signal here template <typename ProcessDataType> void process(ProcessDataType& data) { for (auto& s: data[0]) s *= 0.5f; }
-
@dustbro oh I finally found a solution
// Process the signal here template <typename ProcessDataType> void process(ProcessDataType& data) { auto frame = data.toFrameData(); while(frame.next()) { frame[0] *= levelLeft; frame[1] *= levelRight; } }
-
@ustk Thanks! What about the function to process the input?
For instance, the SNEX shaper has:
float getSample(float input) { return input; }
Anything other than float input returns a parse error.
-
@Christoph-Hart is there a simple example that shows how to do this with an SNEX node?
-
@dustbro
getSample
is just a way to make an external function from theprocess
one, nothing prevents you to remove it and make your algorithm directly in theprocess
function, or make onegetLeftSample
and onegetRightSample
like below:float getLeftSample(float input) { return Math.tanh(input); } float getRightSample(float input) { return Math.tanh(input); } template <typename T> void process(T& data) { auto frame = data.toFrameData(); while(frame.next()) { frame[0] = getLeftSample(frame[0]); frame[1] = getRightSample(frame[1]); } }
The only thing is that this way of using
process
to separate the channels actually transforms it in a frame processing. So if you want block processing of separated channels, I don't know the trick. -
@ustk said in Scripnode 101:
if you want block processing of separated channels, I don't know the trick
Thanks again for this!
That's what I was doing, but got unexpected results. Now that I look a little closer, it appears that placing an SNEX node into a frame2_block returns a mono signal. -
@dustbro Strange indeed...
-
@ustk Looks like it's my code in processFrame. Lemme see if I can figure out the magic potion.
-
@dustbro That's what I'm doing, as you can see the output is stereo:
-
@ustk The framex_block gets it's stream from processFrame. If you leave that blank, the output will be unprocessed.
Here's the same example using an oscilloscope to see the results of placing the SNEX node into the frame block. I'm inverting one channel for easier viewing.
-
@dustbro Oh yes of course! My bad!!!
-
@dustbro Then you might not need a frame2_block, or?
-
@ustk Maybe, but without the frame2_block my DSP is glitchy and distorted.
-
@dustbro That kinda makes sense. I'm trying to get the channels in the processFrame with no luck. in fact it works for the left channel but not for the right one. I'm investigating the use of span with no more luck since yesterday...
-
@dustbro Got something! Try this:
float getLeftSample(float input) { return input; } float getRightSample(float input) { return input * 0.05f; } // Process the signal here template <typename ProcessDataType> void process(ProcessDataType& data) { } // Process the signal as frame here template <int C> void processFrame(span<float, C>& data) { for (int i = 0; i<2; i++) { auto& s = data[i]; s = i == 0 ? getLeftSample(s) : getRightSample(s); } }
-
@ustk Nice one! That's pretty close. Something about it is making the DSP process differently on each channel.
Trying my code again with just the process block seems to work now with:
auto frame = data.toFrameData();
Since the data is being converted to frame data, I no longer need to use a frame?_block.
I can now pop it into a fix_block without glitches :)
-
@dustbro Glad it works :)
But strange the last solution with the processFrame isn't working properly... -
@ustk said in Scripnode 101:
strange the last solution with the processFrame isn't working properly
agreed