Multichannel beheavior


#1

Hello all,

In the past I made plugins with the next kind of processblock:

void PluginProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{

    if (buffer.getNumChannels() == 6)
        {
            i1 = buffer.getWritePointer(0);
            i2 = buffer.getWritePointer(1);
            i3 = buffer.getWritePointer(2);
            i4 = buffer.getWritePointer(3);
            i5 = buffer.getWritePointer(4);
            i6 = buffer.getWritePointer(5);
        }

    if (buffer.getNumChannels() == 2)
        {
            i1 = buffer.getWritePointer(0);
            i2 = buffer.getWritePointer(1);
        }

    if (buffer.getNumChannels() == 1)
        {
            i1 = buffer.getWritePointer(0);
        }




  for (int i = 0; i < sampleframes; i++)
  {
             do something with the inputchannels mixing them, for example
                 outleft = i1 + i2;
             
          if (buffer.getNumChannels()==6)
          {
            {
         *i1++ = fmix * outleft 
                *i2++ = fmix * outright 
                *i3++ = fmix * 0.5f * (outleft + outright) 
                *i4++ = 0.f;
                *i5++ = fmix * outleft 
                *i6++ = fmix * outright 
              }
            
             }
        }

And it worked. But I saw that is probably a lot neater to use the form with channels increasing and then processing the samples. Like from the Juce Demo Plugin:

for (channel = 0; channel < getNumInputChannels(); ++channel)
{
float* channelData = buffer.getWritePointer (channel);
float* delayData = delayBuffer.getWritePointer (jmin (channel, delayBuffer.getNumChannels() - 1));
dp = delayPosition;

    for (int i = 0; i < numSamples; ++i)
    {
        const float in = channelData[i];
        channelData[i] += delayData[dp];
        delayData[dp] = (delayData[dp] + in) * delay->getValue();
        if (++dp >= delayBuffer.getNumSamples())
            dp = 0;
    }
}

What is the best way to do some processing on different channels at the same sampletime? Arrays that are filled with information from first channel and then doing some work on the second channel, etc?

Kind regards,

Harrie