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

High-performance noise gate with state machine, hysteresis, and zero-allocation processing. More...

#include <NoiseGate.h>

Collaboration diagram for dspark::NoiseGate< T >:

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...
 
using KeyEq = KeyEqualizer< T, 16 >
 The equalizer of the key (see setSidechainBand()).
 
using KeyBand = typename KeyEq::Band
 The settings of one band of the key equalizer.
 
using KeyShape = typename KeyEq::Shape
 What a band of the key equalizer does.
 
using KeyPlacement = typename KeyEq::Placement
 The part of a two-channel key a band of the key equalizer acts on.
 

Public Member Functions

 ~NoiseGate ()=default
 
void prepare (double sampleRate, int numChannels=2) 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 setAutoThreshold (bool on) noexcept
 Counts the threshold from the key's own recent level.
 
bool isAutoThreshold () const noexcept
 Whether the threshold counts from the key's recent level (see setAutoThreshold()).
 
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 setLookahead (T ms) noexcept
 Sets the lookahead: the audio is delayed so the gate opens (and closes) ahead of it. 0 (default) is latency-free.
 
T getLookahead () const noexcept
 Returns the lookahead in milliseconds.
 
int getLatency () const noexcept
 Latency in samples (the lookahead), correct right after setLookahead().
 
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.
 
void setSidechainBand (int band, const KeyBand &settings) noexcept
 Sets a band of the equalizer of the key.
 
KeyBand getSidechainBand (int band) const noexcept
 The settings of a band of the key equalizer.
 
KeyEq::Response getSidechainResponse () const noexcept
 The curve of the key equalizer, for a display.
 
void setSidechainListen (bool on) noexcept
 Plays the key instead of the gated audio.
 
bool isSidechainListen () const noexcept
 Whether the key is being played instead of the audio.
 
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
 
int lookaheadSamplesFor (T ms) const noexcept
 
T delayed (T x, int ch) 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).
 
template<typename Sample >
T placedKeyFrame (Sample sample, T &det0) noexcept
 One frame of a two-channel key whose equalizer has bands on the middle or the sides: both channels made finite and high-passed, then through the equalizer together (into heard_).
 
T processSampleInternal (T input, T sidechain, int ch) noexcept
 

Static Protected Member Functions

static T detectorSafe (T x) noexcept
 Non-finite detector samples read as silence (they would latch in the envelope and filter state).
 

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) }
 
std::atomic< T > lookaheadMs_ { T(0) }
 
int lookaheadSamples_ = 0
 Audio-side value (consumed in syncParams()).
 
int maxLookaheadSamples_ = 0
 Allocated delay (0 before prepare()).
 
int lookaheadChannels_ = 0
 Channels with a prepared delay line.
 
std::array< RingBuffer< T >, kMaxLookaheadChannels > lookahead_ {}
 
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_ {}
 
KeyEq keyEq_
 Equalizer of the key, after the high-pass.
 
KeyMonitor< T, 16 > keyMonitor_
 The listened key: late by the lookahead, under full scale.
 
std::atomic< bool > scListen_ { false }
 The key goes out instead of the audio.
 
bool keyOn_ = false
 The equalizer has bands in the path (audio thread).
 
bool listen_ = false
 scListen_ as the audio thread took it.
 
std::array< T, kMaxScChannels > heard_ {}
 The key of each channel in this frame.
 
T attackCoeff_ = T(0)
 
T releaseCoeff_ = T(0)
 
int holdSamples_ = 0
 
std::atomic< bool > autoThreshold_ { false }
 The thresholds count from the key's recent level.
 
bool cachedAutoThreshold_ = false
 
double autoRef_ = kAutoRefFloor
 The reference (linear).
 
double autoFall_ = 1.0
 Its fall per sample (a factor).
 
double autoFallQuiet_ = 1.0
 The same while the key is quiet.
 
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 double kMaxLookaheadMs = 10.0
 
static constexpr int kMaxLookaheadChannels = 16
 
static constexpr int kMaxScChannels = 16
 
static constexpr double kAutoRefFallDb = 1.0
 dB per second its reference falls.
 
