Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidechain input #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libs/tote_bag/dsp/Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,18 @@ inline float Compressor::getMakeupGain()
return -threshold.get() * (1.0f / ratio.get() - 1.0f) / 2.0f;
}

void Compressor::process (juce::dsp::AudioBlock<float>& inAudio)
void Compressor::process (juce::dsp::AudioBlock<float>& inAudio,
juce::dsp::AudioBlock<float>* SChain)
{
makeMonoSidechain (inAudio, analysisSignal);
if (SChain)
{
makeMonoSidechain (*SChain, analysisSignal);
}
else
{
makeMonoSidechain (inAudio, analysisSignal);
}

auto numSamples = inAudio.getNumSamples();
auto numChannels = inAudio.getNumChannels();

Expand Down
2 changes: 1 addition & 1 deletion libs/tote_bag/dsp/Compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Compressor

float calculateGain (float analysisSample);

void process (juce::dsp::AudioBlock<float>& inAudio);
void process (juce::dsp::AudioBlock<float>& inAudio, juce::dsp::AudioBlock<float>* sidechain = nullptr);

float getMakeupGain();

Expand Down
64 changes: 52 additions & 12 deletions src/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,6 +84,9 @@ ValentineAudioProcessor::ValentineAudioProcessor()
, presetManager (this)
, processedDelayLine (32)
, cleanDelayLine (32)
, sidechainOversampler (2,
detail::kOversampleFactor,
Oversampling::filterHalfBandPolyphaseIIR)
#endif
{
initializeDSP();
Expand Down Expand Up @@ -253,6 +257,8 @@ void ValentineAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBl

oversampler->reset();
oversampler->initProcessing (static_cast<size_t> (samplesPerBlock));
sidechainOversampler.reset();
sidechainOversampler.initProcessing (static_cast<size_t> (samplesPerBlock));

saturator->reset (sampleRate);
boundedSaturator->reset (sampleRate);
Expand Down Expand Up @@ -308,7 +314,13 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
auto bufferSize = buffer.getNumSamples();

auto inputOutputBuffer = getBusBuffer (buffer, true, 0);
auto sideChainBuffer = getBusBuffer (buffer, true, 1);

const auto numMainInputChannels = inputOutputBuffer.getNumChannels();

auto bufferSize = inputOutputBuffer.getNumSamples();
auto currentSamplesPerBlock = bufferSize;

if (latencyChanged.get())
Expand All @@ -321,19 +333,19 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer<float>& 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);

Expand All @@ -357,16 +369,41 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
}

auto g = compressValue.get();
for (int i = 0; i < totalNumOutputChannels; ++i)
processBuffer.applyGainRamp (i, 0, bufferSize, currentGain, g);

if (sideChainBuffer.getNumChannels() > 0)
{
for (int i = 0; i < totalNumOutputChannels; ++i)
{
sideChainBuffer.applyGainRamp (i, 0, bufferSize, currentGain, g);
}
}
else
{
for (int i = 0; i < totalNumOutputChannels; ++i)
processBuffer.applyGainRamp (i, 0, bufferSize, currentGain, g);
}

// for (int i = 0; i < totalNumOutputChannels; ++i)
// processBuffer.applyGainRamp (i, 0, bufferSize, currentGain, g);

currentGain = g;

// Upsample then do non-linear processing
juce::dsp::AudioBlock<float> processBlock (processBuffer);
juce::dsp::AudioBlock<float> highSampleRateBlock =
oversampler->processSamplesUp (processBlock);

ffCompressor->process (highSampleRateBlock);
if (sideChainBuffer.getNumChannels() > 0)
{
juce::dsp::AudioBlock<float> sidechain (sideChainBuffer);
juce::dsp::AudioBlock<float> highSampleRateSideChain =
sidechainOversampler.processSamplesUp (sideChainBuffer);
ffCompressor->process (highSampleRateBlock, &highSampleRateSideChain);
}
else
{
ffCompressor->process (highSampleRateBlock);
}

if (saturateOn.get())
{
Expand Down Expand Up @@ -428,11 +465,14 @@ void ValentineAudioProcessor::processBlock (juce::AudioBuffer<float>& 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<float>& buffer,
Expand Down
1 change: 1 addition & 0 deletions src/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class ValentineAudioProcessor : public juce::AudioProcessor,
// DSP objects
std::unique_ptr<tote_bag::audio_helpers::SimpleOnePole<float>> dryWetFilter;
std::unique_ptr<Oversampling> oversampler;
Oversampling sidechainOversampler;
std::unique_ptr<Compressor> ffCompressor;
std::unique_ptr<Saturation> saturator;
std::unique_ptr<Saturation> boundedSaturator;
Expand Down
Loading