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

Dynamic parametric EQ with dual above/below threshold per band. More...

#include <DynamicEQ.h>

Classes

struct  BandConfig
 Full configuration for a single dynamic EQ band. More...
 

Public Types

enum class  BandShape { Bell , LowShelf , HighShelf }
 Shape of the dynamic gain filter (and its detector region). More...
 
enum class  Scope {
  Stereo , Left , Right , Mid ,
  Side
}
 Where in a stereo pair a band acts and listens. More...
 
enum class  Timing { Manual , Program }
 What sets how fast the gain of a band moves. More...
 
enum class  LinkMode { Loudest , Dominant }
 What a stereo band's linked level reads (see setLinkMode()). More...
 
enum class  Structure { DirectForm , Ladder }
 How the band filter is realised (see setStructure()). More...
 

Public Member Functions

 DynamicEQ ()
 
void prepare (const AudioSpec &spec)
 Initializes the dynamic EQ, allocating ring buffers and oversamplers.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes audio in-place using self-sidechain.
 
void processBlock (AudioBufferView< T > audio, AudioBufferView< T > sidechain) noexcept
 Processes audio with an external sidechain.
 
void setRemovalListen (bool on) noexcept
 Removal listen: the output is what the bands take out (or add), the input delayed by the latency minus the output. A monitoring control, not in the state.
 
bool isRemovalListen () const noexcept
 
void setKeyListen (int band) noexcept
 Key listen: the output is what one band's detector hears.
 
int getKeyListen () const noexcept
 
void setBand (int band, const BandConfig &config) noexcept
 Thread-safe configuration update for a specific band.
 
void setNumBands (int n) noexcept
 
void setMixedBands (bool on) noexcept
 Chooses the engine of the bands: fixed filters mixed by the gain, or one filter designed again as the gain moves (the default).
 
bool isMixedBands () const noexcept
 Whether the bands are mixed from fixed filters (setMixedBands()).
 
void setLinkMode (LinkMode mode) noexcept
 Chooses how the bands placed on the stereo pair link it.
 
LinkMode getLinkMode () const noexcept
 
void setStructure (Structure structure) noexcept
 Chooses how the filter of each band is realised in the default engine.
 
Structure getStructure () const noexcept
 
void setLinearPhase (bool on) noexcept
 Linear phase: the bands change the level of the signal and nothing of its phase.
 
bool isLinearPhase () const noexcept
 Whether the bands run in linear phase (setLinearPhase()).
 
void setLinearPhaseKernelLength (int taps) noexcept
 Asks for the length of the linear-phase kernels, in taps.
 
int getLinearPhaseKernelLength () const noexcept
 The kernel length in use (after prepare()), or the one asked for.
 
void getBandMagnitude (int band, T dynamicGainDb, const T *frequencies, T *magnitudes, int numPoints) const noexcept
 The magnitude response of a band with its dynamic part at a given gain, as the engine in use plays it.
 
void setOversampling (int factor) noexcept
 Sets the internal oversampling factor.
 
void setAutomaticOversampling (bool on) noexcept
 Lets the host rate choose the factor (setup threads only: like setOversampling() it un-prepares the processor until the next prepare()).
 
bool isOversamplingAutomatic () const noexcept
 Whether the factor follows the host rate (setAutomaticOversampling()).
 
int getOversamplingFactor () const noexcept
 Active oversampling factor (1 = off), as the last prepare() or setter left it.
 
void setLookahead (T ms) noexcept
 Sets the lookahead (0..10 ms). Applied immediately (may click); non-finite values are ignored.
 
int getLatency () const noexcept
 Total latency in samples at the base rate.
 
T getBandGainDb (int band) const noexcept
 The gain the dynamic part of a band is applying, in dB from its rest (metering; any thread).
 
void reset () noexcept
 
std::vector< uint8_t > getState () const
 Serializes bands and modes (setup/UI threads; allocates).
 
bool setState (const uint8_t *data, size_t size)
 Restores bands from a blob (tolerant; rejects foreign ids).
 