static constexpr double kAutoRefQuiet = 0.25
 Share of that fall while the key is under the closing threshold.
 
static constexpr double kAutoRefFloor = 1e-5
 The reference never goes under -100 dBFS.
 
static constexpr int kZeroCrossWindow = 2048
 

Detailed Description

template<FloatType T>
class dspark::NoiseGate< T >

High-performance noise gate with state machine, hysteresis, and zero-allocation processing.

Template Parameters
TSample type (float or double).

Definition at line 84 of file NoiseGate.h.

Member Typedef Documentation

◆ KeyBand

template<FloatType T>
using dspark::NoiseGate< T >::KeyBand = typename KeyEq::Band

The settings of one band of the key equalizer.

Definition at line 448 of file NoiseGate.h.

◆ KeyEq

template<FloatType T>
using dspark::NoiseGate< T >::KeyEq = KeyEqualizer<T, 16>

The equalizer of the key (see setSidechainBand()).

Definition at line 446 of file NoiseGate.h.

◆ KeyPlacement

template<FloatType T>
using dspark::NoiseGate< T >::KeyPlacement = typename KeyEq::Placement

The part of a two-channel key a band of the key equalizer acts on.

Definition at line 452 of file NoiseGate.h.

◆ KeyShape

template<FloatType T>
using dspark::NoiseGate< T >::KeyShape = typename KeyEq::Shape

What a band of the key equalizer does.

Definition at line 450 of file NoiseGate.h.

Member Enumeration Documentation

◆ GateMode

template<FloatType T>
enum class dspark::NoiseGate::GateMode
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 98 of file NoiseGate.h.

◆ State

template<FloatType T>
enum class dspark::NoiseGate::State
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 90 of file NoiseGate.h.

Constructor & Destructor Documentation

◆ ~NoiseGate()

template<FloatType T>
dspark::NoiseGate< T >::~NoiseGate ( )
default

Member Function Documentation

◆ applyFrequencyGate()

template<FloatType T>
T dspark::NoiseGate< T >::applyFrequencyGate ( T  input,
int  ch 
)
inlineprotectednoexcept

Definition at line 784 of file NoiseGate.h.

◆ applyScHpf()

template<FloatType T>
T dspark::NoiseGate< T >::applyScHpf ( T  input,
int  ch 
)
inlineprotectednoexcept

Per-channel one-pole sidechain high-pass (unity gain at Nyquist).

Definition at line 811 of file NoiseGate.h.

◆ computeEnvelopeFollower()

template<FloatType T>
T dspark::NoiseGate< T >::computeEnvelopeFollower ( T  rawLevel)
inlineprotectednoexcept

Updates envelope state to prevent intra-cycle chattering.

Definition at line 688 of file NoiseGate.h.

◆ delayed()

template<FloatType T>
T dspark::NoiseGate< T >::delayed ( T  x,
int  ch 
)
inlineprotectednoexcept

The lookahead-delayed audio sample of a channel (pass-through when off or beyond the prepared channels).

Definition at line 677 of file NoiseGate.h.

◆ detectorSafe()

template<FloatType T>
static T dspark::NoiseGate< T >::detectorSafe ( T  x)
inlinestaticprotectednoexcept

Non-finite detector samples read as silence (they would latch in the envelope and filter state).

Definition at line 821 of file NoiseGate.h.

◆ getCurrentGain()

template<FloatType T>
T dspark::NoiseGate< T >::getCurrentGain ( )
inlineprotectednoexcept

Definition at line 772 of file NoiseGate.h.

◆ getLatency()

template<FloatType T>
int dspark::NoiseGate< T >::getLatency ( ) const
inlinenoexcept

Latency in samples (the lookahead), correct right after setLookahead().

Definition at line 415 of file NoiseGate.h.

◆ getLookahead()

template<FloatType T>
T dspark::NoiseGate< T >::getLookahead ( ) const
inlinenoexcept

Returns the lookahead in milliseconds.

Definition at line 412 of file NoiseGate.h.

◆ getSidechainBand()

template<FloatType T>
KeyBand dspark::NoiseGate< T >::getSidechainBand ( int  band) const
inlinenoexcept

