Skip to content

Commit

Permalink
dodan_lowcut
Browse files Browse the repository at this point in the history
  • Loading branch information
kuncgregor committed Jan 30, 2022
1 parent cb77de4 commit 95dfe8a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
57 changes: 52 additions & 5 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -167,10 +179,10 @@ bool Multiband_compAudioProcessor::isBusesLayoutSupported (const BusesLayout& la
}
#endif

void Multiband_compAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
void Multiband_compAudioProcessor::processBlock(juce::AudioBuffer<float>& 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
Expand All @@ -180,10 +192,41 @@ void Multiband_compAudioProcessor::processBlock (juce::AudioBuffer<float>& 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<float>(filterBuffers[0]);
auto fb1Block = juce::dsp::AudioBlock<float>(filterBuffers[1]);

auto fb0Ctx = juce::dsp::ProcessContextReplacing<float>(fb0Block);
auto fb1Ctx = juce::dsp::ProcessContextReplacing<float>(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]);
}

//==============================================================================
Expand Down Expand Up @@ -257,6 +300,10 @@ juce::AudioProcessorValueTreeState::ParameterLayout Multiband_compAudioProcessor
params.at(Names::Bypassed_Low_Band),
false));

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));


return layout;
Expand Down
12 changes: 11 additions & 1 deletion Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ namespace Params {
inline const std::map<Names, juce::String>& GetParams() {

static std::map<Names, juce::String> 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"},
Expand Down Expand Up @@ -160,6 +162,14 @@ class Multiband_compAudioProcessor : public juce::AudioProcessor
private:

CompressorBand compressor;

using Filter = juce::dsp::LinkwitzRileyFilter<float>;
Filter LP, HP;

juce::AudioParameterFloat* lowCrossover{ nullptr };

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

//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Multiband_compAudioProcessor)
};

0 comments on commit 95dfe8a

Please sign in to comment.