|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Downward expander with ratio control, hysteresis, and sidechain. More...
#include <Expander.h>

Public Types | |
| enum class | State { Closed , Open , Hold } |
Public Member Functions | |
| ~Expander ()=default | |
| void | prepare (double sampleRate) noexcept |
| Initializes the expander with a specific sample rate. | |
| void | prepare (const AudioSpec &spec) noexcept |
| Initializes the expander using an AudioSpec struct. | |
| void | processBlock (AudioBufferView< T > buffer) noexcept |
| Processes an audio block in place (internal detector key). | |
| void | processBlock (AudioBufferView< T > buffer, AudioBufferView< T > sidechain) noexcept |
| Processes an audio block in place, keyed by an external sidechain. | |
| void | setThreshold (T dB) noexcept |
| Sets the threshold in decibels. | |
| void | setRatio (T ratio) noexcept |
| Sets the expansion ratio (e.g., 4.0 for 4:1). | |
| void | setHysteresis (T dB) noexcept |
| Sets the hysteresis gap in decibels to prevent chattering. | |
| void | setRange (T dB) noexcept |
| Sets the maximum gain reduction limit in decibels (<= 0). | |
| void | setAttack (T ms) noexcept |
| Sets the attack time in milliseconds. | |
| void | setHold (T ms) noexcept |
| Sets the hold time in milliseconds before release begins. | |
| void | setRelease (T ms) noexcept |
| Sets the release time in milliseconds. | |
| void | setSidechainHPF (bool enabled, double cutoffHz=80.0) noexcept |
| Enables and configures the sidechain high-pass filter. | |
| State | getGateState () const noexcept |
| T | getCurrentGainDb () const noexcept |
| void | reset () noexcept |
| Resets all internal DSP states to prevent clicks on playback start. | |
| 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). | |
Protected Member Functions | |
| void | cacheParams () noexcept |
| template<bool UseHPF, bool UseSc> | |
| void | processBlockInternal (AudioBufferView< T > buffer, const AudioBufferView< T > *sidechain) noexcept |
| Internal processing loop templated on HPF/sidechain to avoid branching. | |
| void | updateStateMachine (T levelDb) noexcept |
| T | computeGain (T levelDb) noexcept |
| void | updateCoefficients () noexcept |
Protected Attributes | |
| double | sampleRate_ = 48000.0 |
| bool | prepared_ = false |
| std::atomic< T > | threshold_ { T(-40) } |
| std::atomic< T > | ratio_ { T(4) } |
| std::atomic< T > | hysteresis_ { T(4) } |
| std::atomic< T > | attackMs_ { T(0.5) } |
| std::atomic< T > | holdMs_ { T(50) } |
| std::atomic< T > | releaseMs_ { T(100) } |
| std::atomic< T > | rangeDb_ { T(-80) } |
| std::atomic< T > | rangeLinear_ { T(0.0001) } |
| std::atomic< bool > | scHpfEnabled_ { false } |
| std::atomic< T > | scHpfFreqHz_ { T(80) } |
| std::atomic< T > | scHpfCoeff_ { T(0.995) } |
| std::atomic< T > | scHpfA0_ { T(0.9975) } |
| std::array< T, MAX_CHANNELS > | scHpfState_ {} |
| std::array< T, MAX_CHANNELS > | scHpfPrev_ {} |
| std::atomic< T > | attackCoeff_ { T(0) } |
| std::atomic< T > | releaseCoeff_ { T(0) } |
| std::atomic< T > | detAttCoeff_ { T(0.01) } |
| std::atomic< T > | detRelCoeff_ { T(0.001) } |
| std::atomic< int > | holdSamples_ { 0 } |
| T | cachedThreshold_ = T(-40) |
| T | cachedRatio_ = T(4) |
| T | cachedHysteresis_ = T(4) |
| T | cachedRangeLinear_ = T(0.0001) |
| T | cachedAttackCoeff_ = T(0) |
| T | cachedReleaseCoeff_ = T(0) |
| T | cachedDetAttCoeff_ = T(0.01) |
| T | cachedDetRelCoeff_ = T(0.001) |
| T | cachedScHpfCoeff_ = T(0.995) |
| T | cachedScHpfA0_ = T(0.9975) |
| int | cachedHoldSamples_ = 0 |
| bool | cachedScHpfEnabled_ = false |
| State | state_ = State::Closed |
| T | gateGain_ = T(0) |
| T | envelope_ = T(0) |
| int | holdCounter_ = 0 |
Static Protected Attributes | |
| static constexpr int | MAX_CHANNELS = 16 |
Downward expander with ratio control, hysteresis, and sidechain.
| T | Sample type (float or double). |
Definition at line 59 of file Expander.h.
|
strong |
| Enumerator | |
|---|---|
| Closed | |
| Open | |
| Hold | |
Definition at line 64 of file Expander.h.
|
default |
|
inlineprotectednoexcept |
Definition at line 292 of file Expander.h.
|
inlineprotectednoexcept |
Definition at line 395 of file Expander.h.
|
inlinenoexcept |
Definition at line 241 of file Expander.h.
|
inlinenoexcept |
Definition at line 237 of file Expander.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 257 of file Expander.h.
|
inlinenoexcept |
Initializes the expander using an AudioSpec struct.
| spec | Framework audio specification object (invalid specs are ignored). |
Definition at line 91 of file Expander.h.
|
inlinenoexcept |
Initializes the expander with a specific sample rate.
| sampleRate | The sample rate in Hz. Non-finite or non-positive rates are ignored (previous state is kept). |
Definition at line 73 of file Expander.h.
|
inlinenoexcept |
Processes an audio block in place (internal detector key).
| buffer | View of the audio buffer to process. |
Definition at line 101 of file Expander.h.
|
inlinenoexcept |
Processes an audio block in place, keyed by an external sidechain.
The detector (and its optional HPF) runs on the sidechain channels; the resulting gain is applied to the audio buffer. If the sidechain is empty or shorter than the audio block, the internal key is used instead.
| buffer | Audio to process in place. |
| sidechain | Detector key signal (not modified). |
Definition at line 123 of file Expander.h.
|
inlineprotectednoexcept |
Internal processing loop templated on HPF/sidechain to avoid branching.
| UseHPF | Compile-time flag to include HPF processing. |
| UseSc | Compile-time flag: detector keyed by the external sidechain. |
| buffer | View of the audio buffer (gain target). |
| sidechain | Detector key when UseSc (guaranteed >= buffer length). |
Definition at line 316 of file Expander.h.
|
inlinenoexcept |
Resets all internal DSP states to prevent clicks on playback start.
Definition at line 244 of file Expander.h.
|
inlinenoexcept |
Sets the attack time in milliseconds.
Definition at line 181 of file Expander.h.
|
inlinenoexcept |
Sets the hold time in milliseconds before release begins.
Definition at line 189 of file Expander.h.
|
inlinenoexcept |
Sets the hysteresis gap in decibels to prevent chattering.
Definition at line 165 of file Expander.h.
|
inlinenoexcept |
Sets the maximum gain reduction limit in decibels (<= 0).
Definition at line 172 of file Expander.h.
|
inlinenoexcept |
Sets the expansion ratio (e.g., 4.0 for 4:1).
Definition at line 158 of file Expander.h.
|
inlinenoexcept |
Sets the release time in milliseconds.
Definition at line 205 of file Expander.h.
|
inlinenoexcept |
Enables and configures the sidechain high-pass filter.
Invalid cutoffs (non-finite or <= 0) keep the previous frequency and only apply the toggle; the design clamp is [1, 0.45 * sampleRate]. A negative cutoff used to flip the one-pole into an unstable growth filter, blowing up the detector and pinning the expander open.
| enabled | True to engage the HPF. |
| cutoffHz | Cutoff frequency in Hz. |
Definition at line 223 of file Expander.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition at line 275 of file Expander.h.
|
inlinenoexcept |
Sets the threshold in decibels.
Definition at line 151 of file Expander.h.
|
inlineprotectednoexcept |
Definition at line 427 of file Expander.h.
|
inlineprotectednoexcept |
Definition at line 369 of file Expander.h.
|
protected |
Definition at line 474 of file Expander.h.
|
protected |
Definition at line 458 of file Expander.h.
|
protected |
Definition at line 485 of file Expander.h.
|
protected |
Definition at line 487 of file Expander.h.
|
protected |
Definition at line 488 of file Expander.h.
|
protected |
Definition at line 491 of file Expander.h.
|
protected |
Definition at line 483 of file Expander.h.
|
protected |
Definition at line 484 of file Expander.h.
|
protected |
Definition at line 482 of file Expander.h.
|
protected |
Definition at line 486 of file Expander.h.
|
protected |
Definition at line 490 of file Expander.h.
|
protected |
Definition at line 489 of file Expander.h.
|
protected |
Definition at line 492 of file Expander.h.
|
protected |
Definition at line 481 of file Expander.h.
|
protected |
Definition at line 476 of file Expander.h.
|
protected |
Definition at line 477 of file Expander.h.
|
protected |
Definition at line 496 of file Expander.h.
|
protected |
Definition at line 495 of file Expander.h.
|
protected |
Definition at line 497 of file Expander.h.
|
protected |
Definition at line 459 of file Expander.h.
|
protected |
Definition at line 478 of file Expander.h.
|
protected |
Definition at line 457 of file Expander.h.
|
staticconstexprprotected |
Definition at line 470 of file Expander.h.
|
protected |
Definition at line 453 of file Expander.h.
|
protected |
Definition at line 461 of file Expander.h.
|
protected |
Definition at line 462 of file Expander.h.
|
protected |
Definition at line 456 of file Expander.h.
|
protected |
Definition at line 475 of file Expander.h.
|
protected |
Definition at line 460 of file Expander.h.
|
protected |
Definition at line 452 of file Expander.h.
|
protected |
Definition at line 467 of file Expander.h.
|
protected |
Definition at line 466 of file Expander.h.
|
protected |
Definition at line 464 of file Expander.h.
|
protected |
Definition at line 465 of file Expander.h.
|
protected |
Definition at line 472 of file Expander.h.
|
protected |
Definition at line 471 of file Expander.h.
|
protected |
Definition at line 494 of file Expander.h.
|
protected |
Definition at line 455 of file Expander.h.