Best way to grab left & right channel data


#1

Hey Guys,

I’ve got some DSP code i’ve written which is based on per float processing (doesn’t automatically handle multichannel buffers).

I’ve been doing something kind of dirty to make sure the left and right channels don’t corrupt each other.

something like:

if (channel == 0)
{
     //Left Channel Processing
}
else if (channel == 1)
{
     //Right Channel Processing
}
else
{
   //just return data
}

is there a more robust way to get the particular channel data? or should this be fine?
I’ve been getting dead channels sometimes, trying to figure out whats going on


#2

I’m missing some context here… I’m assuming that the if/else block is happening inside the block of DSP code you’re talking about?

A possible solution (without knowing more about your problem) is to make your DSP code a C++ class that stores some kind of state (like block-to-block feedback coefficients for an IIR filter or parameters or something) and having one for each channel you want to process. That way the DSP code is shared, but the parameters/state variables are separated per channel.


#3

thanks jonathon,

this is actually right in the processBlock, my dsp code is wrapped in classes already.

I guess what I meant to ask was, is channel = 0 guaranteed to be the left channel and channel = 1 guaranteed to be the right? And if not is there a way to grab these channels specifically.


#4

To answer your question simply/directly, my experience in 99% of cases (I can’t think of an outlier off the top of my head) where you have two incoming channels, index 0 is left and index 1 is right. However, you might have something else going on if you’ve changed the default channel layouts.

If you’re using the deprecated “plugin channel configurations” option in the Projucer to lay out your input/output channels, then you’re pretty much guaranteed it will be mono/stereo/some canonical channel configuration as far as I know.

If you’re overriding setPreferredBusArrangement (the new/current/more complex way), then you’ll know what your channel layout is (via an AudioChannelSet object) and you’ll be able to figure out the index of the incoming AudioBuffer for just the left and right channels (if you have more than two coming in, say in a 5.1 configuration) to hand to your DSP code.


#5

I agree, but to be perfectly safe I would recommend to call these three steps at the beginning:

    if (busArrangement.inputBuses.size() > 0) {
        AudioChannelSet mainInput = busArrangement.inputBuses.getUnchecked (0).channels;
        const int leftInChannelSet = mainInput.getChannelIndexForType (AudioChannelSet::left);
        const int leftInProcessBuffer = busArrangement.getChannelIndexInProcessBlockBuffer (/*isInput*/ true, /*busIndex*/ 0, leftInChannelSet);
        
        if (channel == leftInProcessBuffer) {
            /* ... */
        }
    }

Then there are no assumptions, because one day the host will come, which will do everything differently… :wink:


#6

great, thanks guys!