Force mono node?
-
Sometimes you know that you definitely want a node to only process in mono.
So if I do:
static constexpr int getFixChannelAmount() { return 1; };
And then later on:
template <typename T> void process(T& data) template <typename T> void process(T& data) { auto& fd = data.template as<ProcessData<getFixChannelAmount()>>(); auto block = fd.toAudioBlock(); auto* left = block.getChannelPointer(0); auto* right = block.getChannelPointer(1); numSamples = data.getNumSamples(); // change "effect" object to StereoAudioEffect // and switch to this if stereo //effect.process(left, right, numSamples); // change "effect" object to MonoAudioEffect // and switch to this if mono //effect.process(left, numSamples); }
I would have two separate effect processor classes; MonoAudioEffect and StereoAudioEffect. Essentially wrappers around some child DSP objects.
Is this a legal approach to effectively switching between mono versus stereo processing? Should I be copying the left channel to the right channel to make things consistent with the rest of scriptnode?
-
Not sure I understand, where do you do the switch? And why do you want to switch if you know that a node is only processing a single channel?
If you're node is known to be mono, then just process the first channel in the implementation, or if you want to force a generic node to only process the first channel, you can use the
wrap::fix
template to force mono processing.// instead of this member declaration MyClass obj; // use wrap::fix<1, MyClass> obj;
Your code is probably throwing an assertion at
auto* right = block.getChannelPointer(1);
if you have created the audio block from a single channel process data object.