How to properly use another busses in processBlock

Sorry, but I have very small experience with more than one main bus.
I suppose that it is better (and faster) to not copy whole buffer from each bus, so I decided to create reference for each bus, and it looks like that:

void MyAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
	AudioBuffer<float> &_input = getBusBuffer(buffer, true, 0);
	AudioBuffer<float> &_sideChain = getBusBuffer(buffer, true, 1);

Is it good routine? Or is there anything more efficient?\

And the other question is: Of course I want use _sideChain bus only if there is any input defined in host, else I want to use only _input. What is the best way to verify that?

Should I do something like that:

for(int channel=0; channel<numInputChannels; channel++)
     if(_sideChain.getMagnitude(channel, 0, _sideChain.getNumSamples() > 0.0f)
          // use _sideChain 
          // use _input

Intuition tells me it’s not good solution. And it’s not efficient to check each samples in each buffer. So could anyone help me and tell what is the best solution to do such things?

For any help thanks in advance.

getBusBuffer returns a value, not a reference. So you need:

AudioBuffer<float> _input = getBusBuffer(buffer, true, 0);


Or easier:

auto _input = getBusBuffer(buffer, true, 0);

It doesn’t copy the buffer, just creates a new AudioBuffer pointing at the existing audio data.

I think you may have to have a switch in your plugin to determine whether the sidechain should be used. I’m not sure you can always detect whether the user has routed audio to it (if the audio could be silent anyway).

1 Like

I’ve already figure it out how to use getBusBuffer, but anyway great thanks for your reply.
And you’ve discovered my next issue. Now I try to understand sidechain behaviour.

1 Like