|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
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. | |
Dynamic parametric EQ with dual above/below threshold per band.
| T | Sample type (float or double). |
| MaxBands | Maximum number of bands (compile-time, default 8). |
Definition at line 180 of file DynamicEQ.h.
|
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.
|
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.
|
strong |
Where in a stereo pair a band acts and listens.
Definition at line 192 of file DynamicEQ.h.
|
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.
|
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.
|
inline |
Definition at line 248 of file DynamicEQ.h.
|
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.
|
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.
| band | Band index. |
| dynamicGainDb | Gain of the dynamic part, in dB from the rest. |
| frequencies | Array of frequencies in Hz. |
| magnitudes | Output array (same size, linear scale). |
| numPoints | Number of frequency points. |
Definition at line 817 of file DynamicEQ.h.
|
inlinenoexcept |
Definition at line 441 of file DynamicEQ.h.
|
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.
|
inlinenoexcept |
The kernel length in use (after prepare()), or the one asked for.
Definition at line 801 of file DynamicEQ.h.
|
inlinenoexcept |
Definition at line 719 of file DynamicEQ.h.
|
inlinenoexcept |
Active oversampling factor (1 = off), as the last prepare() or setter left it.
Definition at line 934 of file DynamicEQ.h.
|
inline |
Serializes bands and modes (setup/UI threads; allocates).
Definition at line 1007 of file DynamicEQ.h.
|
inlinenoexcept |
Definition at line 747 of file DynamicEQ.h.
|
inlinenoexcept |
Whether the bands run in linear phase (setLinearPhase()).
Definition at line 779 of file DynamicEQ.h.
|
inlinenoexcept |
Whether the bands are mixed from fixed filters (setMixedBands()).
Definition at line 692 of file DynamicEQ.h.
|
inlinenoexcept |
Whether the factor follows the host rate (setAutomaticOversampling()).
Definition at line 931 of file DynamicEQ.h.
|
inlinenoexcept |
Definition at line 419 of file DynamicEQ.h.
|
inline |
Initializes the dynamic EQ, allocating ring buffers and oversamplers.
| spec | Audio specification containing sample rate and block size. |
Definition at line 261 of file DynamicEQ.h.
|
inlinenoexcept |
Processes audio with an external sidechain.
| audio | In/Out audio buffer. |
| sidechain | Reference signal used for level detection. |
Definition at line 366 of file DynamicEQ.h.
|
inlinenoexcept |
Processes audio in-place using self-sidechain.
| buffer | In/Out audio buffer. |
Definition at line 356 of file DynamicEQ.h.
|
inlinenoexcept |
Definition at line 969 of file DynamicEQ.h.
|
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.
| on | True to choose the factor from the rate. |
Definition at line 923 of file DynamicEQ.h.
|
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.
|
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.
| band | The band to listen to; negative, or past the last one, for none. |
Definition at line 436 of file DynamicEQ.h.
|
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.
| on | True for linear phase. |
Definition at line 771 of file DynamicEQ.h.
|
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.
| taps | Kernel length, or 0 for the automatic one. |
Definition at line 792 of file DynamicEQ.h.
|
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.
| mode | Loudest (default) or Dominant. |
Definition at line 713 of file DynamicEQ.h.
|
inlinenoexcept |
Sets the lookahead (0..10 ms). Applied immediately (may click); non-finite values are ignored.
Definition at line 938 of file DynamicEQ.h.
|
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.
| on | True for the mixed engine. |
Definition at line 689 of file DynamicEQ.h.
|
inlinenoexcept |
Definition at line 670 of file DynamicEQ.h.
|
inlinenoexcept |
Sets the internal oversampling factor.
Transparency policy: the factor is host-visible, fully configurable and can be turned OFF.
Definition at line 902 of file DynamicEQ.h.
|
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.
|
inline |
Restores bands from a blob (tolerant; rejects foreign ids).
Definition at line 1074 of file DynamicEQ.h.
|
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.
| structure | DirectForm (default) or Ladder. |
Definition at line 741 of file DynamicEQ.h.
|
staticconstexpr |
BandConfig::knee value that asks for the automatic knee.
Definition at line 209 of file DynamicEQ.h.