DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::FilterEngine< T, MaxChannels > Class Template Reference

Professional multi-mode filter with cascaded biquad stages. More...

#include <Filters.h>

Collaboration diagram for dspark::FilterEngine< T, MaxChannels >:

Classes

struct  ButterworthCascade
 
struct  CascadeInfo
 Per-stage Butterworth cascade layout for an LP/HP slope (for analysis). More...
 

Public Types

enum class  Shape {
  LowPass , HighPass , BandPass , Peak ,
  LowShelf , HighShelf , Notch , AllPass ,
  Tilt
}
 Supported filter shapes. More...
 
enum class  Structure { DirectForm , Ladder }
 How each second-order section is realised (see setStructure()). More...
 

Public Member Functions

 ~FilterEngine ()=default
 
void prepare (const AudioSpec &spec)
 Initializes the filter engine with the current audio specification.
 
void reset () noexcept
 Resets the internal state of all cascaded biquads and smoothers. Prevents clicks when relocating playback or enabling the effect.
 
void setLowPass (float freq, float Q=0.707f, int slopeDb=12)
 Configures a low-pass filter.
 
void setHighPass (float freq, float Q=0.707f, int slopeDb=12)
 Configures a high-pass filter.
 
void setBandPass (float freq, float Q=0.707f)
 Configures a band-pass filter (fixed 12 dB/oct).
 
void setPeaking (float freq, float gainDb, float Q=1.0f)
 Configures a peaking / bell EQ filter.
 
void setLowShelf (float freq, float gainDb, float slope=1.0f)
 Configures a low-shelf EQ filter.
 
void setHighShelf (float freq, float gainDb, float slope=1.0f)
 Configures a high-shelf EQ filter.
 
void setNotch (float freq, float Q=10.0f)
 Configures a notch (band-reject) filter.
 
void setAllPass (float freq, float Q=0.707f)
 Configures an all-pass filter (shifts phase, flat frequency response).
 
void setTilt (float centerFreq, float gainDb)
 Configures a tilt EQ filter (boost highs/cut lows or vice versa).
 
void setMatchedPeak (bool enabled) noexcept
 Selects the analog-matched (de-cramped) design for Peak bells.
 
bool isMatchedPeak () const noexcept
 Returns whether Peak bells use the matched (de-cramped) design.
 
void setMatchedFilters (bool enabled) noexcept
 Selects the analog-matched designs for the other shapes.
 
bool isMatchedFilters () const noexcept
 Returns whether the non-bell shapes use the matched designs.
 
void setStructure (Structure structure) noexcept
 Chooses how the sections are realised.
 
Structure getStructure () const noexcept
 
void setShelfSlope (float slope) noexcept
 Sets the shelf slope S on its own (LowShelf/HighShelf shapes).
 
float getShelfSlope () const noexcept
 Returns the shelf slope S used by the shelf shapes.
 
Shape getShape () const noexcept
 Returns the active filter shape.
 
int getSlopeDb () const noexcept
 Returns the active slope in dB/oct (LP/HP only - others = 12).
 
void setShape (Shape newShape, int slopeDb=12) noexcept
 Switches the filter topology while keeping the current frequency, resonance, and gain unchanged.
 
void setFrequency (float freq) noexcept
 Sets the target cutoff/center frequency. Thread-safe.
 
void setResonance (float Q) noexcept
 Sets the target resonance/Q. Thread-safe.
 
void setGain (float dB) noexcept
 Sets the target gain in dB. Thread-safe.
 
void setNonlinearity (T amount) noexcept
 Sets the nonlinearity amount. Thread-safe.
 
void enableAnalogDrift (AnalogRandom::AnalogComponent component, float intensity=0.5f)
 Enables analog-style low-frequency modulation of the cutoff.
 
void disableAnalogDrift () noexcept
 Disables analog-style drift modulation. Thread-safe.
 
void setDriftSeed (std::uint64_t seed) noexcept
 Makes the analog drift reproducible.
 
std::uint64_t getDriftSeed () const noexcept
 The drift seed set by setDriftSeed(); 0 when the drift uses the instance's own unique seed.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes an entire block of audio data. Internally branches into static, smoothed, or nonlinear processing paths to optimize CPU usage and allow auto-vectorization when possible.
 
T processSample (T input, int channel) noexcept
 Processes a single sample without parameter smoothing or coefficient updates.
 
