Vital
|
A state-variable filter (SVF) implementation, supporting multiple filter types (12/24 dB, shelving, dual modes). More...
#include <digital_svf.h>
Classes | |
struct | FilterValues |
Stores three filter state variables (v0, v1, v2) used for multi-mode mixing. More... | |
Public Types | |
typedef OneDimLookup< computeSvfOnePoleFilterCoefficient, 2048 > | SvfCoefficientLookup |
A lookup table type for quickly converting frequency ratios into filter coefficients. | |
![]() | |
enum | { kAudio , kReset , kMidiCutoff , kResonance , kDriveGain , kGain , kStyle , kPassBlend , kInterpolateX , kInterpolateY , kTranspose , kSpread , kNumInputs } |
enum | Style { k12Db , k24Db , kNotchPassSwap , kDualNotchBand , kBandPeakNotch , kShelving , kNumStyles } |
Different filter styles used in various derived classes. More... | |
typedef OneDimLookup< computeOnePoleFilterCoefficient, 2048 > | CoefficientLookup |
A lookup table for quick computation of one-pole filter coefficients. | |
Public Member Functions | |
DigitalSvf () | |
Constructor that initializes the filter’s internal states. | |
virtual | ~DigitalSvf () |
Default destructor. | |
virtual Processor * | clone () const override |
Creates a clone of this filter by invoking the copy constructor. | |
virtual void | process (int num_samples) override |
Processes a block of samples by pulling from the primary audio input and computing the SVF output. Delegates to processWithInput() . | |
void | processWithInput (const poly_float *audio_in, int num_samples) override |
Processes a block of samples using a provided input buffer. | |
void | reset (poly_mask reset_masks) override |
Resets internal filter states for voices specified by the reset_masks . | |
void | hardReset () override |
Performs a complete reset of the filter states for all voices. | |
void | setupFilter (const FilterState &filter_state) override |
Configures this SVF based on a FilterState (cutoff, resonance, style, etc.). | |
void | setResonanceBounds (mono_float min, mono_float max) |
Sets the minimum and maximum resonance for the filter (used in resonance interpolation). | |
void | process12 (const poly_float *audio_in, int num_samples, poly_float current_resonance, poly_float current_drive, poly_float current_post_multiply, FilterValues &blends) |
Processes a 12 dB filter style, iterating through the block. | |
void | processBasic12 (const poly_float *audio_in, int num_samples, poly_float current_resonance, poly_float current_drive, poly_float current_post_multiply, FilterValues &blends) |
Processes a simpler 12 dB filter style, skipping extra color or overshoot logic. | |
void | process24 (const poly_float *audio_in, int num_samples, poly_float current_resonance, poly_float current_drive, poly_float current_post_multiply, FilterValues &blends) |
Processes a 24 dB filter style, adding additional stages. | |
void | processBasic24 (const poly_float *audio_in, int num_samples, poly_float current_resonance, poly_float current_drive, poly_float current_post_multiply, FilterValues &blends) |
Processes a simpler 24 dB filter style, skipping advanced processing. | |
void | processDual (const poly_float *audio_in, int num_samples, poly_float current_resonance, poly_float current_drive, poly_float current_post_multiply, FilterValues &blends1, FilterValues &blends2) |
Processes a dual filter mode, e.g., dual notch + band pass. | |
force_inline poly_float | tick (poly_float audio_in, poly_float coefficient, poly_float resonance, poly_float drive, FilterValues &blends) |
Applies advanced distortion to the input while performing a single SVF tick (12 dB). | |
force_inline poly_float | tickBasic (poly_float audio_in, poly_float coefficient, poly_float resonance, poly_float drive, FilterValues &blends) |
A basic (non-distorting) single SVF tick for a 12 dB filter style. | |
force_inline poly_float | tick24 (poly_float audio_in, poly_float coefficient, poly_float resonance, poly_float drive, FilterValues &blends) |
Tick function for a 24 dB multi-stage filter, adding an additional pre-stage. | |
force_inline poly_float | tickBasic24 (poly_float audio_in, poly_float coefficient, poly_float resonance, poly_float drive, FilterValues &blends) |
A simpler 24 dB tick function without advanced distortion or color. | |
force_inline poly_float | tickDual (poly_float audio_in, poly_float coefficient, poly_float resonance, poly_float drive, FilterValues &blends1, FilterValues &blends2) |
Tick function for a dual filter approach, e.g. notch + band, etc. | |
poly_float | getDrive () const |
Retrieves the final drive (post drive compensation) used in the filter. | |
poly_float | getMidiCutoff () const |
Retrieves the current MIDI-based cutoff frequency. | |
poly_float | getResonance () const |
Retrieves the current resonance value (inverted if needed). | |
poly_float | getLowAmount () const |
Retrieves the current low-frequency mix portion. | |
poly_float | getBandAmount () const |
Retrieves the current band-frequency mix portion. | |
poly_float | getHighAmount () const |
Retrieves the current high-frequency mix portion. | |
poly_float | getLowAmount24 (int style) const |
Helper for a 24 dB filter style that may swap low/high in a dual notch band. | |
poly_float | getHighAmount24 (int style) const |
Helper for a 24 dB filter style that may swap low/high in a dual notch band. | |
void | setBasic (bool basic) |
Sets whether this filter should use a simpler, “basic” processing path. | |
void | setDriveCompensation (bool drive_compensation) |
Enables or disables drive compensation (reducing drive as resonance increases). | |
![]() | |
Processor (int num_inputs, int num_outputs, bool control_rate=false, int max_oversample=1) | |
Constructs a Processor with a given number of inputs/outputs and oversampling. | |
virtual | ~Processor () |
Virtual destructor. | |
virtual bool | hasState () const |
Indicates whether this Processor requires per-voice state. | |
virtual void | init () |
Called after constructor, used for any additional initialization. Subclasses can override. Sets the initialized flag. | |
bool | initialized () |
Returns whether this Processor has been initialized. | |
virtual void | setSampleRate (int sample_rate) |
Updates the sample rate of this Processor (scaled by oversampling). | |
virtual void | setOversampleAmount (int oversample) |
Sets the oversampling amount and updates the effective sample rate. | |
force_inline bool | enabled () const |
Checks if this Processor is enabled. | |
virtual void | enable (bool enable) |
Enables or disables this Processor. | |
force_inline int | getSampleRate () const |
Retrieves the current (effective) sample rate. | |
force_inline int | getOversampleAmount () const |
Retrieves the current oversampling factor. | |
force_inline bool | isControlRate () const |
Checks if this Processor is running at control rate (buffer_size == 1). | |
virtual void | setControlRate (bool control_rate) |
Sets whether this Processor runs at control rate. | |
force_inline poly_mask | getResetMask (int input_index) const |
Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_value to kVoiceOn. | |
force_inline void | clearOutputBufferForReset (poly_mask reset_mask, int input_index, int output_index) const |
Clears output samples for voices that are about to be reset, based on the trigger offset. | |
bool | inputMatchesBufferSize (int input=0) |
Checks whether the buffer size of a particular input matches the size needed by this Processor. | |
bool | checkInputAndOutputSize (int num_samples) |
Checks if all inputs and outputs have buffers big enough for num_samples . | |
virtual bool | isPolyphonic () const |
Checks if this Processor is polyphonic by querying its ProcessorRouter. | |
void | plug (const Output *source) |
Connects an external Output to this Processor's first input. | |
void | plug (const Output *source, unsigned int input_index) |
Connects an external Output to a specified input index. | |
void | plug (const Processor *source) |
Connects the first output of a Processor to this Processor's first input. | |
void | plug (const Processor *source, unsigned int input_index) |
Connects the first output of a Processor to a specified input index. | |
void | plugNext (const Output *source) |
Connects an external Output to the first available (unplugged) input. | |
void | plugNext (const Processor *source) |
Connects the first output of a Processor to the first available (unplugged) input. | |
void | useInput (Input *input) |
Uses an existing Input object as this Processor's first input. | |
void | useInput (Input *input, int index) |
Uses an existing Input object at a specified input index. | |
void | useOutput (Output *output) |
Uses an existing Output object as this Processor's first output. | |
void | useOutput (Output *output, int index) |
Uses an existing Output object at a specified output index. | |
int | connectedInputs () |
Counts how many inputs are connected to a real source (not null_source_). | |
virtual void | unplugIndex (unsigned int input_index) |
Removes the connection at a specified input index, if any. | |
virtual void | unplug (const Output *source) |
Removes a connection to a given Output from all inputs. | |
virtual void | unplug (const Processor *source) |
Removes connections to all outputs from a given Processor. | |
virtual void | numInputsChanged () |
Called when the number of inputs changes (e.g., new connections). Subclasses may override for dynamic behavior. | |
force_inline void | router (ProcessorRouter *router) |
Sets the ProcessorRouter that owns or manages this Processor. | |
force_inline ProcessorRouter * | router () const |
Returns the ProcessorRouter that currently owns this Processor. | |
ProcessorRouter * | getTopLevelRouter () const |
Gets the topmost (root) ProcessorRouter by traversing parent routers. | |
virtual void | registerInput (Input *input, int index) |
Registers a new input, appending it to the input list. | |
virtual Output * | registerOutput (Output *output, int index) |
Registers a new Output in the output list at a specified index. | |
virtual void | registerInput (Input *input) |
Registers a new Input by appending it to the end of the input list. | |
virtual Output * | registerOutput (Output *output) |
Registers a new Output by appending it to the end of the output list. | |
force_inline int | numInputs () const |
Returns the total number of Input pointers (owned or otherwise). | |
force_inline int | numOutputs () const |
Returns the total number of Output pointers (owned or otherwise). | |
force_inline int | numOwnedInputs () const |
Returns how many Input objects this Processor owns. | |
force_inline int | numOwnedOutputs () const |
Returns how many Output objects this Processor owns. | |
force_inline Input * | input (unsigned int index=0) const |
Retrieves the Input pointer at a given index. | |
force_inline bool | isInputSourcePolyphonic (int index=0) |
Checks if the input source at a given index is polyphonic. | |
force_inline Input * | ownedInput (unsigned int index=0) const |
Retrieves an owned Input pointer at a given index. | |
force_inline Output * | output (unsigned int index=0) const |
Retrieves the Output pointer at a given index. | |
force_inline Output * | ownedOutput (unsigned int index=0) const |
Retrieves an owned Output pointer at a given index. | |
void | setPluggingStart (int start) |
Sets the position at which plugNext starts searching for an open input. | |
![]() | |
virtual | ~SynthFilter () |
Virtual destructor for the SynthFilter base class. | |
Static Public Member Functions | |
static force_inline mono_float | computeSvfOnePoleFilterCoefficient (mono_float frequency_ratio) |
Computes a one-pole SVF coefficient from a normalized frequency ratio. | |
static const SvfCoefficientLookup * | getSvfCoefficientLookup () |
Retrieves a pointer to the global SVF coefficient lookup table. | |
![]() | |
static force_inline mono_float | computeOnePoleFilterCoefficient (mono_float frequency_ratio) |
Computes a one-pole filter coefficient from a frequency ratio. | |
static const CoefficientLookup * | getCoefficientLookup () |
Retrieves a pointer to the static coefficient lookup table. | |
static SynthFilter * | createFilter (constants::FilterModel model) |
Factory method for creating a specialized filter based on a model enum. | |
Static Public Attributes | |
static constexpr mono_float | kDefaultMinResonance = 0.5f |
Default minimum resonance used when filtering (if not overridden). | |
static constexpr mono_float | kDefaultMaxResonance = 16.0f |
Default maximum resonance used when filtering (if not overridden). | |
static constexpr mono_float | kMinCutoff = 1.0f |
Minimum allowed cutoff frequency in Hz for the filter. | |
static constexpr mono_float | kMaxGain = 15.0f |
Maximum gain in dB for shelf or gain-based operations. | |
static constexpr mono_float | kMinGain = -15.0f |
Minimum gain in dB for shelf or gain-based operations. | |
static const SvfCoefficientLookup | svf_coefficient_lookup_ |
A static global lookup table instance for SVF coefficients. | |
![]() | |
static const CoefficientLookup | coefficient_lookup_ |
Static instance of the coefficient lookup table, generated at compile time. | |
Additional Inherited Members | |
![]() | |
Output * | addOutput (int oversample=1) |
Creates and registers a new Output. Handles control rate vs. audio rate. | |
Input * | addInput () |
Creates and registers a new Input, initially connected to null_source_. | |
![]() | |
std::shared_ptr< ProcessorState > | state_ |
Shared state (sample rate, oversample, etc.) | |
int | plugging_start_ |
The index at which plugNext starts searching for an unplugged input. | |
std::vector< std::shared_ptr< Input > > | owned_inputs_ |
Inputs owned by this Processor. | |
std::vector< std::shared_ptr< Output > > | owned_outputs_ |
Outputs owned by this Processor. | |
std::shared_ptr< std::vector< Input * > > | inputs_ |
All inputs, owned or external. | |
std::shared_ptr< std::vector< Output * > > | outputs_ |
All outputs, owned or external. | |
ProcessorRouter * | router_ |
The ProcessorRouter that manages this Processor. | |
![]() | |
FilterState | filter_state_ |
Internal storage of the most recent FilterState, used by derived filters. | |
![]() | |
static const Output | null_source_ |
A null (dummy) source used for unconnected inputs. | |
A state-variable filter (SVF) implementation, supporting multiple filter types (12/24 dB, shelving, dual modes).
The DigitalSvf class provides a flexible filter design that can morph between low-pass, high-pass, band-pass, notch, peak, and specialized dual filter modes. It optionally supports a basic or advanced processing path, drive compensation, and user-defined resonance bounds.
A lookup table type for quickly converting frequency ratios into filter coefficients.
vital::DigitalSvf::DigitalSvf | ( | ) |
Constructor that initializes the filter’s internal states.
Constructs a DigitalSvf object, resetting its internal states to defaults.
|
inlinevirtual |
Default destructor.
|
inlineoverridevirtual |
Creates a clone of this filter by invoking the copy constructor.
Implements vital::Processor.
|
inlinestatic |
Computes a one-pole SVF coefficient from a normalized frequency ratio.
Ensures the ratio is clamped so that tan() doesn’t blow up near Nyquist.
frequency_ratio | The normalized frequency in [0..0.5). |
|
inline |
Retrieves the current band-frequency mix portion.
|
inline |
Retrieves the final drive (post drive compensation) used in the filter.
|
inline |
Retrieves the current high-frequency mix portion.
|
inline |
Helper for a 24 dB filter style that may swap low/high in a dual notch band.
style | An integer enumerating the filter style. |
|
inline |
Retrieves the current low-frequency mix portion.
|
inline |
Helper for a 24 dB filter style that may swap low/high in a dual notch band.
style | An integer enumerating the filter style. |
|
inline |
Retrieves the current MIDI-based cutoff frequency.
|
inline |
Retrieves the current resonance value (inverted if needed).
|
inlinestatic |
Retrieves a pointer to the global SVF coefficient lookup table.
svf_coefficient_lookup_
.
|
overridevirtual |
Performs a complete reset of the filter states for all voices.
Performs a complete reset of all internal states for every voice.
Reimplemented from vital::Processor.
|
overridevirtual |
Processes a block of samples by pulling from the primary audio input and computing the SVF output. Delegates to processWithInput()
.
Processes a block of samples by reading from the main audio input, then calls processWithInput().
num_samples | Number of samples to process. |
Implements vital::Processor.
void vital::DigitalSvf::process12 | ( | const poly_float * | audio_in, |
int | num_samples, | ||
poly_float | current_resonance, | ||
poly_float | current_drive, | ||
poly_float | current_post_multiply, | ||
FilterValues & | blends ) |
Processes a 12 dB filter style, iterating through the block.
audio_in | Input audio data. |
num_samples | Number of samples in the buffer. |
current_resonance | Current resonance value (possibly interpolated). |
current_drive | Current drive value. |
current_post_multiply | Additional multiplier after the filter. |
blends | Filter mix gains (low/band/high). |
void vital::DigitalSvf::process24 | ( | const poly_float * | audio_in, |
int | num_samples, | ||
poly_float | current_resonance, | ||
poly_float | current_drive, | ||
poly_float | current_post_multiply, | ||
FilterValues & | blends ) |
Processes a 24 dB filter style, adding additional stages.
audio_in | Input audio data. |
num_samples | Number of samples in the buffer. |
current_resonance | Current resonance value. |
current_drive | Current drive value. |
current_post_multiply | Additional multiplier after the filter. |
blends | Filter mix gains (low/band/high). |
void vital::DigitalSvf::processBasic12 | ( | const poly_float * | audio_in, |
int | num_samples, | ||
poly_float | current_resonance, | ||
poly_float | current_drive, | ||
poly_float | current_post_multiply, | ||
FilterValues & | blends ) |
Processes a simpler 12 dB filter style, skipping extra color or overshoot logic.
audio_in | Input audio data. |
num_samples | Number of samples in the buffer. |
current_resonance | Current resonance value. |
current_drive | Current drive value. |
current_post_multiply | Additional multiplier after the filter. |
blends | Filter mix gains (low/band/high). |
void vital::DigitalSvf::processBasic24 | ( | const poly_float * | audio_in, |
int | num_samples, | ||
poly_float | current_resonance, | ||
poly_float | current_drive, | ||
poly_float | current_post_multiply, | ||
FilterValues & | blends ) |
Processes a simpler 24 dB filter style, skipping advanced processing.
audio_in | Input audio data. |
num_samples | Number of samples in the buffer. |
current_resonance | Current resonance value. |
current_drive | Current drive value. |
current_post_multiply | Additional multiplier after the filter. |
blends | Filter mix gains (low/band/high). |
void vital::DigitalSvf::processDual | ( | const poly_float * | audio_in, |
int | num_samples, | ||
poly_float | current_resonance, | ||
poly_float | current_drive, | ||
poly_float | current_post_multiply, | ||
FilterValues & | blends1, | ||
FilterValues & | blends2 ) |
Processes a dual filter mode, e.g., dual notch + band pass.
Splits filter processing into two sets of FilterValues (blends1 and blends2).
audio_in | Input audio data. |
num_samples | Number of samples to process. |
current_resonance | Current resonance value. |
current_drive | Current drive value. |
current_post_multiply | Additional multiplier. |
blends1 | The first set of filter mixes (low/band/high). |
blends2 | The second set of filter mixes (low/band/high). |
|
overridevirtual |
Processes a block of samples using a provided input buffer.
Detailed logic for processing a block of samples, handling filter style and interpolation.
Applies configured filter settings to compute the final output.
audio_in | Pointer to the input audio buffer. |
num_samples | Number of samples to process. |
audio_in | Pointer to the input audio buffer. |
num_samples | Number of samples to process. |
Reimplemented from vital::Processor.
|
overridevirtual |
Resets internal filter states for voices specified by the reset_masks
.
Resets specified voices in the filter’s internal state variables.
reset_masks | Mask specifying which voices to reset. |
reset_masks | The poly_mask selecting which voices to reset. |
Reimplemented from vital::Processor.
|
inline |
Sets whether this filter should use a simpler, “basic” processing path.
basic | If true, uses the simplified process path. |
|
inline |
Enables or disables drive compensation (reducing drive as resonance increases).
drive_compensation | If true, drive is reduced as resonance goes up. |
void vital::DigitalSvf::setResonanceBounds | ( | mono_float | min, |
mono_float | max ) |
Sets the minimum and maximum resonance for the filter (used in resonance interpolation).
min | The new minimum resonance value. |
max | The new maximum resonance value. |
|
overridevirtual |
Configures this SVF based on a FilterState (cutoff, resonance, style, etc.).
Configures the filter based on the provided FilterState, computing resonance, drive, etc.
filter_state | The FilterState containing all relevant parameters. |
filter_state | The FilterState containing style, cutoff, resonance, gain, etc. |
Implements vital::SynthFilter.
force_inline poly_float vital::DigitalSvf::tick | ( | poly_float | audio_in, |
poly_float | coefficient, | ||
poly_float | resonance, | ||
poly_float | drive, | ||
FilterValues & | blends ) |
Applies advanced distortion to the input while performing a single SVF tick (12 dB).
Tick function for advanced, saturating 12 dB filtering.
audio_in | The current input sample. |
drive | Amount of drive (pre-gain). |
resonance | The filter resonance. |
coefficient | The filter coefficient derived from cutoff. |
blends | The low/band/high mix values. |
audio_in | The current input sample. |
coefficient | The computed filter coefficient. |
resonance | The filter resonance. |
drive | Input drive multiplier. |
blends | The filter’s low/band/high mix. |
force_inline poly_float vital::DigitalSvf::tick24 | ( | poly_float | audio_in, |
poly_float | coefficient, | ||
poly_float | resonance, | ||
poly_float | drive, | ||
FilterValues & | blends ) |
Tick function for a 24 dB multi-stage filter, adding an additional pre-stage.
Tick function for 24 dB filtering, performing a pre-stage, saturating, then a second SVF pass.
audio_in | The current input sample. |
coefficient | The filter coefficient. |
resonance | The filter resonance. |
drive | The input drive multiplier. |
blends | The filter’s mix values (low/band/high). |
audio_in | The input sample. |
coefficient | The filter coefficient. |
resonance | The filter resonance. |
drive | Input drive multiplier. |
blends | Filter mixing parameters. |
force_inline poly_float vital::DigitalSvf::tickBasic | ( | poly_float | audio_in, |
poly_float | coefficient, | ||
poly_float | resonance, | ||
poly_float | drive, | ||
FilterValues & | blends ) |
A basic (non-distorting) single SVF tick for a 12 dB filter style.
A simpler single tick for a 12 dB filter, skipping advanced distortion.
audio_in | The current input sample. |
coefficient | The filter coefficient derived from cutoff. |
resonance | The filter resonance. |
drive | The input drive multiplier. |
blends | The filter’s mix values for low/band/high output. |
audio_in | The input sample. |
coefficient | The filter coefficient from the lookup. |
resonance | The filter resonance (inverted). |
drive | The input drive multiplier. |
blends | Low/band/high mix factors. |
force_inline poly_float vital::DigitalSvf::tickBasic24 | ( | poly_float | audio_in, |
poly_float | coefficient, | ||
poly_float | resonance, | ||
poly_float | drive, | ||
FilterValues & | blends ) |
A simpler 24 dB tick function without advanced distortion or color.
Basic, non-distorting 24 dB filter tick.
audio_in | The current input sample. |
coefficient | The filter coefficient. |
resonance | The filter resonance. |
drive | The input drive multiplier. |
blends | The filter’s mix values (low/band/high). |
audio_in | The input sample. |
coefficient | The filter coefficient. |
resonance | The filter resonance. |
drive | Input drive multiplier. |
blends | Filter mixing parameters. |
force_inline poly_float vital::DigitalSvf::tickDual | ( | poly_float | audio_in, |
poly_float | coefficient, | ||
poly_float | resonance, | ||
poly_float | drive, | ||
FilterValues & | blends1, | ||
FilterValues & | blends2 ) |
Tick function for a dual filter approach, e.g. notch + band, etc.
A dual-stage filter approach, e.g., for dual notch/band passes.
audio_in | The current input sample. |
coefficient | The filter coefficient (cutoff). |
resonance | The filter resonance. |
drive | The input drive multiplier. |
blends1 | Low/band/high mixing for the first filter pass. |
blends2 | Low/band/high mixing for the second filter pass. |
audio_in | The input sample. |
coefficient | The filter coefficient. |
resonance | Filter resonance. |
drive | Input drive multiplier. |
blends1 | The first filter stage blends. |
blends2 | The second filter stage blends. |
|
staticconstexpr |
Default maximum resonance used when filtering (if not overridden).
|
staticconstexpr |
Default minimum resonance used when filtering (if not overridden).
|
staticconstexpr |
Maximum gain in dB for shelf or gain-based operations.
|
staticconstexpr |
Minimum allowed cutoff frequency in Hz for the filter.
|
staticconstexpr |
Minimum gain in dB for shelf or gain-based operations.
|
static |
A static global lookup table instance for SVF coefficients.
The global SVF coefficient lookup table instance.
Initializes a 2048-entry table converting normalized frequency ratios to one-pole filter coefficients using computeSvfOnePoleFilterCoefficient().