|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
High-performance noise gate with state machine, hysteresis, and zero-allocation processing. More...
#include <NoiseGate.h>

Public Types | |
| enum class | State { Closed , Open , Hold } |
| Gate state machine phases. More... | |
| enum class | GateMode { Amplitude , Frequency } |
| Operating mode for the gate processing. More... | |
Public Member Functions | |
| ~NoiseGate ()=default | |
| void | prepare (double sampleRate) noexcept |
| Prepares the noise gate for processing. | |
| void | prepare (const AudioSpec &spec) noexcept |
| Prepares from AudioSpec (unified API). | |
| void | processBlock (AudioBufferView< T > buffer) noexcept |
| Processes an AudioBufferView in-place. | |
| void | processBlock (AudioBufferView< T > audio, AudioBufferView< T > sidechain) noexcept |
| Processes audio with an external sidechain signal. | |
| void | setThreshold (T dB) noexcept |
| Sets the opening threshold. | |
| void | setHysteresis (T dB) noexcept |
| Sets the hysteresis amount (gap between open and close thresholds). | |
| void | setAttack (T ms) noexcept |
| Sets attack time in milliseconds. Non-finite values are ignored. | |
| void | setHold (T ms) noexcept |
| Sets hold time in milliseconds. Non-finite values are ignored. | |
| void | setRelease (T ms) noexcept |
| Sets release time in milliseconds. Non-finite values are ignored. | |
| void | setRange (T dB) noexcept |
| Sets maximum attenuation range. | |
| void | setDuckMode (bool enabled) noexcept |
| Toggles ducking mode (invert gate logic). | |
| void | setGateMode (GateMode mode) noexcept |
| Selects the processing mode (Amplitude or Frequency; wild enum values clamp). | |
| void | setAdaptiveHold (bool enabled) noexcept |
| Toggles adaptive hold based on zero-crossing rate. | |
| void | setSidechainHPF (bool enabled, double cutoffHz=80.0) noexcept |
| Configures sidechain High-Pass filter. | |
| T | processSample (T input) noexcept |
| Processes a single mono sample. | |
| T | processSampleWithSidechain (T input, T sidechain) noexcept |
| Processes a mono sample using an external sidechain. | |
| void | reset () noexcept |
| Resets DSP state (clears filters, sets state to Closed). | |
| 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 | syncParamsIfDirty () noexcept |
| void | syncParams () noexcept |
| T | computeEnvelopeFollower (T rawLevel) noexcept |
| Updates envelope state to prevent intra-cycle chattering. | |
| void | updateStateMachine (T envelopeLinear) noexcept |
| void | updateZeroCrossing (T sample) noexcept |
| T | getCurrentGain () noexcept |
| T | applyFrequencyGate (T input, int ch) noexcept |
| T | applyScHpf (T input, int ch) noexcept |
| Per-channel one-pole sidechain high-pass (unity gain at Nyquist). | |
| T | processSampleInternal (T input, T sidechain, int ch) noexcept |
Protected Attributes | |
| double | sampleRate_ = 48000.0 |
| std::atomic< T > | threshold_ { T(-40) } |
| 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< bool > | duckMode_ { false } |
| std::atomic< GateMode > | gateMode_ { GateMode::Amplitude } |
| std::atomic< bool > | adaptiveHold_ { false } |
| std::atomic< bool > | paramsDirty_ { true } |
| std::atomic< bool > | scHpfEnabled_ { false } |
| std::atomic< T > | scHpfFreq_ { T(80) } |
| T | cachedThresholdLinear_ = T(0.01) |
| T | cachedCloseThresholdLinear_ = T(0.0063) |
| T | cachedRangeLinear_ = T(0.0001) |
| bool | cachedDuck_ = false |
| GateMode | cachedGateMode_ = GateMode::Amplitude |
| bool | cachedAdaptiveHold_ = false |
| bool | cachedScHpfEnabled_ = false |
| T | cachedNyquist_ = T(24000) |
| T | cachedFsInvPi2_ = T(0) |
| T | scHpfCoeff_ = T(0.995) |
| T | scHpfA0_ = T(0.9975) |
| std::array< T, kMaxScChannels > | scHpfState_ {} |
| std::array< T, kMaxScChannels > | scHpfPrev_ {} |
| T | attackCoeff_ = T(0) |
| T | releaseCoeff_ = T(0) |
| int | holdSamples_ = 0 |
| T | envelopeState_ = T(0) |
| T | detectorReleaseCoeff_ = T(0) |
| State | state_ = State::Closed |
| T | gateGain_ = T(0) |
| int | holdCounter_ = 0 |
| T | freqSmoothCoeff_ = T(0) |
| std::array< T, kMaxChannels > | freqLpState_ {} |
| std::array< T, kMaxChannels > | freqHpState_ {} |
| std::array< T, kMaxChannels > | freqHpPrev_ {} |
| std::array< T, kMaxChannels > | freqLpFreq_ {} |
| std::array< T, kMaxChannels > | freqHpFreq_ {} |
| int | zeroCrossCount_ = 0 |
| int | zeroCrossSamples_ = 0 |
| bool | prevSign_ = false |
| int | estimatedPeriod_ = 0 |
Static Protected Attributes | |
| static constexpr int | kMaxChannels = 2 |
| static constexpr int | kMaxScChannels = 16 |
| static constexpr int | kZeroCrossWindow = 2048 |
High-performance noise gate with state machine, hysteresis, and zero-allocation processing.
| T | Sample type (float or double). |
Definition at line 77 of file NoiseGate.h.
|
strong |
Operating mode for the gate processing.
| Enumerator | |
|---|---|
| Amplitude | Standard amplitude gain reduction (default). |
| Frequency | Gatelope-style: narrows bandpass dynamically instead of direct gain reduction. |
Definition at line 91 of file NoiseGate.h.
|
strong |
Gate state machine phases.
| Enumerator | |
|---|---|
| Closed | Gate is fully closed (applying range attenuation). |
| Open | Gate is fully open (passing audio). |
| Hold | Gate is open but counting down hold time before closing. |
Definition at line 83 of file NoiseGate.h.
|
default |
|
inlineprotectednoexcept |
Definition at line 576 of file NoiseGate.h.
|
inlineprotectednoexcept |
Per-channel one-pole sidechain high-pass (unity gain at Nyquist).
Definition at line 600 of file NoiseGate.h.
|
inlineprotectednoexcept |
Updates envelope state to prevent intra-cycle chattering.
Definition at line 493 of file NoiseGate.h.
|
inlineprotectednoexcept |
Definition at line 564 of file NoiseGate.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 396 of file NoiseGate.h.
|
inlinenoexcept |
Prepares from AudioSpec (unified API).
| spec | AudioSpec containing format details. |
Definition at line 117 of file NoiseGate.h.
|
inlinenoexcept |
Prepares the noise gate for processing.
Release-safe: a non-positive or non-finite sample rate makes this call a no-op (the previous state and rate are kept).
| sampleRate | Operating sample rate in Hz (must be > 0). |
Definition at line 105 of file NoiseGate.h.
|
inlinenoexcept |
Processes audio with an external sidechain signal.
Detection (including the optional HPF, the adaptive-hold zero-crossing tracker and Frequency mode) behaves exactly like the internal-key path; only the level source changes to the sidechain buffer.
| audio | Audio buffer to gate (modified in-place). |
| sidechain | External sidechain signal (read-only). |
Definition at line 185 of file NoiseGate.h.
|
inlinenoexcept |
Processes an AudioBufferView in-place.
Detection is linked across ALL channels (peak), so no channel is left ungated. In Frequency mode, channels beyond kMaxChannels fall back to amplitude gating (per-channel filter state is kept for the first two).
| buffer | Audio buffer (mono or multi-channel). |
Definition at line 128 of file NoiseGate.h.
|
inlinenoexcept |
Processes a single mono sample.
Bit-identical to processBlock() for mono streams.
| input | Source sample. |
Definition at line 351 of file NoiseGate.h.
|
inlineprotectednoexcept |
Definition at line 608 of file NoiseGate.h.
|
inlinenoexcept |
Processes a mono sample using an external sidechain.
| input | Source sample. |
| sidechain | Key/Sidechain sample. |
Definition at line 363 of file NoiseGate.h.
|
inlinenoexcept |
Resets DSP state (clears filters, sets state to Closed).
Definition at line 372 of file NoiseGate.h.
|
inlinenoexcept |
Toggles adaptive hold based on zero-crossing rate.
Definition at line 314 of file NoiseGate.h.
|
inlinenoexcept |
Sets attack time in milliseconds. Non-finite values are ignored.
Definition at line 264 of file NoiseGate.h.
|
inlinenoexcept |
Toggles ducking mode (invert gate logic).
Definition at line 299 of file NoiseGate.h.
|
inlinenoexcept |
Selects the processing mode (Amplitude or Frequency; wild enum values clamp).
Definition at line 306 of file NoiseGate.h.
|
inlinenoexcept |
Sets hold time in milliseconds. Non-finite values are ignored.
Definition at line 272 of file NoiseGate.h.
|
inlinenoexcept |
Sets the hysteresis amount (gap between open and close thresholds).
| dB | Hysteresis in decibels (floored to 0). Non-finite values are ignored. |
Definition at line 256 of file NoiseGate.h.
|
inlinenoexcept |
Sets maximum attenuation range.
| dB | Range in decibels (capped at 0). Non-finite values are ignored. |
Definition at line 291 of file NoiseGate.h.
|
inlinenoexcept |
Sets release time in milliseconds. Non-finite values are ignored.
Definition at line 280 of file NoiseGate.h.
|
inlinenoexcept |
Configures sidechain High-Pass filter.
An invalid cutoff (non-finite or non-positive) keeps the previous frequency and only applies the toggle: a negative cutoff would make the one-pole coefficient exceed 1 (an unstable, runaway filter).
| enabled | Filter active state. |
| cutoffHz | Filter cutoff in Hz (clamped to [1, 0.45 * fs]). |
Definition at line 330 of file NoiseGate.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition at line 414 of file NoiseGate.h.
|
inlinenoexcept |
Sets the opening threshold.
| dB | Threshold in decibels. Non-finite values are ignored. |
Definition at line 245 of file NoiseGate.h.
|
inlineprotectednoexcept |
Definition at line 444 of file NoiseGate.h.
|
inlineprotectednoexcept |
Definition at line 435 of file NoiseGate.h.
|
inlineprotectednoexcept |
Definition at line 503 of file NoiseGate.h.
|
inlineprotectednoexcept |
Definition at line 544 of file NoiseGate.h.
|
protected |
Definition at line 640 of file NoiseGate.h.
|
protected |
Definition at line 663 of file NoiseGate.h.
|
protected |
Definition at line 634 of file NoiseGate.h.
|
protected |
Definition at line 652 of file NoiseGate.h.
|
protected |
Definition at line 648 of file NoiseGate.h.
|
protected |
Definition at line 650 of file NoiseGate.h.
|
protected |
Definition at line 655 of file NoiseGate.h.
|
protected |
Definition at line 651 of file NoiseGate.h.
|
protected |
Definition at line 654 of file NoiseGate.h.
|
protected |
Definition at line 649 of file NoiseGate.h.
|
protected |
Definition at line 653 of file NoiseGate.h.
|
protected |
Definition at line 647 of file NoiseGate.h.
|
protected |
Definition at line 669 of file NoiseGate.h.
|
protected |
Definition at line 638 of file NoiseGate.h.
|
protected |
Definition at line 668 of file NoiseGate.h.
|
protected |
Definition at line 686 of file NoiseGate.h.
|
protected |
Definition at line 680 of file NoiseGate.h.
|
protected |
Definition at line 678 of file NoiseGate.h.
|
protected |
Definition at line 677 of file NoiseGate.h.
|
protected |
Definition at line 679 of file NoiseGate.h.
|
protected |
Definition at line 676 of file NoiseGate.h.
|
protected |
Definition at line 675 of file NoiseGate.h.
|
protected |
Definition at line 672 of file NoiseGate.h.
|
protected |
Definition at line 639 of file NoiseGate.h.
|
protected |
Definition at line 673 of file NoiseGate.h.
|
protected |
Definition at line 635 of file NoiseGate.h.
|
protected |
Definition at line 665 of file NoiseGate.h.
|
protected |
Definition at line 633 of file NoiseGate.h.
|
staticconstexprprotected |
Definition at line 433 of file NoiseGate.h.
|
staticconstexprprotected |
Definition at line 657 of file NoiseGate.h.
|
staticconstexprprotected |
Definition at line 682 of file NoiseGate.h.
|
protected |
Definition at line 641 of file NoiseGate.h.
|
protected |
Definition at line 685 of file NoiseGate.h.
|
protected |
Definition at line 637 of file NoiseGate.h.
|
protected |
Definition at line 664 of file NoiseGate.h.
|
protected |
Definition at line 636 of file NoiseGate.h.
|
protected |
Definition at line 630 of file NoiseGate.h.
|
protected |
Definition at line 659 of file NoiseGate.h.
|
protected |
Definition at line 658 of file NoiseGate.h.
|
protected |
Definition at line 643 of file NoiseGate.h.
|
protected |
Definition at line 644 of file NoiseGate.h.
|
protected |
Definition at line 661 of file NoiseGate.h.
|
protected |
Definition at line 660 of file NoiseGate.h.
|
protected |
Definition at line 671 of file NoiseGate.h.
|
protected |
Definition at line 632 of file NoiseGate.h.
|
protected |
Definition at line 683 of file NoiseGate.h.
|
protected |
Definition at line 684 of file NoiseGate.h.