void applyParametersNow () noexcept
 Applies pending parameter targets immediately and rebuilds the coefficients (no smoothing: values jump).
 
std::vector< uint8_t > getState () const
 Serializes the parameter state (setup/UI threads; allocates).
 
bool setState (const uint8_t *data, size_t size)
 Restores parameters from a blob (tolerant; rejects foreign ids).
 

Static Public Member Functions

static CascadeInfo cascadeForSlope (int slopeDb, float userQ=0.707f) noexcept
 Returns the exact Butterworth cascade (first-order flag + per-stage Q values) used internally for a given LP/HP slope. Lets callers reproduce the true cascade magnitude instead of approximating with a single Q.
 

Protected Member Functions

int activeStages () const noexcept
 Stages in use; bounded here so every loop over them is seen to stay inside the stage arrays.
 
void syncLadders () noexcept
 The ladders take the sections' coefficients at once (ends their ramps).
 
void updateCoefficients (float freq, float Q, float gainDb) noexcept
 Designs and installs the coefficients at once (static path).
 
void startCoefficientRamp (float freq, float Q, float gainDb) noexcept
 Designs the coefficients of a chunk refresh and starts the ramp from the active coefficients towards them.
 
int designCoefficients (float freq, float Q, float gainDb, std::array< BiquadCoeffs, kMaxStages > &out) const noexcept
 Designs the cascade into out[]; returns the stage count.
 

Static Protected Member Functions

static ButterworthCascade computeCascade (int slopeDb) noexcept
 
static int slopeToStages (int slopeDb) noexcept
 

Protected Attributes

AudioSpec spec_ {}
 
std::atomic< Shape > shape_ { Shape::LowPass }
 
std::atomic< int > numStages_ { 1 }
 
std::atomic< int > slopeDb_ { 12 }
 
std::atomic< float > shelfSlope_ { 1.0f }
 
std::atomic< bool > matchedPeak_ { false }
 
std::atomic< bool > matchedFilters_ { false }
 
std::array< BiquadCoeffs, kMaxStages > stageCoeffs_ {}
 The coefficients in use (their record for the ramps and the ladders).
 
BiquadCascade< T, kMaxStages, MaxChannels > cascade_
 The sections, run in one pass.
 
std::array< NormalizedLadder< T, MaxChannels >, kMaxStages > ladders_ {}
 The sections as ladders (setStructure()).
 
std::atomic< Structure > structure_ { Structure::DirectForm }
 
bool ladderActive_ = false
 The audio thread runs the ladders.
 
Smoothers::HermiteSmoother freqSmoother_
 
Smoothers::LinearSmoother resSmoother_
 
Smoothers::LinearSmoother gainSmoother_
 
std::atomic< float > targetFreq_ {1000.0f}
 
std::atomic< float > targetRes_ {0.707f}
 
std::atomic< float > targetGain_ {0.0f}
 
std::atomic< float > targetNonlinearity_ {0.0f}
 
std::atomic< bool > driftEnabled_ { false }
 
std::atomic< float > driftIntensity_ { 0.0f }
 
std::atomic< std::uint64_t > driftSeed_ { 0 }
 0 = the instance's unique seed.
 
AnalogRandom::Generator< float > driftGen_
 
float lastFreq_ = -1.0f
 
float lastQ_ = -1.0f
 
float lastGain_ = -1e9f
 
Shape lastShape_ = Shape::LowPass
 
int lastSlopeDb_ = -1
 
bool lastMatched_ = false
 
bool lastMatchedFilters_ = false
 
float lastShelfSlope_ = -1.0f
 Shelf S: a slope-only change must rebuild coeffs.
 
bool snapNext_ = true
 Next block skips the smoothers to their targets.
 
unsigned chunkPhase_ = 0
 Stream position in the 16-sample refresh grid.
 
std::array< BiquadCoeffs, kMaxStages > rampTo_ {}
 
int rampPos_ = kChunkSize
 Samples into the ramp; kChunkSize = settled on rampTo_.
 
Shape rampShape_ = Shape::LowPass
 
int rampSlopeDb_ = -1
 

Static Protected Attributes

static constexpr int kMaxStages = 4
 
static constexpr int kChunkSize = 16
 Samples between coefficient designs in the dynamic path.
 
static constexpr int kMaxOrder = 8
 
static constexpr float kFreqGlideMs = 165.0f
 Cutoff glide time (10-90% in 100 ms).
 

