Skip to content

Commit

Permalink
Pre/Post Spectrum Analyser and Tasks for AnalogEQ
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke authored and jatinchowdhury18 committed Jan 3, 2024
1 parent 6e9b190 commit 922e99d
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/dsp/AnalogEQ/AnalogEQProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ void AnalogEQProcessor::prepare (const juce::dsp::ProcessSpec& spec)
{
for (auto& model : wdf)
model.prepare ((float) spec.sampleRate);

preSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
postSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
}

void AnalogEQProcessor::reset()
Expand All @@ -16,6 +19,10 @@ void AnalogEQProcessor::reset()

void AnalogEQProcessor::processBlock (const chowdsp::BufferView<float>& buffer)
{

if (extraState.isEditorOpen.load() && extraState.showPreSpectrum.get())
preSpectrumAnalyserTask.processBlockInput (buffer.toAudioBuffer());

const auto getMagParam = [] (const chowdsp::FloatParameter* param, bool isBoosting)
{
const auto normValue = param->convertTo0to1 (param->getCurrentValue());
Expand All @@ -41,5 +48,8 @@ void AnalogEQProcessor::processBlock (const chowdsp::BufferView<float>& buffer)
}

chowdsp::BufferMath::applyGain (buffer, juce::Decibels::decibelsToGain (22.4f));

if (extraState.isEditorOpen.load() && extraState.showPostSpectrum.get())
postSpectrumAnalyserTask.processBlockInput (buffer.toAudioBuffer());
}
} // namespace dsp::analog_eq
23 changes: 22 additions & 1 deletion src/dsp/AnalogEQ/AnalogEQProcessor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "PultecEQWDF.h"
#include "gui/Shared/SpectrumAnalyserTask.h"

namespace dsp::analog_eq
{
Expand Down Expand Up @@ -65,20 +66,40 @@ struct Params : chowdsp::ParamHolder
};
};

struct ExtraState
{
std::atomic<bool> isEditorOpen { false };
chowdsp::StateValue<std::atomic_bool, bool> showPreSpectrum { "analog_eq_show_pre_spectrum", true };
chowdsp::StateValue<std::atomic_bool, bool> showPostSpectrum { "analog_eq_show_post_spectrum", true };
};