Static Public Attributes

static constexpr T kAutomaticKnee = T(-1)
 BandConfig::knee value that asks for the automatic knee.
 

Detailed Description

template<FloatType T, int MaxBands = 8>
class dspark::DynamicEQ< T, MaxBands >

Dynamic parametric EQ with dual above/below threshold per band.

Template Parameters
TSample type (float or double).
MaxBandsMaximum number of bands (compile-time, default 8).

Definition at line 180 of file DynamicEQ.h.

Member Enumeration Documentation

◆ BandShape

template<FloatType T, int MaxBands = 8>
enum class dspark::DynamicEQ::BandShape
strong

Shape of the dynamic gain filter (and its detector region).

Enumerator
Bell 

Parametric bell; detector is a bandpass at freq/Q.

LowShelf 

Dynamic low shelf; detector hears below freq.

HighShelf 

Dynamic high shelf; detector hears above freq.

Definition at line 184 of file DynamicEQ.h.

◆ LinkMode

template<FloatType T, int MaxBands = 8>
enum class dspark::DynamicEQ::LinkMode
strong

What a stereo band's linked level reads (see setLinkMode()).

Enumerator
Loudest 

The louder channel's level (the default).

Dominant 

The level of the pair's dominant component in the band.

Definition at line 695 of file DynamicEQ.h.

◆ Scope

template<FloatType T, int MaxBands = 8>
enum class dspark::DynamicEQ::Scope
strong

Where in a stereo pair a band acts and listens.

Enumerator
Stereo 

Every channel, linked by the loudest. Default.

Left 

The first channel only.

Right 

The second channel only.

Mid 

The middle of the first two channels: what they share.

Side 

Their sides: what sets them apart.

Definition at line 192 of file DynamicEQ.h.

◆ Structure

template<FloatType T, int MaxBands = 8>
enum class dspark::DynamicEQ::Structure
strong

How the band filter is realised (see setStructure()).

Enumerator
DirectForm 

Direct form (the default).

Ladder 

Normalized ladder: passive while the gain moves the filter.

Definition at line 722 of file DynamicEQ.h.

◆ Timing

template<FloatType T, int MaxBands = 8>
enum class dspark::DynamicEQ::Timing
strong

What sets how fast the gain of a band moves.

Enumerator
Manual 

The attack and release fields, applied to the gain. Default.

Program 

Three followers of the level, timed from the band's frequency and width.

Definition at line 202 of file DynamicEQ.h.

Constructor & Destructor Documentation

◆ DynamicEQ()

template<FloatType T, int MaxBands = 8>
dspark::DynamicEQ< T, MaxBands >::DynamicEQ ( )
inline

Definition at line 248 of file DynamicEQ.h.

Member Function Documentation

◆ getBandGainDb()

template<FloatType T, int MaxBands = 8>
T dspark::DynamicEQ< T, MaxBands >::getBandGainDb ( int  band) const
inlinenoexcept

The gain the dynamic part of a band is applying, in dB from its rest (metering; any thread).

Definition at line 963 of file DynamicEQ.h.

◆ getBandMagnitude()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::getBandMagnitude ( int  band,
T  dynamicGainDb,
const T *  frequencies,
T *  magnitudes,
int  numPoints 
) const
inlinenoexcept

The magnitude response of a band with its dynamic part at a given gain, as the engine in use plays it.

For an interface: draw it at getBandGainDb() for the live curve, or at the range of a side for where the band can go. Reads the published band; setup or UI threads.

Parameters
bandBand index.
dynamicGainDbGain of the dynamic part, in dB from the rest.
frequenciesArray of frequencies in Hz.
magnitudesOutput array (same size, linear scale).
numPointsNumber of frequency points.

Definition at line 817 of file DynamicEQ.h.

◆ getKeyListen()

template<FloatType T, int MaxBands = 8>
int dspark::DynamicEQ< T, MaxBands >::getKeyListen ( ) const
inlinenoexcept
Returns
The band whose key is the output, or -1 for none.