Detailed Description

template<typename T, int MaxChannels = 16>
class dspark::FilterEngine< T, MaxChannels >

Professional multi-mode filter with cascaded biquad stages.

Utilizes SIMD-friendly branching and atomic parameter states for thread-safe real-time manipulation.

Template Parameters
TSample type (float or double).
MaxChannelsMaximum number of audio channels allowed.

Definition at line 85 of file Filters.h.

Member Enumeration Documentation

◆ Shape

template<typename T , int MaxChannels = 16>
enum class dspark::FilterEngine::Shape
strong

Supported filter shapes.

Enumerator
LowPass 
HighPass 
BandPass 
Peak 
LowShelf 
HighShelf 
Notch 
AllPass 
Tilt 

Definition at line 94 of file Filters.h.

◆ Structure

template<typename T , int MaxChannels = 16>
enum class dspark::FilterEngine::Structure
strong

How each second-order section is realised (see setStructure()).

Enumerator
DirectForm 

Direct form with a double memory: the cheapest (default).

Ladder 

Normalized ladder: passive under any change of its coefficients.

Definition at line 327 of file Filters.h.

Constructor & Destructor Documentation

◆ ~FilterEngine()

template<typename T , int MaxChannels = 16>
dspark::FilterEngine< T, MaxChannels >::~FilterEngine ( )
default

Member Function Documentation

◆ activeStages()

template<typename T , int MaxChannels = 16>
int dspark::FilterEngine< T, MaxChannels >::activeStages ( ) const
inlineprotectednoexcept

Stages in use; bounded here so every loop over them is seen to stay inside the stage arrays.

Definition at line 889 of file Filters.h.

◆ applyParametersNow()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::applyParametersNow ( )
inlinenoexcept

Applies pending parameter targets immediately and rebuilds the coefficients (no smoothing: values jump).

For per-sample workflows where processBlock() never runs, so the atomic parameter targets would otherwise never reach the biquad stages. Owner (audio) thread only, like processSample().

Definition at line 797 of file Filters.h.

◆ cascadeForSlope()

template<typename T , int MaxChannels = 16>
static CascadeInfo dspark::FilterEngine< T, MaxChannels >::cascadeForSlope ( int  slopeDb,
float  userQ = 0.707f 
)
inlinestaticnoexcept

Returns the exact Butterworth cascade (first-order flag + per-stage Q values) used internally for a given LP/HP slope. Lets callers reproduce the true cascade magnitude instead of approximating with a single Q.

Parameters
slopeDbSlope in dB/octave (6..48).
userQThe engine's resonance parameter: scales the final stage exactly as updateCoefficients() does (neutral at the 0.707 default, resonant peak above it).

Definition at line 397 of file Filters.h.

◆ computeCascade()

template<typename T , int MaxChannels = 16>
static ButterworthCascade dspark::FilterEngine< T, MaxChannels >::computeCascade ( int  slopeDb)
inlinestaticprotectednoexcept

Definition at line 902 of file Filters.h.

◆ designCoefficients()

template<typename T , int MaxChannels = 16>
int dspark::FilterEngine< T, MaxChannels >::designCoefficients ( float  freq,
float  Q,
float  gainDb,
std::array< BiquadCoeffs, kMaxStages > &  out 
) const
inlineprotectednoexcept

Designs the cascade into out[]; returns the stage count.

Definition at line 979 of file Filters.h.

◆ disableAnalogDrift()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::disableAnalogDrift ( )
inlinenoexcept

Disables analog-style drift modulation. Thread-safe.

Definition at line 513 of file Filters.h.

◆ enableAnalogDrift()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::enableAnalogDrift ( AnalogRandom::AnalogComponent  component,
float  intensity = 0.5f 
)
inline

Enables analog-style low-frequency modulation of the cutoff.

Note
Setup thread only (it re-prepares the internal generator, which is not safe concurrently with processBlock). Call prepare() first so the generator receives the real sample rate.
Parameters
componentThe analog component profile to simulate.
intensityModulation depth (0.0 to 1.0). Non-finite values are ignored.

Definition at line 501 of file Filters.h.

◆ getDriftSeed()

template<typename T , int MaxChannels = 16>
std::uint64_t dspark::FilterEngine< T, MaxChannels >::getDriftSeed ( ) const
inlinenoexcept

The drift seed set by setDriftSeed(); 0 when the drift uses the instance's own unique seed.