class AnalogEQProcessor
{
public:
explicit AnalogEQProcessor (const Params& pultecParams) : params (pultecParams) {}
explicit AnalogEQProcessor (const Params& pultecParams, const ExtraState& pultecExtraState) : params (pultecParams), extraState(pultecExtraState)
{
preSpectrumAnalyserTask.spectrumAnalyserUITask.setDBRange (-25, 20);
postSpectrumAnalyserTask.spectrumAnalyserUITask.setDBRange (-25, 20);
}

void prepare (const juce::dsp::ProcessSpec& spec);
void reset();
void processBlock (const chowdsp::BufferView<float>& buffer);

gui::SpectrumAnalyserTask::PrePostPair getSpectrumAnalyserTasks()
{
return { std::ref (preSpectrumAnalyserTask.spectrumAnalyserUITask), std::ref (postSpectrumAnalyserTask.spectrumAnalyserUITask) };
}

private:
const Params& params;
const ExtraState& extraState;

PultecEqWDF wdf[2];

gui::SpectrumAnalyserTask preSpectrumAnalyserTask;
gui::SpectrumAnalyserTask postSpectrumAnalyserTask;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AnalogEQProcessor)
};
} // namespace dsp::analog_eq
8 changes: 4 additions & 4 deletions src/dsp/EQ/EQProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace dsp::eq
{
EQProcessor::EQProcessor (const EQToolParams& eqParams, const ExtraState& es)
EQProcessor::EQProcessor (const EQToolParams& eqParams, const ExtraState& eqExtraState)
: params (eqParams),
extraState (es)
extraState (eqExtraState)
{
preSpectrumAnalyserTask.spectrumAnalyserUITask.setDBRange (-20, 20);
postSpectrumAnalyserTask.spectrumAnalyserUITask.setDBRange (-20, 20);
preSpectrumAnalyserTask.spectrumAnalyserUITask.setDBRange (-25, 20);
postSpectrumAnalyserTask.spectrumAnalyserUITask.setDBRange (-25, 20);
}

void EQProcessor::prepare (const juce::dsp::ProcessSpec& spec)
Expand Down
2 changes: 1 addition & 1 deletion src/dsp/EQ/EQProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct ExtraState
class EQProcessor
{
public:
EQProcessor (const EQToolParams& eqParams, const ExtraState& extraState);
EQProcessor (const EQToolParams& eqParams, const ExtraState& eqExtraState);

void prepare (const juce::dsp::ProcessSpec& spec);
void processBlock (const chowdsp::BufferView<float>& buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/dsp/MultiToolProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace detail
}; }),
tool_maker<signal_gen::SignalGeneratorProcessor> ([&params]
{ return signal_gen::SignalGeneratorProcessor { *params.signalGenParams }; }),
tool_maker<analog_eq::AnalogEQProcessor> ([&params]
{ return analog_eq::AnalogEQProcessor { *params.analogEQParams }; }),
tool_maker<analog_eq::AnalogEQProcessor> ([&params, &pluginState]
{ return analog_eq::AnalogEQProcessor { *params.analogEQParams, *pluginState.nonParams.analogEqExtraState }; }),
tool_maker<band_splitter::BandSplitterProcessor> ([&params, &pluginState]
{ return band_splitter::BandSplitterProcessor { *params.bandSplitParams, *pluginState.nonParams.bandSplitterExtraState }; }),
tool_maker<brickwall::BrickwallProcessor> ([&params, &pluginState]
Expand Down
9 changes: 7 additions & 2 deletions src/gui/AnalogEQ/AnalogEQEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

namespace gui::analog_eq
{
AnalogEQEditor::AnalogEQEditor (State& pluginState, dsp::analog_eq::Params& params, const chowdsp::HostContextProvider& hcp)
: plot (pluginState, params, hcp)
AnalogEQEditor::AnalogEQEditor (State& pluginState,
dsp::analog_eq::Params& params,
dsp::analog_eq::ExtraState& analogEqExtraState,
const chowdsp::HostContextProvider& hcp,
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks)
: plot (pluginState, params, analogEqExtraState, hcp, spectrumAnalyserTasks),
extraState(analogEqExtraState)
{
addAndMakeVisible (plot);
}
Expand Down
7 changes: 6 additions & 1 deletion src/gui/AnalogEQ/AnalogEQEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ namespace gui::analog_eq
class AnalogEQEditor : public juce::Component
{
public:
AnalogEQEditor (State& pluginState, dsp::analog_eq::Params& params, const chowdsp::HostContextProvider& hcp);
AnalogEQEditor (State& pluginState,
dsp::analog_eq::Params& params,
dsp::analog_eq::ExtraState& analogEqExtraState,
const chowdsp::HostContextProvider& hcp,
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks);

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

private:
AnalogEQPlot plot;
dsp::analog_eq::ExtraState& extraState;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AnalogEQEditor)
};
Expand Down
68 changes: 63 additions & 5 deletions src/gui/AnalogEQ/AnalogEQPlot.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "AnalogEQPlot.h"
#include "gui/Shared/Colours.h"
#include "gui/Shared/DotSlider.h"
#include "gui/Shared/LookAndFeels.h"
#include "gui/Shared/FrequencyPlotHelpers.h"

namespace gui::analog_eq
Expand Down Expand Up @@ -39,7 +40,11 @@ namespace
}
} // namespace

