diff --git a/src/PluginProcessor.cpp b/src/PluginProcessor.cpp index 1583d1a1..6836f3c6 100644 --- a/src/PluginProcessor.cpp +++ b/src/PluginProcessor.cpp @@ -75,6 +75,7 @@ ValentineAudioProcessor::ValentineAudioProcessor() #if !JucePlugin_IsMidiEffect #if !JucePlugin_IsSynth .withInput ("Input", juce::AudioChannelSet::stereo(), true) + .withInput ("Sidechain", juce::AudioChannelSet::stereo(), true) #endif .withOutput ("Output", juce::AudioChannelSet::stereo(), true) #endif @@ -308,7 +309,13 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::ScopedNoDenormals noDenormals; auto totalNumInputChannels = getTotalNumInputChannels(); auto totalNumOutputChannels = getTotalNumOutputChannels(); - auto bufferSize = buffer.getNumSamples(); + + auto inputOutputBuffer = getBusBuffer (buffer, true, 0); + const auto sideChainBuffer = getBusBuffer (buffer, true, 1); + + const auto numMainInputChannels = inputOutputBuffer.getNumChannels(); + + auto bufferSize = inputOutputBuffer.getNumSamples(); auto currentSamplesPerBlock = bufferSize; if (latencyChanged.get()) @@ -321,19 +328,19 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer& buffer, // oversampling latency. Copying into the process buffer after this, then, would undo the // purpose of the delay: maintaining phase coherence between processed and unprocessed // signals. - processBuffer.setSize (totalNumOutputChannels, + processBuffer.setSize (numMainInputChannels, currentSamplesPerBlock, true, true, true); - for (auto channel = 0; channel < totalNumInputChannels; ++channel) + for (auto channel = 0; channel < numMainInputChannels; ++channel) processBuffer.copyFrom (channel, 0, - buffer.getReadPointer (channel), - buffer.getNumSamples()); + inputOutputBuffer.getReadPointer (channel), + inputOutputBuffer.getNumSamples()); - prepareInputBuffer (buffer, - totalNumInputChannels, + prepareInputBuffer (inputOutputBuffer, + numMainInputChannels, totalNumOutputChannels, currentSamplesPerBlock); @@ -342,7 +349,7 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer& buffer, return; } - inputMeterSource.measureBlock (buffer); + inputMeterSource.measureBlock (sideChainBuffer); // "Downsample" and Bitcrush processing if (crushOn.get()) @@ -428,11 +435,14 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer& buffer, auto processed = processBuffer.getSample (i, j); auto unprocessed = buffer.getSample (i, j); - buffer.setSample (i, j, mix * processed + (1.0f - currentMix) * unprocessed); + inputOutputBuffer.setSample (i, + j, + mix * processed + + (1.0f - currentMix) * unprocessed); } } - outputMeterSource.measureBlock (buffer); + outputMeterSource.measureBlock (inputOutputBuffer); } void ValentineAudioProcessor::processBlockBypassed (juce::AudioBuffer& buffer,