Definition at line 536 of file Filters.h.

◆ getShape()

template<typename T , int MaxChannels = 16>
Shape dspark::FilterEngine< T, MaxChannels >::getShape ( ) const
inlinenoexcept

Returns the active filter shape.

Definition at line 379 of file Filters.h.

◆ getShelfSlope()

template<typename T , int MaxChannels = 16>
float dspark::FilterEngine< T, MaxChannels >::getShelfSlope ( ) const
inlinenoexcept

Returns the shelf slope S used by the shelf shapes.

Definition at line 373 of file Filters.h.

◆ getSlopeDb()

template<typename T , int MaxChannels = 16>
int dspark::FilterEngine< T, MaxChannels >::getSlopeDb ( ) const
inlinenoexcept

Returns the active slope in dB/oct (LP/HP only - others = 12).

Definition at line 382 of file Filters.h.

◆ getState()

template<typename T , int MaxChannels = 16>
std::vector< uint8_t > dspark::FilterEngine< T, MaxChannels >::getState ( ) const
inline

Serializes the parameter state (setup/UI threads; allocates).

Definition at line 829 of file Filters.h.

◆ getStructure()

template<typename T , int MaxChannels = 16>
Structure dspark::FilterEngine< T, MaxChannels >::getStructure ( ) const
inlinenoexcept
Returns
How the sections are realised.

Definition at line 352 of file Filters.h.

◆ isMatchedFilters()

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::isMatchedFilters ( ) const
inlinenoexcept

Returns whether the non-bell shapes use the matched designs.

Definition at line 321 of file Filters.h.

◆ isMatchedPeak()

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::isMatchedPeak ( ) const
inlinenoexcept

Returns whether Peak bells use the matched (de-cramped) design.

Definition at line 298 of file Filters.h.

◆ prepare()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::prepare ( const AudioSpec &  spec)
inline

Initializes the filter engine with the current audio specification.

Parameters
specThe audio specification containing sample rate and block size. An invalid spec (non-positive or NaN fields) is ignored.

Definition at line 107 of file Filters.h.

◆ processBlock()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes an entire block of audio data. Internally branches into static, smoothed, or nonlinear processing paths to optimize CPU usage and allow auto-vectorization when possible.

Parameters
bufferView of the audio buffer to process in-place.

Definition at line 550 of file Filters.h.

◆ processSample()

template<typename T , int MaxChannels = 16>
T dspark::FilterEngine< T, MaxChannels >::processSample ( T  input,
int  channel 
)
inlinenoexcept

Processes a single sample without parameter smoothing or coefficient updates.

Warning
Must only be used when parameter changes are managed externally: call applyParametersNow() after changing parameters, or rely on processBlock() to consume them (it smooths).
Parameters
inputInput sample value.
channelIndex of the audio channel being processed. Out-of-range channels return the input unprocessed (the per-channel biquad state is bounded to MaxChannels).
Returns
T Processed sample value.

Definition at line 774 of file Filters.h.

◆ reset()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::reset ( )
inlinenoexcept

Resets the internal state of all cascaded biquads and smoothers. Prevents clicks when relocating playback or enabling the effect.

Definition at line 130 of file Filters.h.

◆ setAllPass()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setAllPass ( float  freq,
float  Q = 0.707f 
)
inline

Configures an all-pass filter (shifts phase, flat frequency response).

Parameters
freqPhase transition center frequency in Hz.
QQuality factor.

Definition at line 260 of file Filters.h.

◆ setBandPass()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setBandPass ( float  freq,
float  Q = 0.707f 
)
inline

Configures a band-pass filter (fixed 12 dB/oct).

Parameters
freqTarget center frequency in Hz.
QQuality factor (bandwidth control).

Definition at line 184 of file Filters.h.

◆ setDriftSeed()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setDriftSeed ( std::uint64_t  seed)
inlinenoexcept

Makes the analog drift reproducible.

By default every instance draws its drift from its own unique seed, so two filters never wander together and no two renders of the same session drift alike. A non-zero seed pins the drift instead: from the next block, and again after every reset() and prepare(), the drift sequence restarts from that seed, so rendering the same input twice with the same settings produces the same output sample for sample. Zero returns to the default unique seed, and the drift carries on from wherever it is. Thread-safe, lock free; applied on the audio thread's next block.

Definition at line 528 of file Filters.h.