AnalogEQPlot::AnalogEQPlot (State& pluginState, dsp::analog_eq::Params& pultecParams, const chowdsp::HostContextProvider& hcp)
AnalogEQPlot::AnalogEQPlot (State& pluginState,
dsp::analog_eq::Params& pultecParams,
dsp::analog_eq::ExtraState& analogEqExtraState,
const chowdsp::HostContextProvider& hcp,
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks)
: chowdsp::SpectrumPlotBase (chowdsp::SpectrumPlotParams {
.minFrequencyHz = (float) minFrequency,
.maxFrequencyHz = (float) maxFrequency,
Expand All @@ -50,9 +55,27 @@ AnalogEQPlot::AnalogEQPlot (State& pluginState, dsp::analog_eq::Params& pultecPa
.freqSmoothOctaves = 1.0f / 12.0f,
.fftOrder = fftOrder,
}),
pultecEQ (pultecParams),
chyron (pluginState, *pluginState.params.analogEQParams, hcp)
extraState (analogEqExtraState),
pultecEQ (pultecParams, extraState),
chyron (pluginState, *pluginState.params.analogEQParams, hcp),
spectrumAnalyser(*this, spectrumAnalyserTasks)
{

addMouseListener (this, true);
extraState.isEditorOpen.store (true);
spectrumAnalyser.setShouldShowPreEQ (extraState.showPreSpectrum.get());
spectrumAnalyser.setShouldShowPostEQ (extraState.showPostSpectrum.get());
callbacks += {
extraState.showPreSpectrum.changeBroadcaster.connect ([this]
{
spectrumAnalyser.setShouldShowPreEQ(extraState.showPreSpectrum.get());
spectrumAnalyser.repaint(); }),
extraState.showPostSpectrum.changeBroadcaster.connect ([this]
{
spectrumAnalyser.setShouldShowPostEQ(extraState.showPostSpectrum.get());
spectrumAnalyser.repaint(); }),
};

pultecEQ.prepare ({ sampleRate, (uint32_t) blockSize, 1 });
filterPlotter.runFilterCallback = [this] (const float* input, float* output, int numSamples)
{
Expand Down Expand Up @@ -201,11 +224,18 @@ AnalogEQPlot::AnalogEQPlot (State& pluginState, dsp::analog_eq::Params& pultecPa

updatePlot();


addAndMakeVisible (chyron);
chyron.toFront (false);
addAndMakeVisible (spectrumAnalyser);
spectrumAnalyser.toBack();
}

AnalogEQPlot::~AnalogEQPlot() = default;
AnalogEQPlot::~AnalogEQPlot()
{
removeMouseListener (this);
extraState.isEditorOpen.store (false);
}

void AnalogEQPlot::updatePlot()
{
Expand Down Expand Up @@ -258,10 +288,38 @@ void AnalogEQPlot::resized()
getHeight() - pad - chyronHeight,
chyronWidth,
chyronHeight);
spectrumAnalyser.setBounds(getLocalBounds());
}

void AnalogEQPlot::mouseDown (const juce::MouseEvent&)
void AnalogEQPlot::mouseDown (const juce::MouseEvent& event)
{
chyron.setSelectedBand (EQBand::None);
if (event.mods.isPopupMenu())
{
chowdsp::SharedLNFAllocator lnfAllocator;
juce::PopupMenu menu;

juce::PopupMenu::Item preSpectrumItem;
preSpectrumItem.itemID = 100;
preSpectrumItem.text = extraState.showPreSpectrum.get() ? "Disable Pre-EQ Visualizer" : "Enable Pre-EQ Visualizer";
preSpectrumItem.action = [this]
{
extraState.showPreSpectrum.set (! extraState.showPreSpectrum.get());
};
menu.addItem (preSpectrumItem);

juce::PopupMenu::Item postSpectrumItem;
postSpectrumItem.itemID = 101;
postSpectrumItem.text = extraState.showPostSpectrum.get() ? "Disable Post-EQ Visualizer" : "Enable Post-EQ Visualizer";
postSpectrumItem.action = [this]
{
extraState.showPostSpectrum.set (! extraState.showPostSpectrum.get());
};
menu.addItem (postSpectrumItem);

menu.setLookAndFeel (lnfAllocator->getLookAndFeel<lnf::MenuLNF>());
menu.showMenuAsync (juce::PopupMenu::Options {}
.withParentComponent (getParentComponent()));
}
}
} // namespace gui::analog_eq
11 changes: 9 additions & 2 deletions src/gui/AnalogEQ/AnalogEQPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "EQChyron.h"
#include "dsp/AnalogEQ/AnalogEQProcessor.h"
#include "gui/Shared/SpectrumAnalyser.h"
#include "state/PluginState.h"

namespace gui::analog_eq
Expand All @@ -11,7 +12,11 @@ class DotSlider;
class AnalogEQPlot : public chowdsp::SpectrumPlotBase
{
public:
AnalogEQPlot (State& pluginState, dsp::analog_eq::Params& params, const chowdsp::HostContextProvider& hcp);
AnalogEQPlot (State& pluginState,
dsp::analog_eq::Params& params,
dsp::analog_eq::ExtraState& analogEqExtraState,
const chowdsp::HostContextProvider& hcp,
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks);
~AnalogEQPlot() override;

void paint (juce::Graphics& g) override;
Expand All @@ -26,12 +31,13 @@ class AnalogEQPlot : public chowdsp::SpectrumPlotBase
};

private:
void mouseDown (const juce::MouseEvent& e) override;
void mouseDown (const juce::MouseEvent& event) override;

void updatePlot();
void setSelectedBand (BandID bandID);

chowdsp::GenericFilterPlotter filterPlotter;
dsp::analog_eq::ExtraState& extraState;
dsp::analog_eq::AnalogEQProcessor pultecEQ;

chowdsp::ScopedCallbackList callbacks;
Expand All @@ -47,6 +53,7 @@ class AnalogEQPlot : public chowdsp::SpectrumPlotBase
std::unique_ptr<juce::Component> highCutFullControl;

EQChyron chyron;
SpectrumAnalyser spectrumAnalyser;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AnalogEQPlot)
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/EQ/EQEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EQEditor : public juce::Component
dsp::eq::EQToolParams& eqParams,
dsp::eq::ExtraState& extraState,
const chowdsp::HostContextProvider& hcp,
std::pair<SpectrumAnalyserTask::OptionalBackgroundTask, SpectrumAnalyserTask::OptionalBackgroundTask> spectrumAnalyserTasks);
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks);
~EQEditor() override;

