DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
NoiseGate.h File Reference

Noise gate with hysteresis, hold time, and duck mode. More...

#include "../Core/DspMath.h"
#include "../Core/AudioSpec.h"
#include "../Core/AudioBuffer.h"
#include "../Core/DenormalGuard.h"
#include "../Core/StateBlob.h"
#include <algorithm>
#include <array>
#include <atomic>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <numbers>
#include <utility>
#include <vector>
Include dependency graph for NoiseGate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::NoiseGate< T >
 High-performance noise gate with state machine, hysteresis, and zero-allocation processing. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Noise gate with hysteresis, hold time, and duck mode.

A professional noise gate that attenuates audio below a threshold. Uses a state machine (Open/Hold/Close) with hysteresis to prevent chattering. Includes an internal peak envelope detector for distortion-free low-frequency tracking. Thresholds are precomputed in the linear domain, so the per-sample path is branch-light and free of log/pow calls (the envelope recursion itself is serial and does not vectorize).

Features:

  • State machine: Open -> Hold -> Close (with hysteresis)
  • True envelope peak detection (prevents audio-rate chatter)
  • Open/close threshold hysteresis
  • Configurable hold time before closing
  • Range: -inf to 0 dB (allows partial attenuation)
  • Sidechain: internal or external with optional HPF
  • Duck mode (attenuate when above threshold, for ducking music under voice)
  • Stereo linked detection
  • Smooth attack/release transitions
  • Adaptive hold (holds at least one estimated signal period)

Threading: prepare() belongs to the setup thread; processBlock(), processSample() and reset() belong to the audio thread. All setters are lock-free atomic publications, safe from any thread; they are consumed at the start of the next block (or the next processSample() call). Non-finite setter arguments are ignored.

Dependencies: DspMath.h, AudioSpec.h, AudioBuffer.h, DenormalGuard.h, StateBlob.h.

gate.prepare(48000.0);
gate.setThreshold(-40.0f); // open at -40 dB
gate.setHysteresis(4.0f); // close at -44 dB
gate.setAttack(0.5f); // 0.5 ms attack
gate.setHold(50.0f); // 50 ms hold
gate.setRelease(100.0f); // 100 ms release
for (int i = 0; i < numSamples; ++i)
output[i] = gate.processSample(input[i]);
High-performance noise gate with state machine, hysteresis, and zero-allocation processing.
Definition NoiseGate.h:78
void prepare(double sampleRate) noexcept
Prepares the noise gate for processing.
Definition NoiseGate.h:105
T processSample(T input) noexcept
Processes a single mono sample.
Definition NoiseGate.h:351
void setAttack(T ms) noexcept
Sets attack time in milliseconds. Non-finite values are ignored.
Definition NoiseGate.h:264
void setRelease(T ms) noexcept
Sets release time in milliseconds. Non-finite values are ignored.
Definition NoiseGate.h:280
void setHold(T ms) noexcept
Sets hold time in milliseconds. Non-finite values are ignored.
Definition NoiseGate.h:272
void setHysteresis(T dB) noexcept
Sets the hysteresis amount (gap between open and close thresholds).
Definition NoiseGate.h:256
void setThreshold(T dB) noexcept
Sets the opening threshold.
Definition NoiseGate.h:245

Definition in file NoiseGate.h.