Definition at line 441 of file DynamicEQ.h.

◆ getLatency()

template<FloatType T, int MaxBands = 8>
int dspark::DynamicEQ< T, MaxBands >::getLatency ( ) const
inlinenoexcept

Total latency in samples at the base rate.

Lookahead delay plus the oversampler's group delay. Neither was reported before, so hosts could not compensate (PDC). Safe to call from the main thread once prepared (the oversampler only changes inside prepare()).

Definition at line 953 of file DynamicEQ.h.

◆ getLinearPhaseKernelLength()

template<FloatType T, int MaxBands = 8>
int dspark::DynamicEQ< T, MaxBands >::getLinearPhaseKernelLength ( ) const
inlinenoexcept

The kernel length in use (after prepare()), or the one asked for.

Definition at line 801 of file DynamicEQ.h.

◆ getLinkMode()

template<FloatType T, int MaxBands = 8>
LinkMode dspark::DynamicEQ< T, MaxBands >::getLinkMode ( ) const
inlinenoexcept
Returns
How the stereo bands link the pair.

Definition at line 719 of file DynamicEQ.h.

◆ getOversamplingFactor()

template<FloatType T, int MaxBands = 8>
int dspark::DynamicEQ< T, MaxBands >::getOversamplingFactor ( ) const
inlinenoexcept

Active oversampling factor (1 = off), as the last prepare() or setter left it.

Definition at line 934 of file DynamicEQ.h.

◆ getState()

template<FloatType T, int MaxBands = 8>
std::vector< uint8_t > dspark::DynamicEQ< T, MaxBands >::getState ( ) const
inline

Serializes bands and modes (setup/UI threads; allocates).

Definition at line 1007 of file DynamicEQ.h.

◆ getStructure()

template<FloatType T, int MaxBands = 8>
Structure dspark::DynamicEQ< T, MaxBands >::getStructure ( ) const
inlinenoexcept
Returns
How the filter of each band is realised.

Definition at line 747 of file DynamicEQ.h.

◆ isLinearPhase()

template<FloatType T, int MaxBands = 8>
bool dspark::DynamicEQ< T, MaxBands >::isLinearPhase ( ) const
inlinenoexcept

Whether the bands run in linear phase (setLinearPhase()).

Definition at line 779 of file DynamicEQ.h.

◆ isMixedBands()

template<FloatType T, int MaxBands = 8>
bool dspark::DynamicEQ< T, MaxBands >::isMixedBands ( ) const
inlinenoexcept

Whether the bands are mixed from fixed filters (setMixedBands()).

Definition at line 692 of file DynamicEQ.h.

◆ isOversamplingAutomatic()

template<FloatType T, int MaxBands = 8>
bool dspark::DynamicEQ< T, MaxBands >::isOversamplingAutomatic ( ) const
inlinenoexcept

Whether the factor follows the host rate (setAutomaticOversampling()).

Definition at line 931 of file DynamicEQ.h.

◆ isRemovalListen()

template<FloatType T, int MaxBands = 8>
bool dspark::DynamicEQ< T, MaxBands >::isRemovalListen ( ) const
inlinenoexcept
Returns
Whether the output is what the bands change.

Definition at line 419 of file DynamicEQ.h.

◆ prepare()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::prepare ( const AudioSpec &  spec)
inline

Initializes the dynamic EQ, allocating ring buffers and oversamplers.

Parameters
specAudio specification containing sample rate and block size.

Definition at line 261 of file DynamicEQ.h.

◆ processBlock() [1/2]

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::processBlock ( AudioBufferView< T >  audio,
AudioBufferView< T >  sidechain 
)
inlinenoexcept

Processes audio with an external sidechain.

Parameters
audioIn/Out audio buffer.
sidechainReference signal used for level detection.

Definition at line 366 of file DynamicEQ.h.

◆ processBlock() [2/2]

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes audio in-place using self-sidechain.

Parameters
bufferIn/Out audio buffer.

Definition at line 356 of file DynamicEQ.h.