The settings of a band of the key equalizer.

Definition at line 477 of file NoiseGate.h.

◆ getSidechainResponse()

template<FloatType T>
KeyEq::Response dspark::NoiseGate< T >::getSidechainResponse ( ) const
inlinenoexcept

The curve of the key equalizer, for a display.

Definition at line 480 of file NoiseGate.h.

◆ getState()

template<FloatType T>
std::vector< uint8_t > dspark::NoiseGate< T >::getState ( ) const
inline

Serializes the parameter state (setup/UI threads; allocates).

Definition at line 558 of file NoiseGate.h.

◆ isAutoThreshold()

template<FloatType T>
bool dspark::NoiseGate< T >::isAutoThreshold ( ) const
inlinenoexcept

Whether the threshold counts from the key's recent level (see setAutoThreshold()).

Definition at line 330 of file NoiseGate.h.

◆ isSidechainListen()

template<FloatType T>
bool dspark::NoiseGate< T >::isSidechainListen ( ) const
inlinenoexcept

Whether the key is being played instead of the audio.

Definition at line 494 of file NoiseGate.h.

◆ lookaheadSamplesFor()

template<FloatType T>
int dspark::NoiseGate< T >::lookaheadSamplesFor ( T  ms) const
inlineprotectednoexcept

Lookahead in samples for a ms value (shared by syncParams() and getLatency()).

Definition at line 669 of file NoiseGate.h.

◆ placedKeyFrame()

template<FloatType T>
template<typename Sample >
T dspark::NoiseGate< T >::placedKeyFrame ( Sample  sample,
T &  det0 
)
inlineprotectednoexcept

One frame of a two-channel key whose equalizer has bands on the middle or the sides: both channels made finite and high-passed, then through the equalizer together (into heard_).

Parameters
sampleThe key of a channel in this frame.
det0Set to channel 0's key, for the zero-crossing tracker.
Returns
The larger magnitude of the two.

Definition at line 832 of file NoiseGate.h.

◆ prepare() [1/2]

template<FloatType T>
void dspark::NoiseGate< T >::prepare ( const AudioSpec &  spec)
inlinenoexcept

Prepares from AudioSpec (unified API).

Parameters
specAudioSpec containing format details.

Definition at line 133 of file NoiseGate.h.

◆ prepare() [2/2]

template<FloatType T>
void dspark::NoiseGate< T >::prepare ( double  sampleRate,
int  numChannels = 2 
)
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; +inf used to pass). Allocates the lookahead delay lines (setup thread only).

Parameters
sampleRateOperating sample rate in Hz (must be > 0).
numChannelsChannels that receive the lookahead delay (clamped to [1, 16]); further channels are gated undelayed.

Definition at line 115 of file NoiseGate.h.

◆ processBlock() [1/2]

template<FloatType T>
void dspark::NoiseGate< T >::processBlock ( AudioBufferView< T >  audio,
AudioBufferView< T >  sidechain 
)
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.

Parameters
audioAudio buffer to gate (modified in-place).
sidechainExternal sidechain signal (read-only).

Definition at line 217 of file NoiseGate.h.

◆ processBlock() [2/2]

template<FloatType T>
void dspark::NoiseGate< T >::processBlock ( AudioBufferView< T >  buffer)
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).

Parameters
bufferAudio buffer (mono or multi-channel).

Definition at line 144 of file NoiseGate.h.

◆ processSample()

template<FloatType T>
T dspark::NoiseGate< T >::processSample ( T  input)
inlinenoexcept

Processes a single mono sample.

Bit-identical to processBlock() for mono streams.

Note
No DenormalGuard here (per-sample hot path); per-sample callers are expected to guard their own processing loop.
Parameters
inputSource sample.
Returns
Gated output sample.

Definition at line 509 of file NoiseGate.h.

◆ processSampleInternal()

template<FloatType T>
T dspark::NoiseGate< T >::processSampleInternal ( T  input,
T  sidechain,
int  ch 
)
inlineprotectednoexcept

Definition at line 845 of file NoiseGate.h.

◆ processSampleWithSidechain()

