diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index f192ae4..9e45db4 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -53,6 +53,11 @@ Multiband_compAudioProcessor::Multiband_compAudioProcessor() }; boolHelper(compressor.bypassed, Names::Bypassed_Low_Band); + + floatHelper(lowCrossover, Names::Low_Mid_Crossover_Freq); + + LP.setType(juce::dsp::LinkwitzRileyFilterType::lowpass); + HP.setType(juce::dsp::LinkwitzRileyFilterType::highpass); } Multiband_compAudioProcessor::~Multiband_compAudioProcessor() @@ -133,6 +138,13 @@ void Multiband_compAudioProcessor::prepareToPlay (double sampleRate, int samples spec.sampleRate = sampleRate; compressor.prepare(spec); + + LP.prepare(spec); + HP.prepare(spec); + + for (auto& buffer : filterBuffers) { + buffer.setSize(spec.numChannels, samplesPerBlock); + } } void Multiband_compAudioProcessor::releaseResources() @@ -167,10 +179,10 @@ bool Multiband_compAudioProcessor::isBusesLayoutSupported (const BusesLayout& la } #endif -void Multiband_compAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) +void Multiband_compAudioProcessor::processBlock(juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) { juce::ScopedNoDenormals noDenormals; - auto totalNumInputChannels = getTotalNumInputChannels(); + auto totalNumInputChannels = getTotalNumInputChannels(); auto totalNumOutputChannels = getTotalNumOutputChannels(); // In case we have more outputs than inputs, this code clears any output @@ -180,10 +192,41 @@ void Multiband_compAudioProcessor::processBlock (juce::AudioBuffer& buffe // when they first compile a plugin, but obviously you don't need to keep // this code if your algorithm always overwrites all the output channels. for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i) - buffer.clear (i, 0, buffer.getNumSamples()); + buffer.clear(i, 0, buffer.getNumSamples()); + + //compressor.updateCompressorSettings(); + //compressor.process(buffer); + + for (auto& fb : filterBuffers) { + fb = buffer; + } + + auto cutoff = lowCrossover->get(); + LP.setCutoffFrequency(cutoff); + HP.setCutoffFrequency(cutoff); + + auto fb0Block = juce::dsp::AudioBlock(filterBuffers[0]); + auto fb1Block = juce::dsp::AudioBlock(filterBuffers[1]); + + auto fb0Ctx = juce::dsp::ProcessContextReplacing(fb0Block); + auto fb1Ctx = juce::dsp::ProcessContextReplacing(fb1Block); + + LP.process(fb0Ctx); + HP.process(fb1Ctx); + + auto numSamples = buffer.getNumSamples(); + auto numChannels = buffer.getNumChannels(); + + buffer.clear(); + + auto addFilterBand = [nc = numChannels, ns = numSamples](auto& inputBuffer, const auto& source) { + for (auto i = 0; i < nc; ++i) { + inputBuffer.addFrom(i, 0, source, i, 0, ns); + } + }; - compressor.updateCompressorSettings(); - compressor.process(buffer); + addFilterBand(buffer, filterBuffers[0]); + addFilterBand(buffer, filterBuffers[1]); } //============================================================================== @@ -257,6 +300,10 @@ juce::AudioProcessorValueTreeState::ParameterLayout Multiband_compAudioProcessor params.at(Names::Bypassed_Low_Band), false)); + layout.add(std::make_unique (params.at(Names::Low_Mid_Crossover_Freq), + params.at(Names::Low_Mid_Crossover_Freq), + NormalisableRange(20, 2000, 1, 1), + 500)); return layout; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index a0adb90..86be748 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -41,8 +41,10 @@ namespace Params { inline const std::map& GetParams() { static std::map params = { + + {Low_Mid_Crossover_Freq, "Low-Mid Crossover Freq"}, - {Mid_High_Crossover_Freq, "Mid_High_Crossover_Freq"}, + {Mid_High_Crossover_Freq, "Mid-High Crossover_Freq"}, {Threshold_Low_Band, "Threshold Low Band"}, {Threshold_Mid_Band, "Threshold Mid Band"}, @@ -160,6 +162,14 @@ class Multiband_compAudioProcessor : public juce::AudioProcessor private: CompressorBand compressor; + + using Filter = juce::dsp::LinkwitzRileyFilter; + Filter LP, HP; + + juce::AudioParameterFloat* lowCrossover{ nullptr }; + + std::array, 2> filterBuffers; + //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Multiband_compAudioProcessor) };