Skip to content

Commit

Permalink
dynamically allocate Spectrum Analysers for bandsplitter
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke committed Dec 24, 2023
1 parent 3622ea1 commit 3a33647
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 40 deletions.
17 changes: 17 additions & 0 deletions src/dsp/BandSplitter/BandSplitterProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ void BandSplitterProcessor::prepare (const juce::dsp::ProcessSpec& spec)
[spec] (auto&& filter)
{ filter.prepare (spec); });

lowPreSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
lowPostSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
midPreSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
midPostSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
highPreSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
highPostSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
}

void BandSplitterProcessor::processBlock (const chowdsp::BufferView<const float>& bufferIn,
Expand All @@ -32,7 +36,11 @@ void BandSplitterProcessor::processBlock (const chowdsp::BufferView<const float>
return;

if (extraState.isEditorOpen.load() && extraState.showPreSpectrum.get())
{
lowPreSpectrumAnalyserTask.processBlockInput (bufferLow.toAudioBuffer());
midPreSpectrumAnalyserTask.processBlockInput (bufferMid.toAudioBuffer());
highPreSpectrumAnalyserTask.processBlockInput (bufferHigh.toAudioBuffer());
}

const auto processTwoBandFilter = [&] (auto& filter)
{
Expand Down Expand Up @@ -66,12 +74,21 @@ void BandSplitterProcessor::processBlock (const chowdsp::BufferView<const float>
{
processCrossover (threeBandFilters, processThreeBandFilter);
if (extraState.isEditorOpen.load() && extraState.showPostSpectrum.get())
{
lowPostSpectrumAnalyserTask.processBlockInput(bufferLow.toAudioBuffer());
midPostSpectrumAnalyserTask.processBlockInput (bufferMid.toAudioBuffer());
highPostSpectrumAnalyserTask.processBlockInput (bufferHigh.toAudioBuffer());
}
}
else
{
bufferMid.clear();
processCrossover (twoBandFilters, processTwoBandFilter);
if (extraState.isEditorOpen.load() && extraState.showPostSpectrum.get())
{
lowPostSpectrumAnalyserTask.processBlockInput (bufferLow.toAudioBuffer());
highPostSpectrumAnalyserTask.processBlockInput (bufferHigh.toAudioBuffer());
}
}
}
} // namespace dsp::band_splitter
29 changes: 28 additions & 1 deletion src/dsp/BandSplitter/BandSplitterProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ class BandSplitterProcessor
public:
explicit BandSplitterProcessor (const Params& bandSplitParams, const ExtraState& extraState) : params (bandSplitParams), extraState (extraState)
{
lowPreSpectrumAnalyserTask.SpectrumAnalyserUITask.setDBRange (-60, 5);
lowPostSpectrumAnalyserTask.SpectrumAnalyserUITask.setDBRange (-60, 5);
midPreSpectrumAnalyserTask.SpectrumAnalyserUITask.setDBRange (-60, 5);
midPostSpectrumAnalyserTask.SpectrumAnalyserUITask.setDBRange (-60, 5);
highPreSpectrumAnalyserTask.SpectrumAnalyserUITask.setDBRange (-60, 5);
highPostSpectrumAnalyserTask.SpectrumAnalyserUITask.setDBRange (-60, 5);
}

void prepare (const juce::dsp::ProcessSpec& spec);
Expand All @@ -80,11 +84,29 @@ class BandSplitterProcessor
const chowdsp::BufferView<float>& bufferMid,
const chowdsp::BufferView<float>& bufferHigh);

std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> getSpectrumAnalyserTasks()

std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> getSpectrumAnalyserTasksLow()
{
return { std::ref (lowPreSpectrumAnalyserTask.SpectrumAnalyserUITask), std::ref (lowPostSpectrumAnalyserTask.SpectrumAnalyserUITask) };
}

std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> getSpectrumAnalyserTasksMid()
{
return { std::ref (midPreSpectrumAnalyserTask.SpectrumAnalyserUITask), std::ref (midPostSpectrumAnalyserTask.SpectrumAnalyserUITask) };
}

std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> getSpectrumAnalyserTasksHigh()
{
return { std::ref (highPreSpectrumAnalyserTask.SpectrumAnalyserUITask), std::ref (highPostSpectrumAnalyserTask.SpectrumAnalyserUITask) };
}

// static std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> getSpectrumAnalyserTasks(gui::SpectrumAnalyserTask::Optional preTask,
// gui::SpectrumAnalyserTask::Optional postTask)
// {
// return {preTask.has_value() ? std::ref (preTask).get() :std::nullopt,
// postTask.has_value() ? std::ref (postTask).get() : std::nullopt };
// }

private:
const Params& params;
const ExtraState& extraState;
Expand All @@ -107,8 +129,13 @@ class BandSplitterProcessor
chowdsp::ThreeWayCrossoverFilter<float, 12> filter12;
} threeBandFilters;


gui::SpectrumAnalyserTask lowPreSpectrumAnalyserTask;
gui::SpectrumAnalyserTask lowPostSpectrumAnalyserTask;
gui::SpectrumAnalyserTask midPreSpectrumAnalyserTask;
gui::SpectrumAnalyserTask midPostSpectrumAnalyserTask;
gui::SpectrumAnalyserTask highPreSpectrumAnalyserTask;
gui::SpectrumAnalyserTask highPostSpectrumAnalyserTask;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BandSplitterProcessor)
};
Expand Down
6 changes: 4 additions & 2 deletions src/gui/BandSplitter/BandSplitterEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ BandSplitterEditor::BandSplitterEditor (State& pluginState,
dsp::band_splitter::Params& params,
dsp::band_splitter::ExtraState& bandSplitterExtraState,
const chowdsp::HostContextProvider& hcp,
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasks)
: bandSplitterPlot (pluginState, params, bandSplitterExtraState, hcp, spectrumAnalyserTasks),
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasksLow,
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasksMid,
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasksHigh)
: bandSplitterPlot (pluginState, params, bandSplitterExtraState, hcp, spectrumAnalyserTasksLow, spectrumAnalyserTasksMid, spectrumAnalyserTasksHigh),
slopePicker (pluginState, *params.slope),
extraState (bandSplitterExtraState),
bandsButton (*params.threeBandOnOff, pluginState)
Expand Down
4 changes: 3 additions & 1 deletion src/gui/BandSplitter/BandSplitterEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class BandSplitterEditor : public juce::Component
dsp::band_splitter::Params& params,
dsp::band_splitter::ExtraState& bandSplitterExtraState,
const chowdsp::HostContextProvider& hcp,
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasks);
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasksLow,
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasksMid,
std::pair<gui::SpectrumAnalyserTask::Optional, gui::SpectrumAnalyserTask::Optional> spectrumAnalyserTasksHigh);

void paint (juce::Graphics& g) override;
void resized() override;
Expand Down
Loading

0 comments on commit 3a33647

Please sign in to comment.