template<FloatType T>
T dspark::NoiseGate< T >::processSampleWithSidechain ( T  input,
T  sidechain 
)
inlinenoexcept

Processes a mono sample using an external sidechain.

Parameters
inputSource sample.
sidechainKey/Sidechain sample.
Returns
Gated output sample.

Definition at line 521 of file NoiseGate.h.

◆ reset()

template<FloatType T>
void dspark::NoiseGate< T >::reset ( )
inlinenoexcept

Resets DSP state (clears filters, sets state to Closed).

Definition at line 530 of file NoiseGate.h.

◆ setAdaptiveHold()

template<FloatType T>
void dspark::NoiseGate< T >::setAdaptiveHold ( bool  enabled)
inlinenoexcept

Toggles adaptive hold based on zero-crossing rate.

Definition at line 421 of file NoiseGate.h.

◆ setAttack()

template<FloatType T>
void dspark::NoiseGate< T >::setAttack ( T  ms)
inlinenoexcept

Sets attack time in milliseconds. Non-finite values are ignored.

Definition at line 344 of file NoiseGate.h.

◆ setAutoThreshold()

template<FloatType T>
void dspark::NoiseGate< T >::setAutoThreshold ( bool  on)
inlinenoexcept

Counts the threshold from the key's own recent level.

A reference follows the detected level: it rises at once and falls 1 dB per second, and the thresholds are counted from it. The gate then acts the same at any input level: a threshold of -40 dB closes on what lies more than 40 dB under the programme's recent peaks. While the key is under the closing threshold the reference falls a quarter as fast, so a pause lowers the threshold by 1 dB every four seconds: far enough into a long one the floor opens the gate again (the range bounds what that lets through), and a stray peak that left the programme under the threshold is forgotten at that pace. Off by default: the threshold is in dBFS.

State key "autoThreshold" (absent = off).

Definition at line 323 of file NoiseGate.h.

◆ setDuckMode()

template<FloatType T>
void dspark::NoiseGate< T >::setDuckMode ( bool  enabled)
inlinenoexcept

Toggles ducking mode (invert gate logic).

Definition at line 379 of file NoiseGate.h.

◆ setGateMode()

template<FloatType T>
void dspark::NoiseGate< T >::setGateMode ( GateMode  mode)
inlinenoexcept

Selects the processing mode (Amplitude or Frequency; wild enum values clamp).

Definition at line 386 of file NoiseGate.h.

◆ setHold()

template<FloatType T>
void dspark::NoiseGate< T >::setHold ( T  ms)
inlinenoexcept

Sets hold time in milliseconds. Non-finite values are ignored.

Definition at line 352 of file NoiseGate.h.

◆ setHysteresis()

template<FloatType T>
void dspark::NoiseGate< T >::setHysteresis ( T  dB)
inlinenoexcept

Sets the hysteresis amount (gap between open and close thresholds).

Parameters
dBHysteresis in decibels (floored to 0). Non-finite values are ignored.

Definition at line 336 of file NoiseGate.h.

◆ setLookahead()

template<FloatType T>
void dspark::NoiseGate< T >::setLookahead ( T  ms)
inlinenoexcept

Sets the lookahead: the audio is delayed so the gate opens (and closes) ahead of it. 0 (default) is latency-free.

RT-safe publication, consumed at the next block; change it while stopped (a live change jumps the delay and may click). Report getLatency() to the host for delay compensation.

Parameters
msLookahead in milliseconds, clamped to [0, 10]. Non-finite values are ignored.

Definition at line 404 of file NoiseGate.h.

◆ setRange()

template<FloatType T>
void dspark::NoiseGate< T >::setRange ( T  dB)
inlinenoexcept

Sets maximum attenuation range.

Parameters
dBRange in decibels (capped at 0). Non-finite values are ignored.

Definition at line 371 of file NoiseGate.h.

◆ setRelease()

template<FloatType T>
void dspark::NoiseGate< T >::setRelease ( T  ms)
inlinenoexcept

Sets release time in milliseconds. Non-finite values are ignored.

Definition at line 360 of file NoiseGate.h.

◆ setSidechainBand()