void paint (juce::Graphics& g) override;
Expand Down
6 changes: 5 additions & 1 deletion src/gui/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ void PluginEditor::refreshEditor()
else if constexpr (std::is_same_v<ToolType, dsp::signal_gen::SignalGeneratorProcessor>)
editorComponent = std::make_unique<signal_gen::SignalGeneratorEditor> (pluginState, hostContextProvider);
else if constexpr (std::is_same_v<ToolType, dsp::analog_eq::AnalogEQProcessor>)
editorComponent = std::make_unique<analog_eq::AnalogEQEditor> (pluginState, *pluginState.params.analogEQParams, hostContextProvider);
editorComponent = std::make_unique<analog_eq::AnalogEQEditor> (pluginState,
*pluginState.params.analogEQParams,
*pluginState.nonParams.analogEqExtraState,
hostContextProvider,
std::get<dsp::analog_eq::AnalogEQProcessor> (plugin.getProcessor().getTools()).getSpectrumAnalyserTasks());
else if constexpr (std::is_same_v<ToolType, dsp::band_splitter::BandSplitterProcessor>)
editorComponent = std::make_unique<band_splitter::BandSplitterEditor> (pluginState,
*pluginState.params.bandSplitParams,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/SVF/SVFEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SVFEditor : public juce::Component
dsp::svf::Params& svfParams,
dsp::svf::ExtraState& extraState,
const chowdsp::HostContextProvider& hcp,
std::pair<SpectrumAnalyserTask::OptionalBackgroundTask, SpectrumAnalyserTask::OptionalBackgroundTask> spectrumAnalyserTasks);
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks);

void resized() override;
void paint (juce::Graphics& g) override;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/SVF/SVFPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SVFPlot : public chowdsp::SpectrumPlotBase,
dsp::svf::Params& params,
dsp::svf::ExtraState& svfExtraState,
const chowdsp::HostContextProvider& hcp,
std::pair<SpectrumAnalyserTask::OptionalBackgroundTask, SpectrumAnalyserTask::OptionalBackgroundTask> spectrumAnalyserTasks);
SpectrumAnalyserTask::PrePostPair spectrumAnalyserTasks);
~SVFPlot();
void paint (juce::Graphics& g) override;
void paintOverChildren (juce::Graphics& g) override;
Expand Down
3 changes: 3 additions & 0 deletions src/state/PluginState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ PluginParams::~PluginParams() = default;
PluginExtraState::PluginExtraState()
{
waveshaperExtraState = std::make_unique<dsp::waveshaper::ExtraState>();
analogEqExtraState.emplace();
eqExtraState.emplace();
brickwallExtraState.emplace();
svfExtraState.emplace();
Expand All @@ -55,6 +56,8 @@ PluginExtraState::PluginExtraState()
addStateValues ({ &waveshaperExtraState->freeDrawState,
&waveshaperExtraState->mathState,
&waveshaperExtraState->pointsState,
&analogEqExtraState->showPreSpectrum,
&analogEqExtraState->showPostSpectrum,
&eqExtraState->showPreSpectrum,
&eqExtraState->showPostSpectrum,
&brickwallExtraState->showPostSpectrum,
Expand Down
2 changes: 2 additions & 0 deletions src/state/PluginState.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace signal_gen
namespace analog_eq
{
struct Params;
struct ExtraState;
}
namespace band_splitter
{
Expand Down Expand Up @@ -77,6 +78,7 @@ struct PluginExtraState : chowdsp::NonParamState
~PluginExtraState();

std::unique_ptr<dsp::waveshaper::ExtraState> waveshaperExtraState;
chowdsp::LocalPointer<dsp::analog_eq::ExtraState, 128> analogEqExtraState;
chowdsp::LocalPointer<dsp::eq::ExtraState, 128> eqExtraState;
chowdsp::LocalPointer<dsp::brickwall::ExtraState, 128> brickwallExtraState;
chowdsp::LocalPointer<dsp::svf::ExtraState, 128> svfExtraState;
Expand Down

0 comments on commit 922e99d

Please sign in to comment.