Play input and audio file simultaniously


Hey guys, I’m stuck with mixing together 2 audio buffers.

I have a plugin that should play a soundfile on top of what is coming from the input channels.

I start by duplicating the input Buffer. then adding the soundfile to the actual buffer.
Now I’m stuck. However I try to mix the two buffers together the input is still muted.

void PomodoroAudioProcessor::processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
ScopedNoDenormals noDenormals;
auto totalNumInputChannels  = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
const int numSamples = buffer.getNumSamples();
AudioBuffer<float>& inputBuffer = buffer;

for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    buffer.clear (i, 0, buffer.getNumSamples());

for (int channel = 0; channel < totalNumInputChannels; ++channel)
    auto* channelData = buffer.getWritePointer(channel);

    // something to the data...
    for(int i=0; i<numSamples; i++)
        if (muteBreakButtonState && isBreak) {                                          // if mute is enabled on break
            channelData[i] = 0;




You are clearing the buffer right after you have got the audio from your transport source! (AudioBuffer& inputBuffer = buffer; does not make a copy of the buffer, it just makes inputBuffer refer to the same buffer.)

You will need to use a separate AudioBuffer to get the audio from the transport source and then mix together that buffer and the plugin input buffer. (Note that the transport source read buffer should be a member variable of your AudioProcessor, you should not allocate a new each time the processBlock method is called.)


I realized my mistake about not using a separate Audiobuffer and clearing it.

Thanks for the hint about the member variable! That could have gone wrong!