template<FloatType T>
void dspark::NoiseGate< T >::setSidechainBand ( int  band,
const KeyBand &  settings 
)
inlinenoexcept

Sets a band of the equalizer of the key.

Six bands (cuts from 6 to 48 dB per octave, bells, shelves, a tilt) shape what the detector weighs, after the sidechain high-pass, on the programme or on the external key, and never on the audio. A band that keeps its form glides to a new setting over 20 ms and a change of shape crosses over the same time; a band that is Off costs nothing. Key channels beyond 16 are read unshaped. The detector reads the loudest channel of the key.

With a two-channel key a band can sit on both channels, on the middle of the pair or on its sides (KeyBand::placement): a low cut on the middle keeps a centred bass from opening the gate while what is wide still does. Keys of one channel or of more than two, and processSample(), take every band on every channel.

Parameters
bandBand index in [0, KeyEq::kBands); others are ignored.
settingsShape, frequency, gain, q, slope and placement of the band.

Definition at line 474 of file NoiseGate.h.

◆ setSidechainHPF()

template<FloatType T>
void dspark::NoiseGate< T >::setSidechainHPF ( bool  enabled,
double  cutoffHz = 80.0 
)
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).

Parameters
enabledFilter active state.
cutoffHzFilter cutoff in Hz (clamped to [1, 0.45 * fs]).

Definition at line 437 of file NoiseGate.h.

◆ setSidechainListen()

template<FloatType T>
void dspark::NoiseGate< T >::setSidechainListen ( bool  on)
inlinenoexcept

Plays the key instead of the gated audio.

Each channel puts out what the detector hears of it (the key after the high-pass and the equalizer), late by the lookahead (the latency the gate reports, so the track keeps its place) and held under full scale (KeyMonitor), while the gate keeps working underneath. A monitoring switch: it is not part of the state.

Definition at line 491 of file NoiseGate.h.

◆ setState()

template<FloatType T>
bool dspark::NoiseGate< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

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

Definition at line 579 of file NoiseGate.h.

◆ setThreshold()

template<FloatType T>
void dspark::NoiseGate< T >::setThreshold ( T  dB)
inlinenoexcept

Sets the opening threshold.

Parameters
dBThreshold in decibels. Non-finite values are ignored.

Definition at line 300 of file NoiseGate.h.

◆ syncParams()

template<FloatType T>
void dspark::NoiseGate< T >::syncParams ( )
inlineprotectednoexcept

Definition at line 615 of file NoiseGate.h.

◆ syncParamsIfDirty()

template<FloatType T>
void dspark::NoiseGate< T >::syncParamsIfDirty ( )
inlineprotectednoexcept

Definition at line 603 of file NoiseGate.h.

◆ updateStateMachine()

template<FloatType T>
void dspark::NoiseGate< T >::updateStateMachine ( T  envelopeLinear)
inlineprotectednoexcept

Definition at line 698 of file NoiseGate.h.

◆ updateZeroCrossing()

template<FloatType T>
void dspark::NoiseGate< T >::updateZeroCrossing ( T  sample)
inlineprotectednoexcept

Definition at line 752 of file NoiseGate.h.

Member Data Documentation

◆ adaptiveHold_

template<FloatType T>
std::atomic<bool> dspark::NoiseGate< T >::adaptiveHold_ { false }
protected

Definition at line 890 of file NoiseGate.h.

◆ attackCoeff_

template<FloatType T>
T dspark::NoiseGate< T >::attackCoeff_ = T(0)
protected

Definition at line 928 of file NoiseGate.h.

◆ attackMs_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::attackMs_ { T(0.5) }
protected

Definition at line 884 of file NoiseGate.h.

◆ autoFall_

template<FloatType T>
double dspark::NoiseGate< T >::autoFall_ = 1.0
protected

Its fall per sample (a factor).

Definition at line 939 of file NoiseGate.h.

◆ autoFallQuiet_

template<FloatType T>
double dspark::NoiseGate< T >::autoFallQuiet_ = 1.0
protected

The same while the key is quiet.

Definition at line 940 of file NoiseGate.h.

◆ autoRef_

template<FloatType T>
double dspark::NoiseGate< T >::autoRef_ = kAutoRefFloor
protected

The reference (linear).

Definition at line 938 of file NoiseGate.h.

◆ autoThreshold_

template<FloatType T>
std::atomic<bool> dspark::NoiseGate< T >::autoThreshold_ { false }
protected

The thresholds count from the key's recent level.

Definition at line 936 of file NoiseGate.h.

◆ cachedAdaptiveHold_

template<FloatType T>
bool dspark::NoiseGate< T >::cachedAdaptiveHold_ = false
protected

Definition at line 911 of file NoiseGate.h.

◆ cachedAutoThreshold_

template<FloatType T>
bool dspark::NoiseGate< T >::cachedAutoThreshold_ = false
protected

Definition at line 937 of file NoiseGate.h.

◆ cachedCloseThresholdLinear_

template<FloatType T>
T dspark::NoiseGate< T >::cachedCloseThresholdLinear_ = T(0.0063)
protected

Definition at line 907 of file NoiseGate.h.

◆ cachedDuck_

template<FloatType T>
bool dspark::NoiseGate< T >::cachedDuck_ = false
protected

Definition at line 909 of file NoiseGate.h.

◆ cachedFsInvPi2_

template<FloatType T>
T dspark::NoiseGate< T >::cachedFsInvPi2_ = T(0)
protected

Definition at line 914 of file NoiseGate.h.

◆ cachedGateMode_

template<FloatType T>
GateMode dspark::NoiseGate< T >::cachedGateMode_ = GateMode::Amplitude
protected

Definition at line 910 of file NoiseGate.h.

◆ cachedNyquist_

template<FloatType T>
T dspark::NoiseGate< T >::cachedNyquist_ = T(24000)
protected

Definition at line 913 of file NoiseGate.h.

◆ cachedRangeLinear_

template<FloatType T>
T dspark::NoiseGate< T >::cachedRangeLinear_ = T(0.0001)
protected

Definition at line 908 of file NoiseGate.h.

◆ cachedScHpfEnabled_

template<FloatType T>
bool dspark::NoiseGate< T >::cachedScHpfEnabled_ = false
protected

Definition at line 912 of file NoiseGate.h.

◆ cachedThresholdLinear_

template<FloatType T>
T dspark::NoiseGate< T >::cachedThresholdLinear_ = T(0.01)
protected

Definition at line 906 of file NoiseGate.h.

◆ detectorReleaseCoeff_

template<FloatType T>
T dspark::NoiseGate< T >::detectorReleaseCoeff_ = T(0)
protected

Definition at line 944 of file NoiseGate.h.

◆ duckMode_

template<FloatType T>
std::atomic<bool> dspark::NoiseGate< T >::duckMode_ { false }
protected

Definition at line 888 of file NoiseGate.h.

◆ envelopeState_

template<FloatType T>
T dspark::NoiseGate< T >::envelopeState_ = T(0)
protected

Definition at line 943 of file NoiseGate.h.

◆ estimatedPeriod_

template<FloatType T>
int dspark::NoiseGate< T >::estimatedPeriod_ = 0
protected

Definition at line 961 of file NoiseGate.h.

◆ freqHpFreq_

template<FloatType T>
std::array<T, kMaxChannels> dspark::NoiseGate< T >::freqHpFreq_ {}
protected

Definition at line 955 of file NoiseGate.h.

◆ freqHpPrev_

template<FloatType T>
std::array<T, kMaxChannels> dspark::NoiseGate< T >::freqHpPrev_ {}
protected

Definition at line 953 of file NoiseGate.h.

◆ freqHpState_

template<FloatType T>
std::array<T, kMaxChannels> dspark::NoiseGate< T >::freqHpState_ {}
protected

Definition at line 952 of file NoiseGate.h.

◆ freqLpFreq_

template<FloatType T>
std::array<T, kMaxChannels> dspark::NoiseGate< T >::freqLpFreq_ {}
protected

Definition at line 954 of file NoiseGate.h.

◆ freqLpState_

template<FloatType T>
std::array<T, kMaxChannels> dspark::NoiseGate< T >::freqLpState_ {}
protected

Definition at line 951 of file NoiseGate.h.

◆ freqSmoothCoeff_

template<FloatType T>
T dspark::NoiseGate< T >::freqSmoothCoeff_ = T(0)
protected

Definition at line 950 of file NoiseGate.h.

◆ gateGain_

template<FloatType T>
T dspark::NoiseGate< T >::gateGain_ = T(0)
protected

Definition at line 947 of file NoiseGate.h.

◆ gateMode_

template<FloatType T>
std::atomic<GateMode> dspark::NoiseGate< T >::gateMode_ { GateMode::Amplitude }
protected

Definition at line 889 of file NoiseGate.h.

◆ heard_

template<FloatType T>
std::array<T, kMaxScChannels> dspark::NoiseGate< T >::heard_ {}
protected

The key of each channel in this frame.

Definition at line 926 of file NoiseGate.h.

◆ holdCounter_

template<FloatType T>
int dspark::NoiseGate< T >::holdCounter_ = 0
protected

Definition at line 948 of file NoiseGate.h.

◆ holdMs_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::holdMs_ { T(50) }
protected

Definition at line 885 of file NoiseGate.h.

◆ holdSamples_

template<FloatType T>
int dspark::NoiseGate< T >::holdSamples_ = 0
protected

Definition at line 930 of file NoiseGate.h.

◆ hysteresis_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::hysteresis_ { T(4) }
protected

Definition at line 883 of file NoiseGate.h.

◆ kAutoRefFallDb

template<FloatType T>
constexpr double dspark::NoiseGate< T >::kAutoRefFallDb = 1.0
staticconstexprprotected

dB per second its reference falls.

Definition at line 933 of file NoiseGate.h.

◆ kAutoRefFloor

template<FloatType T>
constexpr double dspark::NoiseGate< T >::kAutoRefFloor = 1e-5
staticconstexprprotected

The reference never goes under -100 dBFS.

Definition at line 935 of file NoiseGate.h.

◆ kAutoRefQuiet

template<FloatType T>
constexpr double dspark::NoiseGate< T >::kAutoRefQuiet = 0.25
staticconstexprprotected

Share of that fall while the key is under the closing threshold.

Definition at line 934 of file NoiseGate.h.

◆ keyEq_

template<FloatType T>
KeyEq dspark::NoiseGate< T >::keyEq_
protected

Equalizer of the key, after the high-pass.

Definition at line 921 of file NoiseGate.h.

◆ keyMonitor_

template<FloatType T>
KeyMonitor<T, 16> dspark::NoiseGate< T >::keyMonitor_
protected

The listened key: late by the lookahead, under full scale.

Definition at line 922 of file NoiseGate.h.

◆ keyOn_

template<FloatType T>
bool dspark::NoiseGate< T >::keyOn_ = false
protected

The equalizer has bands in the path (audio thread).

Definition at line 924 of file NoiseGate.h.

◆ kMaxChannels

template<FloatType T>
constexpr int dspark::NoiseGate< T >::kMaxChannels = 2
staticconstexprprotected

Definition at line 601 of file NoiseGate.h.

◆ kMaxLookaheadChannels

template<FloatType T>
constexpr int dspark::NoiseGate< T >::kMaxLookaheadChannels = 16
staticconstexprprotected

Definition at line 898 of file NoiseGate.h.

◆ kMaxLookaheadMs

template<FloatType T>
constexpr double dspark::NoiseGate< T >::kMaxLookaheadMs = 10.0
staticconstexprprotected

Definition at line 897 of file NoiseGate.h.

◆ kMaxScChannels

template<FloatType T>
constexpr int dspark::NoiseGate< T >::kMaxScChannels = 16
staticconstexprprotected

Definition at line 916 of file NoiseGate.h.

◆ kZeroCrossWindow

template<FloatType T>
constexpr int dspark::NoiseGate< T >::kZeroCrossWindow = 2048
staticconstexprprotected

Definition at line 957 of file NoiseGate.h.

◆ listen_

template<FloatType T>
bool dspark::NoiseGate< T >::listen_ = false
protected

scListen_ as the audio thread took it.

Definition at line 925 of file NoiseGate.h.

◆ lookahead_

template<FloatType T>
std::array<RingBuffer<T>, kMaxLookaheadChannels> dspark::NoiseGate< T >::lookahead_ {}
protected

Definition at line 903 of file NoiseGate.h.

◆ lookaheadChannels_

template<FloatType T>
int dspark::NoiseGate< T >::lookaheadChannels_ = 0
protected

Channels with a prepared delay line.

Definition at line 902 of file NoiseGate.h.

◆ lookaheadMs_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::lookaheadMs_ { T(0) }
protected

Definition at line 899 of file NoiseGate.h.

◆ lookaheadSamples_

template<FloatType T>
int dspark::NoiseGate< T >::lookaheadSamples_ = 0
protected

Audio-side value (consumed in syncParams()).

Definition at line 900 of file NoiseGate.h.

◆ maxLookaheadSamples_

template<FloatType T>
int dspark::NoiseGate< T >::maxLookaheadSamples_ = 0
protected

Allocated delay (0 before prepare()).

Definition at line 901 of file NoiseGate.h.

◆ paramsDirty_

template<FloatType T>
std::atomic<bool> dspark::NoiseGate< T >::paramsDirty_ { true }
protected

Definition at line 891 of file NoiseGate.h.

◆ prevSign_

template<FloatType T>
bool dspark::NoiseGate< T >::prevSign_ = false
protected

Definition at line 960 of file NoiseGate.h.

◆ rangeDb_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::rangeDb_ { T(-80) }
protected

Definition at line 887 of file NoiseGate.h.

◆ releaseCoeff_

template<FloatType T>
T dspark::NoiseGate< T >::releaseCoeff_ = T(0)
protected

Definition at line 929 of file NoiseGate.h.

◆ releaseMs_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::releaseMs_ { T(100) }
protected

Definition at line 886 of file NoiseGate.h.

◆ sampleRate_

template<FloatType T>
double dspark::NoiseGate< T >::sampleRate_ = 48000.0
protected

Definition at line 880 of file NoiseGate.h.

◆ scHpfA0_

template<FloatType T>
T dspark::NoiseGate< T >::scHpfA0_ = T(0.9975)
protected

Definition at line 918 of file NoiseGate.h.

◆ scHpfCoeff_

template<FloatType T>
T dspark::NoiseGate< T >::scHpfCoeff_ = T(0.995)
protected

Definition at line 917 of file NoiseGate.h.

◆ scHpfEnabled_

template<FloatType T>
std::atomic<bool> dspark::NoiseGate< T >::scHpfEnabled_ { false }
protected

Definition at line 893 of file NoiseGate.h.

◆ scHpfFreq_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::scHpfFreq_ { T(80) }
protected

Definition at line 894 of file NoiseGate.h.

◆ scHpfPrev_

template<FloatType T>
std::array<T, kMaxScChannels> dspark::NoiseGate< T >::scHpfPrev_ {}
protected

Definition at line 920 of file NoiseGate.h.

◆ scHpfState_

template<FloatType T>
std::array<T, kMaxScChannels> dspark::NoiseGate< T >::scHpfState_ {}
protected

Definition at line 919 of file NoiseGate.h.

◆ scListen_

template<FloatType T>
std::atomic<bool> dspark::NoiseGate< T >::scListen_ { false }
protected

The key goes out instead of the audio.

Definition at line 923 of file NoiseGate.h.

◆ state_

template<FloatType T>
State dspark::NoiseGate< T >::state_ = State::Closed
protected

Definition at line 946 of file NoiseGate.h.

◆ threshold_

template<FloatType T>
std::atomic<T> dspark::NoiseGate< T >::threshold_ { T(-40) }
protected

Definition at line 882 of file NoiseGate.h.

◆ zeroCrossCount_

template<FloatType T>
int dspark::NoiseGate< T >::zeroCrossCount_ = 0
protected

Definition at line 958 of file NoiseGate.h.

◆ zeroCrossSamples_

template<FloatType T>
int dspark::NoiseGate< T >::zeroCrossSamples_ = 0
protected

Definition at line 959 of file NoiseGate.h.


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