◆ setFrequency()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setFrequency ( float  freq)
inlinenoexcept

Sets the target cutoff/center frequency. Thread-safe.

Parameters
freqFrequency in Hz. Non-finite values are ignored.

Definition at line 447 of file Filters.h.

◆ setGain()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setGain ( float  dB)
inlinenoexcept

Sets the target gain in dB. Thread-safe.

Parameters
dBGain in decibels. Non-finite values are ignored.

Definition at line 473 of file Filters.h.

◆ setHighPass()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setHighPass ( float  freq,
float  Q = 0.707f,
int  slopeDb = 12 
)
inline

Configures a high-pass filter.

Parameters
freqTarget cutoff frequency in Hz.
QQuality factor (0.707 = Butterworth).
slopeDbSlope in dB/octave (6, 12, 18, 24, 30, 36, 42, 48).

Definition at line 170 of file Filters.h.

◆ setHighShelf()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setHighShelf ( float  freq,
float  gainDb,
float  slope = 1.0f 
)
inline

Configures a high-shelf EQ filter.

Parameters
freqTarget transition frequency in Hz.
gainDbGain in dB to boost or cut.
slopeShelf transition slope (1.0 = standard).

Definition at line 231 of file Filters.h.

◆ setLowPass()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setLowPass ( float  freq,
float  Q = 0.707f,
int  slopeDb = 12 
)
inline

Configures a low-pass filter.

Parameters
freqTarget cutoff frequency in Hz.
QQuality factor (0.707 = Butterworth).
slopeDbSlope in dB/octave (6, 12, 18, 24, 30, 36, 42, 48).

Definition at line 155 of file Filters.h.

◆ setLowShelf()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setLowShelf ( float  freq,
float  gainDb,
float  slope = 1.0f 
)
inline

Configures a low-shelf EQ filter.

Parameters
freqTarget transition frequency in Hz.
gainDbGain in dB to boost or cut.
slopeShelf transition slope (1.0 = standard).

Definition at line 215 of file Filters.h.

◆ setMatchedFilters()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setMatchedFilters ( bool  enabled)
inlinenoexcept

Selects the analog-matched designs for the other shapes.

The counterpart of setMatchedPeak() for LowPass/HighPass (their second-order sections), BandPass and the shelves at slope 1 (BiquadCoeffs::make*Matched, after Vicanek): high corners keep their analog shape instead of cramping toward Nyquist. First-order sections, shelves with a slope below 1, Notch, AllPass and Tilt keep the bilinear design. Off by default (bit-compatible with previous output). Thread-safe. Not serialized by getState()/setState(); owners that persist it must re-apply it on restore (Equalizer does).

Definition at line 315 of file Filters.h.

◆ setMatchedPeak()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setMatchedPeak ( bool  enabled)
inlinenoexcept

Selects the analog-matched (de-cramped) design for Peak bells.

Bilinear bells cramp near Nyquist; the matched design (BiquadCoeffs::makePeakMatched) keeps high bells on their analog shape. Off by default (bit-compatible with previous output). Thread-safe. Not serialized by getState()/setState(); owners that persist it must re-apply it on restore (Equalizer does).

Definition at line 292 of file Filters.h.

◆ setNonlinearity()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setNonlinearity ( T  amount)
inlinenoexcept

Sets the nonlinearity amount. Thread-safe.

Parameters
amount0 = linear (default), 1 = full nonlinearity. Non-finite values are ignored.

Definition at line 484 of file Filters.h.

◆ setNotch()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setNotch ( float  freq,
float  Q = 10.0f 
)
inline

Configures a notch (band-reject) filter.

Parameters
freqTarget center frequency in Hz.
QQuality factor (bandwidth of the cut).

Definition at line 246 of file Filters.h.

◆ setPeaking()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setPeaking ( float  freq,
float  gainDb,
float  Q = 1.0f 
)
inline

Configures a peaking / bell EQ filter.

Parameters
freqTarget center frequency in Hz.
gainDbGain in dB to boost or cut.
QQuality factor.

Definition at line 199 of file Filters.h.

◆ setResonance()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setResonance ( float  Q)
inlinenoexcept

Sets the target resonance/Q. Thread-safe.

For LowPass/HighPass the cascade stays an exact Butterworth at the default Q (0.707) and larger values scale the final (most resonant) stage, adding the classic resonant peak at the cutoff. The 6 dB/oct slope is first-order and has no Q.

Parameters
QQuality factor. Non-finite values are ignored.

Definition at line 463 of file Filters.h.

◆ setShape()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setShape ( Shape  newShape,
int  slopeDb = 12 
)
inlinenoexcept

Switches the filter topology while keeping the current frequency, resonance, and gain unchanged.

Useful for UI dropdowns where the user expects the existing slider values to carry over when they pick a different filter type. For one-shot setup with explicit parameters, the setLowPass()/setPeaking()/etc. helpers are still preferred.

Parameters
newShapeTarget filter shape. Out-of-range values (a wild cast or corrupt state blob) are clamped into the enum range.
slopeDbSlope in dB/octave (only used by LP/HP, default 12).

Definition at line 422 of file Filters.h.

◆ setShelfSlope()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setShelfSlope ( float  slope)
inlinenoexcept

Sets the shelf slope S on its own (LowShelf/HighShelf shapes).

The granular counterpart of the slope argument of setLowShelf() / setHighShelf(), for parameter models with one setter per parameter. RBJ semantics: 1.0 is the steepest shelf without overshoot, smaller values are gentler. Clamped to [0.0001, 1]; non-finite values are ignored (a NaN slope would otherwise pass the design clamp and turn every coefficient into NaN). Thread-safe; applied at the next block.

Parameters
slopeShelf slope S in (0, 1].

Definition at line 366 of file Filters.h.

◆ setState()

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores parameters from a blob (tolerant; rejects foreign ids).

Definition at line 844 of file Filters.h.

◆ setStructure()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setStructure ( Structure  structure)
inlinenoexcept

Chooses how the sections are realised.

Ladder runs every section as a normalized ladder (NormalizedLadder): the same response, and a memory that can only lose energy however fast the cutoff moves (audio-rate modulation, hard jumps of the shape), for about twice the arithmetic. The coefficients ramp on the same 16-sample grid. Thread-safe; the switch restarts the sections' memory at the next block, which may click: choose it before playback.

Parameters
structureDirectForm (default) or Ladder.

Definition at line 345 of file Filters.h.

◆ setTilt()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::setTilt ( float  centerFreq,
float  gainDb 
)
inline

Configures a tilt EQ filter (boost highs/cut lows or vice versa).

Parameters
centerFreqPivot frequency in Hz.
gainDbPositive = bright, negative = dark.

Definition at line 274 of file Filters.h.

◆ slopeToStages()

template<typename T , int MaxChannels = 16>
static int dspark::FilterEngine< T, MaxChannels >::slopeToStages ( int  slopeDb)
inlinestaticprotectednoexcept

Definition at line 924 of file Filters.h.

◆ startCoefficientRamp()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::startCoefficientRamp ( float  freq,
float  Q,
float  gainDb 
)
inlineprotectednoexcept

Designs the coefficients of a chunk refresh and starts the ramp from the active coefficients towards them.

A topology change (stage count, shape or slope) cannot be interpolated and installs the new design at once.

Definition at line 958 of file Filters.h.

◆ syncLadders()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::syncLadders ( )
inlineprotectednoexcept

The ladders take the sections' coefficients at once (ends their ramps).

Definition at line 931 of file Filters.h.

◆ updateCoefficients()

template<typename T , int MaxChannels = 16>
void dspark::FilterEngine< T, MaxChannels >::updateCoefficients ( float  freq,
float  Q,
float  gainDb 
)
inlineprotectednoexcept

Designs and installs the coefficients at once (static path).

Definition at line 938 of file Filters.h.

Member Data Documentation

◆ cascade_

template<typename T , int MaxChannels = 16>
BiquadCascade<T, kMaxStages, MaxChannels> dspark::FilterEngine< T, MaxChannels >::cascade_
protected

The sections, run in one pass.

Definition at line 1078 of file Filters.h.

◆ chunkPhase_

template<typename T , int MaxChannels = 16>
unsigned dspark::FilterEngine< T, MaxChannels >::chunkPhase_ = 0
protected

Stream position in the 16-sample refresh grid.

Definition at line 1111 of file Filters.h.

◆ driftEnabled_

template<typename T , int MaxChannels = 16>
std::atomic<bool> dspark::FilterEngine< T, MaxChannels >::driftEnabled_ { false }
protected

Definition at line 1096 of file Filters.h.

◆ driftGen_