◆ reset()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::reset ( )
inlinenoexcept

Definition at line 969 of file DynamicEQ.h.

◆ setAutomaticOversampling()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setAutomaticOversampling ( bool  on)
inlinenoexcept

Lets the host rate choose the factor (setup threads only: like setOversampling() it un-prepares the processor until the next prepare()).

With it on, every prepare() takes the smallest factor that brings the gain stage to an internal rate of at least 88.2 kHz: 2x at 44.1 and 48 kHz and none from 88.2 kHz up. The nonlinearity then runs at about the same rate whatever the session rate, and a high-rate session stops paying for a factor it does not need. Off by default; an explicit setOversampling() turns it off.

Parameters
onTrue to choose the factor from the rate.

Definition at line 923 of file DynamicEQ.h.

◆ setBand()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setBand ( int  band,
const BandConfig &  config 
)
inlinenoexcept

Thread-safe configuration update for a specific band.

Fields are sanitized on the way in: non-finite values keep the band's previously published value (a NaN frequency/Q/time used to poison the detector or the gain ballistics permanently), wild shape enums are clamped (a scope or a timing that is not one keeps the band's own), the gain at rest is held within 24 dB, the knee within 40 dB (any negative knee is the automatic one), the range fields are floored at 0, and the edges of the listening zone are floored at 0 and put in order when both are there. Configuring a band at or beyond the current band count raises the count to band + 1 (it used to leave the band silent until setNumBands()).

Definition at line 628 of file DynamicEQ.h.

◆ setKeyListen()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setKeyListen ( int  band)
inlinenoexcept

Key listen: the output is what one band's detector hears.

The key (the sidechain, or the signal itself) through the detector filters of the band – its zone when it has one – on the channels of the band's scope: a band of the middle is heard in the centre and one of the sides with its two channels opposed. It is late by getLatency(), so it lines up with the processed signal it takes the place of, and it comes and goes through a 10 ms fade. The bands keep working underneath: when the listen ends the processing is where it would have been. With the removal listen on as well, the key is what is heard. A monitoring control, not in the state. Safe from any thread.

Parameters
bandThe band to listen to; negative, or past the last one, for none.

Definition at line 436 of file DynamicEQ.h.

◆ setLinearPhase()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setLinearPhase ( bool  on)
inlinenoexcept

Linear phase: the bands change the level of the signal and nothing of its phase.

Each band is then zero-phase filters (its rest, and the end of each side, as in the mixed engine), run by one partitioned convolution, and the gain sets how much of each is added to the signal, late by the latency of the mode: half the kernel plus one partition (2560 samples at 44.1 and 48 kHz with the default kernel; getLatency() reports it). The bands add up side by side, each one heard from the input, so two bands that overlap add their changes instead of multiplying them. The detector runs ahead of the audio by that latency, and the gain is held back to meet it (less the lookahead, which costs no latency here). The kernel resolves bands down to about its own length: with the default one a bell narrower than some 100 Hz comes out wider and shallower (setLinearPhaseKernelLength()). The mode runs at the host rate: oversampling is not used with it.

Note
Setup threads only: like setOversampling() this un-prepares the processor until the next prepare().
Parameters
onTrue for linear phase.

Definition at line 771 of file DynamicEQ.h.

◆ setLinearPhaseKernelLength()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setLinearPhaseKernelLength ( int  taps)
inlinenoexcept

Asks for the length of the linear-phase kernels, in taps.

A power of two from 1024 to 65536 (other values go up to the next one); 0, the default, is 4096 at 44.1 and 48 kHz and in proportion at higher rates. Longer kernels resolve lower and narrower bands and add latency (half the kernel plus an eighth). Setup threads only: it un-prepares the processor when the mode is on.

Parameters
tapsKernel length, or 0 for the automatic one.

Definition at line 792 of file DynamicEQ.h.

◆ setLinkMode()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setLinkMode ( LinkMode  mode)
inlinenoexcept

Chooses how the bands placed on the stereo pair link it.

