How to DSP process only specific channels of a buffer

So I am still working on my first synthesizer, on it’s way to become one that may have more waveform manipulation than man (and woman, and hermaphrodite) have ever seen before, so far having 20 ways to manipulate duty cycle, 27 modulation types (several variations of each; AM, RM, PD, PM, and FM), 11 wave shaping types, and 8 wave morphing types, all with one or more ways of adjusting effect, and all individually on 8 tone generators each up to 16 unison voices.

Anyways I am now implementing a few simple JUCE DSP effects, first being the Reverb.

So the below works;

  tgTempBuffer.copyFrom (0, 0, TGBuffer.getReadPointer (channelLeft), buffer.getNumSamples ());
  tgTempBuffer.copyFrom (1, 0, TGBuffer.getReadPointer (channelRight), buffer.getNumSamples ());

  dsp::AudioBlock<float> output0 (tgTempBuffer);
  dsp::ProcessContextReplacing<float> context0 (output0);
  processorChain[tg].process (context0);

  TGBuffer.copyFrom(channelLeft, 0, tgTempBuffer.getReadPointer(0), buffer.getNumSamples ());
  TGBuffer.copyFrom (channelRight, 0, tgTempBuffer.getReadPointer (1), buffer.getNumSamples ());

What I doing here is only adding reverb on one tone generator (tg) numbered 0 through 7, at a time as the user specifies. TGBuffer has 16 channels, 8 stereo pairs. So tone generator one occupies channels 0-1, two occupies 2-3, and so on.

In the above code I copy a stereo pair from TGBuffer, one channel at a time, so two for a stereo pair, to a temp buffer, invoke the reverb processing, and then copy the temp buffer back to the TGBuffer. So for example to process reverb on first tone generator (0), variables channelLeft = 0, and channelRight = 1.

So my question is, is there a way to avoid that copying, so the DSP reverb only processes specific channels of any given buffer?

get the only the channels you wanna process from that output0 block before processing?

Do the audio block on the actual buffer without making a temp copy, point it to the correct channels to process

1 Like

Thank you very much. Not your fault, but I feel rather foolish now for forgetting to check the documentation.

So for anyone else trying to do the something similar, here is what works as a charm (compared to the above):

  dsp::AudioBlock<float> output0 (TGBuffer);
  dsp::ProcessContextReplacing<float> context0 (output0.getSubsetChannelBlock(channelLeft, 2));
  processorChain[tg].process (context0);

no problem ! imo the DSP blocks and processor chains are a bit confusing. I tend to stray away from them as much as possible as well, just experienced this same issue :sweat_smile: