Skip to content

Commit

Permalink
DSP_razdelitev_v_3bande
Browse files Browse the repository at this point in the history
  • Loading branch information
kuncgregor committed Jan 30, 2022
1 parent 7b13b8e commit ffa76a6
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 51 deletions.
133 changes: 88 additions & 45 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -206,31 +221,48 @@ void Multiband_compAudioProcessor::processBlock(juce::AudioBuffer<float>& 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<float>(filterBuffers[0]);
auto fb1Block = juce::dsp::AudioBlock<float>(filterBuffers[1]);
auto fb2Block = juce::dsp::AudioBlock<float>(filterBuffers[2]);

auto fb0Ctx = juce::dsp::ProcessContextReplacing<float>(fb0Block);
auto fb1Ctx = juce::dsp::ProcessContextReplacing<float>(fb1Block);
auto fb2Ctx = juce::dsp::ProcessContextReplacing<float>(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<float>(invAPBuffer);
//auto invAPCtx = juce::dsp::ProcessContextReplacing<float>(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<float>(apBuffer);
auto apContext = juce::dsp::ProcessContextReplacing<float>(apBlock);
AP.process(apContext);


buffer.clear();
Expand All @@ -240,27 +272,24 @@ void Multiband_compAudioProcessor::processBlock(juce::AudioBuffer<float>& 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);
}
*/

}

//==============================================================================
Expand Down Expand Up @@ -303,41 +332,55 @@ juce::AudioProcessorValueTreeState::ParameterLayout Multiband_compAudioProcessor
using namespace Params;
const auto& params = GetParams();

layout.add(std::make_unique<AudioParameterFloat>(params.at(Names::Threshold_Low_Band),params.at(Names::Threshold_Low_Band),
NormalisableRange<float>(-60, 12, 1, 1),
0));
layout.add(std::make_unique<AudioParameterFloat>(
params.at(Names::Threshold_Low_Band),
params.at(Names::Threshold_Low_Band),
NormalisableRange<float>(-60, 12, 1, 1),
0));

auto attackReleseRange = NormalisableRange<float>(5, 500, 1, 1);

layout.add(std::make_unique<AudioParameterFloat>(params.at(Names::Attack_Low_Band),
layout.add(std::make_unique<AudioParameterFloat>(
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<double>{ 1,1.5,2,3,4,5,6,7,8,10,15,20,50,100 };
juce::StringArray sa;
for (auto choice : choices) {
sa.add(juce::String(choice, 1));
}

layout.add(std::make_unique<AudioParameterChoice>(params.at(Names::Ratio_Low_Band),
layout.add(std::make_unique<AudioParameterChoice>(
params.at(Names::Ratio_Low_Band),
params.at(Names::Ratio_Low_Band),
sa,
3));

layout.add(std::make_unique<AudioParameterBool>(params.at(Names::Bypassed_Low_Band),
layout.add(std::make_unique<AudioParameterBool>(
params.at(Names::Bypassed_Low_Band),
params.at(Names::Bypassed_Low_Band),
false));

layout.add(std::make_unique <AudioParameterFloat>(params.at(Names::Low_Mid_Crossover_Freq),

layout.add(std::make_unique <AudioParameterFloat>(
params.at(Names::Low_Mid_Crossover_Freq),
params.at(Names::Low_Mid_Crossover_Freq),
NormalisableRange<float>(20, 2000, 1, 1),
500));
NormalisableRange<float>(20, 999, 1, 1),
400));

layout.add(std::make_unique <AudioParameterFloat>(
params.at(Names::Mid_High_Crossover_Freq),
params.at(Names::Mid_High_Crossover_Freq),
NormalisableRange<float>(1000, 20000, 1, 1),
2000));


return layout;
Expand Down
15 changes: 9 additions & 6 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,18 @@ class Multiband_compAudioProcessor : public juce::AudioProcessor
CompressorBand compressor;

using Filter = juce::dsp::LinkwitzRileyFilter<float>;
Filter LP, HP;
// fc0 fc1
Filter LP1, AP2,
HP1, LP2,
HP2;

Filter AP;
//Filter invAP1, invAP2;
//juce::AudioBuffer<float> invAPBuffer;

juce::AudioBuffer<float> apBuffer;
juce::AudioParameterFloat* lowMidCrossover { nullptr };
juce::AudioParameterFloat* midHighCrossover { nullptr };

juce::AudioParameterFloat* lowCrossover{ nullptr };

std::array<juce::AudioBuffer<float>, 2> filterBuffers;
std::array<juce::AudioBuffer<float>, 3> filterBuffers;

//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Multiband_compAudioProcessor)
Expand Down

0 comments on commit ffa76a6

Please sign in to comment.