Dominant reads, in each band, the level of the pair's dominant component: the two channels' band levels and their correlation over 20 ms make a covariance whose larger eigenvalue is read (see dominantPairLevel()). A source reads the same wherever an equal-power pan puts it, and uncorrelated channels read the louder 3 dB down. It applies to Scope::Stereo bands on two channels. Safe from any thread.

Parameters
modeLoudest (default) or Dominant.

Definition at line 713 of file DynamicEQ.h.

◆ setLookahead()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setLookahead ( T  ms)
inlinenoexcept

Sets the lookahead (0..10 ms). Applied immediately (may click); non-finite values are ignored.

Definition at line 938 of file DynamicEQ.h.

◆ setMixedBands()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setMixedBands ( bool  on)
inlinenoexcept

Chooses the engine of the bands: fixed filters mixed by the gain, or one filter designed again as the gain moves (the default).

A mixed band is the signal and one fixed filter per side (the end of the range), none of which ever changes while the gain moves; the gain sets how much of the filter is heard, sample by sample (see the file notes). Safe from any thread; the audio thread changes engine at the next block and every band starts clean there, which may click: choose it before playback.

Parameters
onTrue for the mixed engine.

Definition at line 689 of file DynamicEQ.h.

◆ setNumBands()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setNumBands ( int  n)
inlinenoexcept

Definition at line 670 of file DynamicEQ.h.

◆ setOversampling()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setOversampling ( int  factor)
inlinenoexcept

Sets the internal oversampling factor.

Transparency policy: the factor is host-visible, fully configurable and can be turned OFF.

  • Supported factors: {1, 2, 4}. DEFAULT is 1 = OFF (no internal resampling, zero added latency, no hidden cascaded resampler). 3 rounds up to 4 (the underlying Oversampling engine works in powers of two); values outside [1,4] are clamped.
  • CPU/latency cost per factor (relative to 1x=off): 2x roughly doubles the per-band detector+filter work and adds the half-band polyphase group delay (64 samples); 4x roughly quadruples it and adds 70 (the second stage runs a much shorter half-band). The exact added latency for the active factor is reported by getLatency() so the host can apply correct PDC. Prefer 1x and oversample the whole nonlinear section once (docs/cookbook.md) when a chain already oversamples.
Note
Setup threads only: this un-prepares the processor and requires a prepare() call before the new factor takes effect.

Definition at line 902 of file DynamicEQ.h.

◆ setRemovalListen()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setRemovalListen ( bool  on)
inlinenoexcept

Removal listen: the output is what the bands take out (or add), the input delayed by the latency minus the output. A monitoring control, not in the state.

Definition at line 417 of file DynamicEQ.h.

◆ setState()

template<FloatType T, int MaxBands = 8>
bool dspark::DynamicEQ< T, MaxBands >::setState ( const uint8_t *  data,
size_t  size 
)
inline

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

Definition at line 1074 of file DynamicEQ.h.

◆ setStructure()

template<FloatType T, int MaxBands = 8>
void dspark::DynamicEQ< T, MaxBands >::setStructure ( Structure  structure)
inlinenoexcept

Chooses how the filter of each band is realised in the default engine.

The default engine designs each band again every 16 samples as its gain moves. Ladder runs that filter as a normalized ladder (NormalizedLadder): the same response, and a memory that cannot gain energy at the jumps however fast the gain swings, for about twice the arithmetic of the filter. The mixed engine (setMixedBands()) and the linear phase keep their own filters. Safe from any thread; the switch restarts the bands' memory at the next block.

Parameters
structureDirectForm (default) or Ladder.

Definition at line 741 of file DynamicEQ.h.

Member Data Documentation

◆ kAutomaticKnee

template<FloatType T, int MaxBands = 8>
constexpr T dspark::DynamicEQ< T, MaxBands >::kAutomaticKnee = T(-1)
staticconstexpr

BandConfig::knee value that asks for the automatic knee.

Definition at line 209 of file DynamicEQ.h.


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