From ffa76a63f22815262a1f99fd93768233ddd42d43 Mon Sep 17 00:00:00 2001 From: Gregor Kunc Date: Sun, 30 Jan 2022 18:27:50 +0100 Subject: [PATCH] DSP_razdelitev_v_3bande --- Source/PluginProcessor.cpp | 133 ++++++++++++++++++++++++------------- Source/PluginProcessor.h | 15 +++-- 2 files changed, 97 insertions(+), 51 deletions(-) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index c88861a..e2d7e46 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -54,12 +54,19 @@ Multiband_compAudioProcessor::Multiband_compAudioProcessor() boolHelper(compressor.bypassed, Names::Bypassed_Low_Band); - floatHelper(lowCrossover, Names::Low_Mid_Crossover_Freq); + floatHelper(lowMidCrossover, Names::Low_Mid_Crossover_Freq); + floatHelper(midHighCrossover, Names::Mid_High_Crossover_Freq); - LP.setType(juce::dsp::LinkwitzRileyFilterType::lowpass); - HP.setType(juce::dsp::LinkwitzRileyFilterType::highpass); + LP1.setType(juce::dsp::LinkwitzRileyFilterType::lowpass); + HP1.setType(juce::dsp::LinkwitzRileyFilterType::highpass); - AP.setType(juce::dsp::LinkwitzRileyFilterType::allpass); + AP2.setType(juce::dsp::LinkwitzRileyFilterType::allpass); + + LP2.setType(juce::dsp::LinkwitzRileyFilterType::lowpass); + HP2.setType(juce::dsp::LinkwitzRileyFilterType::highpass); + + //invAP1.setType(juce::dsp::LinkwitzRileyFilterType::allpass); + //invAP2.setType(juce::dsp::LinkwitzRileyFilterType::allpass); } Multiband_compAudioProcessor::~Multiband_compAudioProcessor() @@ -141,11 +148,19 @@ void Multiband_compAudioProcessor::prepareToPlay (double sampleRate, int samples compressor.prepare(spec); - LP.prepare(spec); - HP.prepare(spec); + LP1.prepare(spec); + HP1.prepare(spec); + + AP2.prepare(spec); + + LP2.prepare(spec); + HP2.prepare(spec); + + //invAP1.prepare(spec); + //invAP2.prepare(spec); + + //invAPBuffer.setSize(spec.numChannels, samplesPerBlock); - AP.prepare(spec); - apBuffer.setSize(spec.numChannels, samplesPerBlock); for (auto& buffer : filterBuffers) { buffer.setSize(spec.numChannels, samplesPerBlock); @@ -206,31 +221,48 @@ void Multiband_compAudioProcessor::processBlock(juce::AudioBuffer& buffer fb = buffer; } - auto cutoff = lowCrossover->get(); - LP.setCutoffFrequency(cutoff); - HP.setCutoffFrequency(cutoff); + //invAPBuffer = buffer; - AP.setCutoffFrequency(cutoff); + auto lowMidCutoffFreq = lowMidCrossover->get(); + LP1.setCutoffFrequency(lowMidCutoffFreq); + HP1.setCutoffFrequency(lowMidCutoffFreq); + //invAP1.setCutoffFrequency(lowMidCutoffFreq); + + auto midHighCutoffFreq = midHighCrossover->get(); + AP2.setCutoffFrequency(midHighCutoffFreq); + LP2.setCutoffFrequency(midHighCutoffFreq); + HP2.setCutoffFrequency(midHighCutoffFreq); + //invAP2.setCutoffFrequency(midHighCutoffFreq); auto fb0Block = juce::dsp::AudioBlock(filterBuffers[0]); auto fb1Block = juce::dsp::AudioBlock(filterBuffers[1]); + auto fb2Block = juce::dsp::AudioBlock(filterBuffers[2]); auto fb0Ctx = juce::dsp::ProcessContextReplacing(fb0Block); auto fb1Ctx = juce::dsp::ProcessContextReplacing(fb1Block); + auto fb2Ctx = juce::dsp::ProcessContextReplacing(fb2Block); + + LP1.process(fb0Ctx); + AP2.process(fb0Ctx); + + HP1.process(fb1Ctx); + filterBuffers[2] = filterBuffers[1]; + LP2.process(fb1Ctx); - LP.process(fb0Ctx); - HP.process(fb1Ctx); + HP2.process(fb2Ctx); + + //auto invAPBlock = juce::dsp::AudioBlock(invAPBuffer); + //auto invAPCtx = juce::dsp::ProcessContextReplacing(invAPBlock); + + //invAP1.process(invAPCtx); + //invAP2.process(invAPCtx); auto numSamples = buffer.getNumSamples(); auto numChannels = buffer.getNumChannels(); - //if (compressor.bypassed->get()) - // return; + if (compressor.bypassed->get()) + return; - apBuffer = buffer; - auto apBlock = juce::dsp::AudioBlock(apBuffer); - auto apContext = juce::dsp::ProcessContextReplacing(apBlock); - AP.process(apContext); buffer.clear(); @@ -240,27 +272,24 @@ void Multiband_compAudioProcessor::processBlock(juce::AudioBuffer& buffer inputBuffer.addFrom(i, 0, source, i, 0, ns); } }; - /* - if (!compressor.bypassed->get()) { - addFilterBand(buffer, filterBuffers[0]); - addFilterBand(buffer, filterBuffers[1]); - } - else { - addFilterBand(buffer, apBuffer); - } - */ + addFilterBand(buffer, filterBuffers[0]); addFilterBand(buffer, filterBuffers[1]); + addFilterBand(buffer, filterBuffers[2]); + /* if (compressor.bypassed->get()) { for (auto ch = 0; ch < numChannels; ++ch) { - juce::FloatVectorOperations::multiply(apBuffer.getWritePointer(ch), + juce::FloatVectorOperations::multiply( + invAPBuffer.getWritePointer(ch), -1.f, numSamples); } - addFilterBand(buffer, apBuffer); + addFilterBand(buffer, invAPBuffer); } + */ + } //============================================================================== @@ -303,21 +332,25 @@ juce::AudioProcessorValueTreeState::ParameterLayout Multiband_compAudioProcessor using namespace Params; const auto& params = GetParams(); - layout.add(std::make_unique(params.at(Names::Threshold_Low_Band),params.at(Names::Threshold_Low_Band), - NormalisableRange(-60, 12, 1, 1), - 0)); + layout.add(std::make_unique( + params.at(Names::Threshold_Low_Band), + params.at(Names::Threshold_Low_Band), + NormalisableRange(-60, 12, 1, 1), + 0)); auto attackReleseRange = NormalisableRange(5, 500, 1, 1); - layout.add(std::make_unique(params.at(Names::Attack_Low_Band), + layout.add(std::make_unique( params.at(Names::Attack_Low_Band), - attackReleseRange, - 50)); + params.at(Names::Attack_Low_Band), + attackReleseRange, + 50)); - layout.add(std::make_unique < AudioParameterFloat>(params.at(Names::Release_Low_Band), + layout.add(std::make_unique < AudioParameterFloat>( + params.at(Names::Release_Low_Band), params.at(Names::Release_Low_Band), - attackReleseRange, - 250)); + attackReleseRange, + 250)); auto choices = std::vector{ 1,1.5,2,3,4,5,6,7,8,10,15,20,50,100 }; juce::StringArray sa; @@ -325,19 +358,29 @@ juce::AudioProcessorValueTreeState::ParameterLayout Multiband_compAudioProcessor sa.add(juce::String(choice, 1)); } - layout.add(std::make_unique(params.at(Names::Ratio_Low_Band), + layout.add(std::make_unique( + params.at(Names::Ratio_Low_Band), params.at(Names::Ratio_Low_Band), sa, 3)); - layout.add(std::make_unique(params.at(Names::Bypassed_Low_Band), + layout.add(std::make_unique( + params.at(Names::Bypassed_Low_Band), params.at(Names::Bypassed_Low_Band), false)); - layout.add(std::make_unique (params.at(Names::Low_Mid_Crossover_Freq), + + 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)); + NormalisableRange(20, 999, 1, 1), + 400)); + + layout.add(std::make_unique ( + params.at(Names::Mid_High_Crossover_Freq), + params.at(Names::Mid_High_Crossover_Freq), + NormalisableRange(1000, 20000, 1, 1), + 2000)); return layout; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 8e04ca9..abbc955 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -164,15 +164,18 @@ class Multiband_compAudioProcessor : public juce::AudioProcessor CompressorBand compressor; using Filter = juce::dsp::LinkwitzRileyFilter; - Filter LP, HP; + // fc0 fc1 + Filter LP1, AP2, + HP1, LP2, + HP2; - Filter AP; + //Filter invAP1, invAP2; + //juce::AudioBuffer invAPBuffer; - juce::AudioBuffer apBuffer; + juce::AudioParameterFloat* lowMidCrossover { nullptr }; + juce::AudioParameterFloat* midHighCrossover { nullptr }; - juce::AudioParameterFloat* lowCrossover{ nullptr }; - - std::array, 2> filterBuffers; + std::array, 3> filterBuffers; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Multiband_compAudioProcessor)