template<typename T , int MaxChannels = 16>
AnalogRandom::Generator<float> dspark::FilterEngine< T, MaxChannels >::driftGen_
protected

Definition at line 1099 of file Filters.h.

◆ driftIntensity_

template<typename T , int MaxChannels = 16>
std::atomic<float> dspark::FilterEngine< T, MaxChannels >::driftIntensity_ { 0.0f }
protected

Definition at line 1097 of file Filters.h.

◆ driftSeed_

template<typename T , int MaxChannels = 16>
std::atomic<std::uint64_t> dspark::FilterEngine< T, MaxChannels >::driftSeed_ { 0 }
protected

0 = the instance's unique seed.

Definition at line 1098 of file Filters.h.

◆ freqSmoother_

template<typename T , int MaxChannels = 16>
Smoothers::HermiteSmoother dspark::FilterEngine< T, MaxChannels >::freqSmoother_
protected

Definition at line 1084 of file Filters.h.

◆ gainSmoother_

template<typename T , int MaxChannels = 16>
Smoothers::LinearSmoother dspark::FilterEngine< T, MaxChannels >::gainSmoother_
protected

Definition at line 1085 of file Filters.h.

◆ kChunkSize

template<typename T , int MaxChannels = 16>
constexpr int dspark::FilterEngine< T, MaxChannels >::kChunkSize = 16
staticconstexprprotected

Samples between coefficient designs in the dynamic path.

Definition at line 885 of file Filters.h.

◆ kFreqGlideMs

template<typename T , int MaxChannels = 16>
constexpr float dspark::FilterEngine< T, MaxChannels >::kFreqGlideMs = 165.0f
staticconstexprprotected

Cutoff glide time (10-90% in 100 ms).

Definition at line 1083 of file Filters.h.

◆ kMaxOrder

template<typename T , int MaxChannels = 16>
constexpr int dspark::FilterEngine< T, MaxChannels >::kMaxOrder = 8
staticconstexprprotected

Definition at line 886 of file Filters.h.

◆ kMaxStages

template<typename T , int MaxChannels = 16>
constexpr int dspark::FilterEngine< T, MaxChannels >::kMaxStages = 4
staticconstexprprotected

Definition at line 884 of file Filters.h.

◆ ladderActive_

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::ladderActive_ = false
protected

The audio thread runs the ladders.

Definition at line 1081 of file Filters.h.

◆ ladders_

template<typename T , int MaxChannels = 16>
std::array<NormalizedLadder<T, MaxChannels>, kMaxStages> dspark::FilterEngine< T, MaxChannels >::ladders_ {}
protected

The sections as ladders (setStructure()).

Definition at line 1079 of file Filters.h.

◆ lastFreq_

template<typename T , int MaxChannels = 16>
float dspark::FilterEngine< T, MaxChannels >::lastFreq_ = -1.0f
protected

Definition at line 1102 of file Filters.h.

◆ lastGain_

template<typename T , int MaxChannels = 16>
float dspark::FilterEngine< T, MaxChannels >::lastGain_ = -1e9f
protected

Definition at line 1104 of file Filters.h.

◆ lastMatched_

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::lastMatched_ = false
protected

Definition at line 1107 of file Filters.h.

◆ lastMatchedFilters_

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::lastMatchedFilters_ = false
protected

Definition at line 1108 of file Filters.h.

◆ lastQ_

template<typename T , int MaxChannels = 16>
float dspark::FilterEngine< T, MaxChannels >::lastQ_ = -1.0f
protected

Definition at line 1103 of file Filters.h.

◆ lastShape_

template<typename T , int MaxChannels = 16>
Shape dspark::FilterEngine< T, MaxChannels >::lastShape_ = Shape::LowPass
protected

Definition at line 1105 of file Filters.h.

◆ lastShelfSlope_

template<typename T , int MaxChannels = 16>
float dspark::FilterEngine< T, MaxChannels >::lastShelfSlope_ = -1.0f
protected

Shelf S: a slope-only change must rebuild coeffs.

Definition at line 1109 of file Filters.h.

◆ lastSlopeDb_

template<typename T , int MaxChannels = 16>
int dspark::FilterEngine< T, MaxChannels >::lastSlopeDb_ = -1
protected

Definition at line 1106 of file Filters.h.

◆ matchedFilters_

template<typename T , int MaxChannels = 16>
std::atomic<bool> dspark::FilterEngine< T, MaxChannels >::matchedFilters_ { false }
protected

