Vital
Loading...
Searching...
No Matches
equalizer_module.cpp
Go to the documentation of this file.
1#include "equalizer_module.h"
2
3#include "digital_svf.h"
4#include "value.h"
5
6namespace vital {
7
9 SynthModule(0, 1),
10 low_mode_(nullptr), band_mode_(nullptr), high_mode_(nullptr),
11 high_pass_(nullptr), low_shelf_(nullptr),
12 notch_(nullptr), band_shelf_(nullptr),
13 low_pass_(nullptr), high_shelf_(nullptr) {
14 audio_memory_ = std::make_shared<vital::StereoMemory>(vital::kAudioMemorySamples);
15 }
16
26 static const cr::Value kPass(DigitalSvf::k12Db);
27 static const cr::Value kNotch(DigitalSvf::kNotchPassSwap);
28 static const cr::Value kShelving(DigitalSvf::kShelving);
29
30 high_pass_ = new DigitalSvf();
31 low_shelf_ = new DigitalSvf();
32 band_shelf_ = new DigitalSvf();
33 notch_ = new DigitalSvf();
34 low_pass_ = new DigitalSvf();
35 high_shelf_ = new DigitalSvf();
36
37 // Basic mode and no drive compensation to ensure clean filter output for EQ.
39 high_pass_->setBasic(true);
41 notch_->setBasic(true);
43 low_pass_->setBasic(true);
44
51 low_pass_->useOutput(output()); // Final output from either low_pass_ or high_shelf_.
53
54 // Mode controls for switching filter types.
55 low_mode_ = createBaseControl("eq_low_mode");
56 band_mode_ = createBaseControl("eq_band_mode");
57 high_mode_ = createBaseControl("eq_high_mode");
58
59 // Parameter controls for cutoff frequencies.
60 Output* low_cutoff_midi = createMonoModControl("eq_low_cutoff", true, true);
61 Output* band_cutoff_midi = createMonoModControl("eq_band_cutoff", true, true);
62 Output* high_cutoff_midi = createMonoModControl("eq_high_cutoff", true, true);
63
64 // Resonance controls for each band.
65 Output* low_resonance = createMonoModControl("eq_low_resonance");
66 Output* band_resonance = createMonoModControl("eq_band_resonance");
67 Output* high_resonance = createMonoModControl("eq_high_resonance");
68
69 // Gain controls for shelf filters.
70 Output* low_decibels = createMonoModControl("eq_low_gain");
71 Output* band_decibels = createMonoModControl("eq_band_gain");
72 Output* high_decibels = createMonoModControl("eq_high_gain");
73
74 // Configure each filter with the appropriate style and parameter mappings.
77 high_pass_->plug(low_cutoff_midi, DigitalSvf::kMidiCutoff);
78 high_pass_->plug(low_resonance, DigitalSvf::kResonance);
79
82 low_shelf_->plug(low_cutoff_midi, DigitalSvf::kMidiCutoff);
83 low_shelf_->plug(low_resonance, DigitalSvf::kResonance);
84 low_shelf_->plug(low_decibels, DigitalSvf::kGain);
85
88 band_shelf_->plug(band_cutoff_midi, DigitalSvf::kMidiCutoff);
89 band_shelf_->plug(band_resonance, DigitalSvf::kResonance);
90 band_shelf_->plug(band_decibels, DigitalSvf::kGain);
91
94 notch_->plug(band_cutoff_midi, DigitalSvf::kMidiCutoff);
95 notch_->plug(band_resonance, DigitalSvf::kResonance);
96
99 low_pass_->plug(high_cutoff_midi, DigitalSvf::kMidiCutoff);
100 low_pass_->plug(high_resonance, DigitalSvf::kResonance);
101
102 high_shelf_->plug(&kShelving, DigitalSvf::kStyle);
104 high_shelf_->plug(high_cutoff_midi, DigitalSvf::kMidiCutoff);
105 high_shelf_->plug(high_resonance, DigitalSvf::kResonance);
106 high_shelf_->plug(high_decibels, DigitalSvf::kGain);
107
109 }
110
122
140
141 void EqualizerModule::setSampleRate(int sample_rate) {
145 high_pass_->setSampleRate(sample_rate);
146 low_shelf_->setSampleRate(sample_rate);
147 band_shelf_->setSampleRate(sample_rate);
148 notch_->setSampleRate(sample_rate);
149 low_pass_->setSampleRate(sample_rate);
150 high_shelf_->setSampleRate(sample_rate);
151 }
152
153 void EqualizerModule::processWithInput(const poly_float* audio_in, int num_samples) {
161 SynthModule::process(num_samples);
162
163 Processor* low_processor = low_mode_->value() ? high_pass_ : low_shelf_;
164 Processor* band_processor = band_mode_->value() ? notch_ : band_shelf_;
165 Processor* high_processor = high_mode_->value() ? low_pass_ : high_shelf_;
166
167 // Chain the processing: low section -> band section -> high section
168 low_processor->processWithInput(audio_in, num_samples);
169 band_processor->processWithInput(low_processor->output()->buffer, num_samples);
170 high_processor->processWithInput(band_processor->output()->buffer, num_samples);
171
172 const poly_float* output_buffer = high_processor->output()->buffer;
173 for (int i = 0; i < num_samples; ++i)
174 audio_memory_->push(output_buffer[i]);
175 }
176} // namespace vital
A state-variable filter (SVF) implementation, supporting multiple filter types (12/24 dB,...
Definition digital_svf.h:17
void setDriveCompensation(bool drive_compensation)
Enables or disables drive compensation (reducing drive as resonance increases).
Definition digital_svf.h:407
void reset(poly_mask reset_masks) override
Resets internal filter states for voices specified by the reset_masks.
Definition digital_svf.cpp:487
void setBasic(bool basic)
Sets whether this filter should use a simpler, “basic” processing path.
Definition digital_svf.h:400
void setSampleRate(int sample_rate) override
Sets the sample rate of the equalizer and propagates it to all internal filters.
Definition equalizer_module.cpp:141
Value * low_mode_
Determines if the low band uses a shelf or a high-pass filter.
Definition equalizer_module.h:78
void init() override
Initializes the EqualizerModule by creating parameter controls and linking them to internal filters.
Definition equalizer_module.cpp:17
std::shared_ptr< StereoMemory > audio_memory_
Memory buffer for storing processed audio samples.
Definition equalizer_module.h:89
DigitalSvf * low_shelf_
Low shelf filter for low band mode.
Definition equalizer_module.h:83
EqualizerModule()
Constructs an EqualizerModule.
Definition equalizer_module.cpp:8
DigitalSvf * band_shelf_
Band shelf filter for mid band mode.
Definition equalizer_module.h:85
DigitalSvf * high_pass_
High-pass filter for low band mode.
Definition equalizer_module.h:82
void hardReset() override
Resets the equalizer filters to their initial states, clearing any buffer or filter history.
Definition equalizer_module.cpp:111
DigitalSvf * low_pass_
Low-pass filter for high band mode.
Definition equalizer_module.h:86
Value * band_mode_
Determines if the mid band uses a shelf or a notch filter.
Definition equalizer_module.h:79
DigitalSvf * notch_
Notch filter for mid band mode.
Definition equalizer_module.h:84
void enable(bool enable) override
Enables or disables the equalizer module.
Definition equalizer_module.cpp:123
void processWithInput(const poly_float *audio_in, int num_samples) override
Processes an input audio buffer through the equalizer.
Definition equalizer_module.cpp:153
DigitalSvf * high_shelf_
High shelf filter for high band mode.
Definition equalizer_module.h:87
Value * high_mode_
Determines if the high band uses a shelf or a low-pass filter.
Definition equalizer_module.h:80
Base class for all signal-processing units in Vital.
Definition processor.h:212
void useOutput(Output *output)
Uses an existing Output object as this Processor's first output.
Definition processor.cpp:138
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
virtual void process(int num_samples)=0
Main processing function. Called by the ProcessorRouter.
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
virtual void setSampleRate(int sample_rate)
Updates the sample rate of this Processor (scaled by oversampling).
Definition processor.h:285
virtual void init()
Called after constructor, used for any additional initialization. Subclasses can override....
Definition processor.h:258
virtual void processWithInput(const poly_float *audio_in, int num_samples)
An optional processing function taking explicit input buffer. Fallback is an assertion failure (not s...
Definition processor.h:252
virtual void addIdleProcessor(Processor *processor)
Adds a Processor that should remain idle (not processed) in the router.
Definition processor_router.cpp:146
virtual void process(int num_samples) override
Processes audio through all Processors managed by this router.
Definition processor_router.cpp:57
@ kPassBlend
Blending parameter for low-pass, high-pass, band-pass.
Definition synth_filter.h:62
@ kResonance
Resonance parameter.
Definition synth_filter.h:58
@ kMidiCutoff
MIDI-based cutoff parameter.
Definition synth_filter.h:57
@ kStyle
Filter style (12 dB, 24 dB, etc.)
Definition synth_filter.h:61
@ kGain
Additional gain.
Definition synth_filter.h:60
@ kNotchPassSwap
Definition synth_filter.h:77
@ kShelving
Definition synth_filter.h:80
@ k12Db
Definition synth_filter.h:75
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
Value * createBaseControl(std::string name, bool audio_rate=false, bool smooth_value=false)
Creates a simple control processor for a given parameter name.
Definition synth_module.cpp:22
virtual void enable(bool enable) override
Enables or disables this SynthModule and its owned processors.
Definition synth_module.cpp:516
Output * createMonoModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
Creates a monophonic mod control, including applying parameter scaling.
Definition synth_module.cpp:104
force_inline mono_float value() const
Returns the current mono_float value of the first lane.
Definition value.h:60
A control-rate variant of the Value processor.
Definition value.h:82
const poly_mask kFullMask
A mask covering all lanes of a poly_float vector.
Definition synth_constants.h:257
const cr::Value kValueZero(0.0f)
const cr::Value kValueTwo(2.0f)
const cr::Value kValueOne(1.0f)
Contains classes and functions used within the Vital synthesizer framework.
constexpr int kAudioMemorySamples
Size of the stereo audio memory buffer used for visualization.
Definition synth_constants.h:58
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Declares Value processors that output a constant value and can be dynamically set.