Best way to grab left & right channel data


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
   //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


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.


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.


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.


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:


great, thanks guys!