Definition at line 1075 of file Filters.h.

◆ matchedPeak_

template<typename T , int MaxChannels = 16>
std::atomic<bool> dspark::FilterEngine< T, MaxChannels >::matchedPeak_ { false }
protected

Definition at line 1074 of file Filters.h.

◆ numStages_

template<typename T , int MaxChannels = 16>
std::atomic<int> dspark::FilterEngine< T, MaxChannels >::numStages_ { 1 }
protected

Definition at line 1071 of file Filters.h.

◆ rampPos_

template<typename T , int MaxChannels = 16>
int dspark::FilterEngine< T, MaxChannels >::rampPos_ = kChunkSize
protected

Samples into the ramp; kChunkSize = settled on rampTo_.

Definition at line 1115 of file Filters.h.

◆ rampShape_

template<typename T , int MaxChannels = 16>
Shape dspark::FilterEngine< T, MaxChannels >::rampShape_ = Shape::LowPass
protected

Definition at line 1116 of file Filters.h.

◆ rampSlopeDb_

template<typename T , int MaxChannels = 16>
int dspark::FilterEngine< T, MaxChannels >::rampSlopeDb_ = -1
protected

Definition at line 1117 of file Filters.h.

◆ rampTo_

template<typename T , int MaxChannels = 16>
std::array<BiquadCoeffs, kMaxStages> dspark::FilterEngine< T, MaxChannels >::rampTo_ {}
protected

Definition at line 1114 of file Filters.h.

◆ resSmoother_

template<typename T , int MaxChannels = 16>
Smoothers::LinearSmoother dspark::FilterEngine< T, MaxChannels >::resSmoother_
protected

Definition at line 1085 of file Filters.h.

◆ shape_

template<typename T , int MaxChannels = 16>
std::atomic<Shape> dspark::FilterEngine< T, MaxChannels >::shape_ { Shape::LowPass }
protected

Definition at line 1070 of file Filters.h.

◆ shelfSlope_

template<typename T , int MaxChannels = 16>
std::atomic<float> dspark::FilterEngine< T, MaxChannels >::shelfSlope_ { 1.0f }
protected

Definition at line 1073 of file Filters.h.

◆ slopeDb_

template<typename T , int MaxChannels = 16>
std::atomic<int> dspark::FilterEngine< T, MaxChannels >::slopeDb_ { 12 }
protected

Definition at line 1072 of file Filters.h.

◆ snapNext_

template<typename T , int MaxChannels = 16>
bool dspark::FilterEngine< T, MaxChannels >::snapNext_ = true
protected

Next block skips the smoothers to their targets.

Definition at line 1110 of file Filters.h.

◆ spec_

template<typename T , int MaxChannels = 16>
AudioSpec dspark::FilterEngine< T, MaxChannels >::spec_ {}
protected

Definition at line 1066 of file Filters.h.

◆ stageCoeffs_

template<typename T , int MaxChannels = 16>
std::array<BiquadCoeffs, kMaxStages> dspark::FilterEngine< T, MaxChannels >::stageCoeffs_ {}
protected

The coefficients in use (their record for the ramps and the ladders).

Definition at line 1077 of file Filters.h.

◆ structure_

template<typename T , int MaxChannels = 16>
std::atomic<Structure> dspark::FilterEngine< T, MaxChannels >::structure_ { Structure::DirectForm }
protected

Definition at line 1080 of file Filters.h.

◆ targetFreq_

template<typename T , int MaxChannels = 16>
std::atomic<float> dspark::FilterEngine< T, MaxChannels >::targetFreq_ {1000.0f}
protected

Definition at line 1088 of file Filters.h.

◆ targetGain_

template<typename T , int MaxChannels = 16>
std::atomic<float> dspark::FilterEngine< T, MaxChannels >::targetGain_ {0.0f}
protected

Definition at line 1090 of file Filters.h.

◆ targetNonlinearity_

template<typename T , int MaxChannels = 16>
std::atomic<float> dspark::FilterEngine< T, MaxChannels >::targetNonlinearity_ {0.0f}
protected

Definition at line 1091 of file Filters.h.

◆ targetRes_

template<typename T , int MaxChannels = 16>
std::atomic<float> dspark::FilterEngine< T, MaxChannels >::targetRes_ {0.707f}
protected

Definition at line 1089 of file Filters.h.


The documentation for this class was generated from the following file: