SNEX channel in processFrame
-
How do we get access to the channels in a framex_block processing context?
// Process the signal as frame here template <int C> void processFrame(span<float, C>& data) { for(auto& s: data) { // process channels independently? } }
My guess is that the processFrame function is called once per channel so it is impossible, so we would need 2 nodes inside a multi... But I prefer to ask :)
-
@ustk What's wrong with
data[0] = independentProcessing(data[0])
? -
@Christoph-Hart said in SNEX channel in processFrame:
@ustk What's wrong with
data[0] = independentProcessing(data[0])
?Just me I guess...
I wonder how I couldn't see this, the presence of thespan
is obvious though...I was trying with the iterative way like in the block processing:
for(auto ch: data) { for(auto& s: data.toChannelData(ch)) { s = getNew(s); } }
-
@Christoph-Hart Hmmm... Why do I get an out of bound error on
data[1]
knowing everything is in a 2 channels node?template <int C> void processFrame(span<float, C>& data) { mono = (data[0] + data[1]) / 2.0f; }
-
@ustk @Christoph-Hart I'm getting the same error
inputL = data[0]; inputR = data[1];
constant index out of bounds (for the line containing data[1])
Also tried to upload a photo but get the error
Imgur is temporarily over capacity. Please try again later.

-
Yes that is expected behaviour (but it's definitely unintentional and maybe I'll change that during the current SNEX compiler rewrite).
When you define a process function with a templated channel count, the SNEX compiler will create functions for all channels up to the max channel amount. So if you're using it in a stereo DSP network, the snex compiler will expand this function
template <int C> void processFrame(span<float, C>& data);
to
void processFrame(span<float, 1>& data); void processFrame(span<float, 2>& data);
The rationale behind this is that the node can be used with different channel configs (so if you drag it into a multi container, it will get processed with less channels) and thus it would require a recompilation.
Now the compile error with the constant out of bound index is caused if you try to access
data[1]
in the first method, which only has a single element. What I'm usually doing here is to remove the template function and use overloading to specify the behaviour for each channel count individually (in this case it's good because if you already assume that there are two channels withdata[1]
, you can as well just type out the actual channel number). If you never expect the function to be called in a mono context (which again should be the case if you assume that there is adata[1]
element, you can leave it just empty:void processFrame(span<float, 1>& data) { // nothing to see here, move along... } void processFrame(span<float, 2>& data) { // Now you can use data[1] as much as you want... data[1] = data[1] + data[1]; data[1] *= data[1] > 0.5f ? data[1] * 2.0f : data[1] - 0.5f; data[1] = 0.0f; }
-
@Christoph-Hart suddenly it all makes sense! Thanks for the clarification :)
-
@Christoph-Hart said in SNEX channel in processFrame:
If you never expect the function to be called in a mono context (which again should be the case if you assume that there is a
data[1]
element, you can leave it just empty:How does this work with the "Support Mono FX" option? Fill both functions and just exclude data[1] in the first?