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

High-performance brickwall lookahead limiter. More...

#include <Limiter.h>

Public Types

enum class  TruePeakPrecision { Standard , High }
 
enum class  Precision { Standard , High }
 
enum class  HoldMode { Deepest , EveryPeak }
 

Public Member Functions

 ~Limiter ()=default
 
void prepare (double sampleRate, int numChannels=2, double initialLookaheadMs=-1.0)
 Allocates memory and prepares the limiter for processing.
 
void prepare (const AudioSpec &spec)
 Prepares from AudioSpec (unified API).
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes an AudioBufferView in-place.
 
T processSample (T input, int channel) noexcept
 Processes a single sample of one channel.
 
void reset () noexcept
 Resets the internal state (delays, gain reduction). RT-Safe.
 
void setCeiling (T dB) noexcept
 Sets the absolute output ceiling.
 
void setRelease (T ms) noexcept
 Sets the base release time.
 
void setLookahead (T ms) noexcept
 Sets the lookahead time dynamically.
 
void setMaxLookahead (T ms) noexcept
 Keeps a latency for the lookahead to move inside.
 
T getMaxLookahead () const noexcept
 Latency kept for the lookahead in milliseconds (0: none; see setMaxLookahead()).
 
void setTruePeak (bool enabled) noexcept
 Enables ISP true-peak detection. RT-Safe.
 
void setTruePeakPrecision (TruePeakPrecision precision) noexcept
 Selects the true-peak reading (see TruePeakPrecision). RT-Safe.
 
TruePeakPrecision getTruePeakPrecision () const noexcept
 
void setPrecision (Precision precision) noexcept
 Selects how finely the gain computer works (see Precision). RT-Safe.
 
Precision getPrecision () const noexcept
 
void setAdaptiveRelease (bool enabled) noexcept
 Enables program-dependent adaptive release. RT-Safe. The release time grows with how long peaks have been asking for reduction: up to 3x after 200 ms of sustained limiting.
 
void setHold (T ms) noexcept
 Sets how long the reduction is held after the last peak that asked for it, before the release starts. RT-Safe.
 
T getHold () const noexcept
 
void setHoldMode (HoldMode mode) noexcept
 Selects the hold behaviour (see HoldMode). RT-Safe.
 
HoldMode getHoldMode () const noexcept
 
void setSafetyClip (bool enabled) noexcept
 Enables the post-limiter soft-knee safety clipper. RT-Safe.
 
bool isTruePeakEnabled () const noexcept
 
bool isAdaptiveReleaseEnabled () const noexcept
 
bool isSafetyClipEnabled () const noexcept
 
T getLookahead () const noexcept
 
int getLatency () const noexcept
 Reports the processing latency (the lookahead) in samples.
 
T getGainReductionDb () const noexcept
 Current gain reduction in dB (metering).
 
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 Types

using TpEstimator = TruePeakEstimator< T >
 
using TpAnalyzer = TruePeakAnalyzer< T >
 

Protected Member Functions

void detectTruePeak (const T *x, int n, int ch, T *peak, T *annex, T *slow) noexcept
 
T alignHighReadings (T samplePeak, T annex, T slow) noexcept
 
void resetHighAlignment () noexcept
 
void seedHighTruePeakHistory () noexcept
 
void seedTruePeakHistory () noexcept
 
int lookaheadSamplesFor (T ms, bool truePeak, bool highPrecision, bool points) const noexcept
 
void readPoints (T x, int ch, T *points) noexcept
 
void seedPointHistory (bool fromDelayLines) noexcept
 
void applyLookaheadTarget () noexcept
 
int latencyFor (int lookahead, bool truePeak, bool highPrecision, bool points) const noexcept
 
void syncKeptLatency () noexcept
 
T heldGain (int look, int &delay) noexcept
 
void configureGainComputer () noexcept
 
DSPARK_NOINLINE void resumBoxes () noexcept
 
DSPARK_NOINLINE void restartHoldBlock (int64_t firstFrame) noexcept
 
void resetGainComputer () noexcept
 
void restartGainComputerAt (double g) noexcept
 
void advanceGain (T peak, T ceiling, bool adaptive, T relMs) noexcept
 
void advanceGainPoints (const T *points, T ceiling, bool adaptive, T relMs) noexcept
 
void stepGain (double required, bool adaptive, T relMs) noexcept
 
void syncParameters () noexcept
 
void updateHoldSamples () noexcept
 
void updateReleaseCoefficient () noexcept
 
T applySafetyClipper (T out, T clipCeil) const noexcept
 

Protected Attributes

TpEstimator tpEstimator_
 Kernel and phase scratch.
 
std::vector< typename TpEstimator::Channel > tpChannels_
 Per channel history.
 
std::unique_ptr< TpAnalyzer > tpAnalyzer_
 High-precision kernels and scratch (prepare()).
 
std::vector< typename TpAnalyzer::Channel > tpHighChannels_
 Per channel history of the high-precision reading.
 
bool prepared_ = false
 
double sampleRate_ = 48000.0
 
T invSampleRate_ = T(1.0 / 48000.0)
 
int numChannels_ = 2
 
int lookaheadSamples_ = 96
 Audio-side lookahead (consumed from lookaheadMs_).
 
int maxLimitSamples_ = 96000
 Adaptive-release duration cap (2 s).
 
std::atomic< T > ceilingDb_ { T(-0.3) }
 
std::atomic< T > releaseMs_ { T(100) }
 
std::atomic< T > holdMs_ { T(10) }
 
std::atomic< T > lookaheadMs_ { T(2) }
 
std::atomic< bool > lookaheadDirty_ { false }
 
std::atomic< bool > truePeakEnabled_ { false }
 
std::atomic< bool > adaptiveRelease_ { false }
 
std::atomic< bool > safetyClipEnabled_ { false }
 
SmoothedValue< T > ceilingSmooth_
 
T lastCeilingDb_ = T(-0.3)
 Change detector for the ceiling pow skip.
 
T releaseCoeff_ = T(0)
 
T lastReleaseMs_ = T(-1)
 
T lastHoldMs_ = T(-1)
 
int holdSamples_ = 0
 Hold length in samples.
 
int maxHoldSamples_ = 2400
 Hold length of kMaxHoldMs.
 
int counterHold_ = 0
 Hold-counter restart value (Deepest mode).
 
int holdLeft_ = 0
 Hold samples left before the release may act.
 
int lastHoldMode_ = 0
 Applied HoldMode (0 Deepest, 1 EveryPeak).
 
std::atomic< int > holdMode_ { 0 }
 
std::atomic< int > truePeakPrecision_ { 0 }
 Published TruePeakPrecision (0 Standard, 1 High).
 
bool ispApplied_ = false
 Detection mode the gain computer is sized for.
 
bool tpHighApplied_ = false
 High-precision reading applied (implies ispApplied_).
 
std::atomic< int > precision_ { 0 }
 Published Precision (0 Standard, 1 High).
 
bool pointsApplied_ = false
 Readings at eight points per sample applied (sample-peak mode).
 
int stepsPerSample_ = 1
 Steps of the gain computer per sample (1 or kSteps).
 
double holdSlack_ = 1.0
 Factor of the held reduction a crest restarts the hold within.
 
T pointPhase_ [kSteps - 1][kPointTaps] = {}
 Interpolation phases (prepare()).
 
T pointHist_ [kMaxChannels][2 *kPointTaps] = {}
 Mirrored interpolation history per channel.
 
int pointAt_ [kMaxChannels] = {}
 Next write position in it.
 
T chunkPoints_ [kChunk][kSteps] = {}
 processBlock() points per frame (loudest channel).
 
T pendingPoints_ [kSteps] = {}
 Other channels' points for the next processSample() frame.
 
T currentGain_ = T(1)
 
std::atomic< T > publishedGain_ { T(1) }
 
int limitingDuration_ = 0
 
T lookaheadCurrent_ = T(96)
 Smoothed read offset (glides on live changes).
 
int histSize_ = 0
 
int histMask_ = 0
 Moving-average histories (lookahead).
 
int holdHistSize_ = 0
 
int holdMask_ = 0
 Required-gain history (lookahead + hold).
 
std::vector< double > eHist_
 Released envelope history.
 
std::vector< double > avgHist_
 First moving-average output history.
 
std::vector< double > rHist_
 Required-gain history.
 
std::vector< double > sufMin_
 Suffix minima of the last complete hold block (+1 empty).
 
int blockPos_ = 0
 Position inside the current hold block.
 
double prefixMin_ = 1.0
 Running minimum of the current hold block.
 
int64_t frame_ = 0
 
double envelope_ = 1.0
 
double sum1_ = 1.0
 
double sum2_ = 1.0
 
int boxA_ = 1
 
int boxB_ = 1
 
double invBoxA_ = 1.0
 
double invBoxB_ = 1.0
 
int holdLen_ = 97
 
int sinceResum_ = 0
 
T pendingPeak_ = T(0)
 Other channels' peaks for the next processSample() frame.
 
T pendingAnnex_ = T(0)
 The same for their Annex 2 readings (high precision).
 
T pendingSlow_ = T(0)
 The same for their analyzer readings (high precision).
 
T alignSample_ [kAlignRecent] = {}
 Recent sample peaks.
 
T alignAnnex_ [kAlignRecent] = {}
 Recent Annex 2 readings.
 
T alignFast_ [kAlignRing] = {}
 Fast readings per sample, waiting for the analyzer.
 
T alignSlow_ [2] = {}
 Last two analyzer readings.
 
int alignFrame_ = 0
 Frame counter modulo kAlignRing.
 
T chunkAnnex_ [kChunk] = {}
 
T chunkSlow_ [kChunk] = {}
 
T chunkPeak_ [kChunk] = {}
 
T chunkCeiling_ [kChunk] = {}
 
T chunkGain_ [kChunk] = {}
 
int chunkLook_ [kChunk] = {}
 
int chunkDelay_ [kChunk] = {}
 Delay of the audio per frame (the lookahead, or the latency kept).
 
T sampleCeiling_ = T(0.96605)
 
int sampleLookNow_ = 96
 
int sampleDelayNow_ = 96
 Delay of the audio for the frame.
 
T sampleGainNow_ = T(1)
 Gain heard in the frame.
 
std::atomic< T > maxLookaheadMs_ { T(0) }
 Latency kept (0: none).
 
int latencySamples_ = 96
 Delay the audio is asked to have (audio thread).
 
T latencyCurrent_ = T(96)
 Its smoothed value while kept.
 
bool kept_ = false
 The gain is being held back.
 
int gainSpan_ = 0
 Length of the gain line.
 
RingBuffer< T > gainLine_
 Gains waiting for the audio they belong to.
 
std::vector< RingBuffer< T > > delayLines_
 

Static Protected Attributes

static constexpr int kMaxChannels = 16
 
static constexpr double kMaxLookaheadMs = 10.0
 
static constexpr double kMaxHoldMs = 50.0
 
static constexpr T kSafetyClipCeiling = T(0.96605)
 -0.3 dBFS
 
static constexpr int kChunk = 128
 
static constexpr int kTpDelay = TpEstimator::getDelay()
 Samples a reading reaches back.
 
static constexpr int kTpMinLookahead = kTpDelay + 16
 Leaves at least a 16-sample ramp.
 
static constexpr int kTpHighDelay = TpAnalyzer::getDelay() + 1
 Samples a high-precision reading reaches back.
 
static constexpr int kAnnexWindow = TruePeakDetector<T, 1>::getTaps()
 Samples one Annex 2 reading is formed from.
 
static constexpr int kAlignFast = kTpHighDelay - (kAnnexWindow - 1)
 Delay of the fast readings.
 
static constexpr int kAlignRing = 256
 Power of two above kAlignFast.
 
static constexpr int kAlignRecent = 16
 Power of two holding kAnnexWindow frames.
 
static constexpr int kSteps = 8
 Steps of the gain computer per sample at Precision::High.
 
static constexpr int kPointTaps = 16
 Taps of the interpolation.
 
static constexpr int kPointDelay = 7
 Samples the points reach back.
 
static constexpr double kPointBeta = 9.0
 Kaiser beta of the interpolation.
 
static constexpr double kHoldTolerance = 1.0011520
 0.01 dB: crests that close restart the hold (Precision::High).
 
static constexpr int kResumPeriod = 1 << 16
 

Detailed Description

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

High-performance brickwall lookahead limiter.

Template Parameters
TSample type (float or double).

Definition at line 126 of file Limiter.h.

Member Typedef Documentation

◆ TpAnalyzer

template<FloatType T>
using dspark::Limiter< T >::TpAnalyzer = TruePeakAnalyzer<T>
protected

Definition at line 906 of file Limiter.h.

◆ TpEstimator

template<FloatType T>
using dspark::Limiter< T >::TpEstimator = TruePeakEstimator<T>
protected

Definition at line 888 of file Limiter.h.

Member Enumeration Documentation

◆ HoldMode

template<FloatType T>
enum class dspark::Limiter::HoldMode
strong

How the hold treats a peak that asks for less reduction than the one being held.

Enumerator
Deepest 

The hold restarts only when a peak pushes the reduction down (or keeps it down); a shallower peak inside the hold is not held after the deeper one expires, so the gain can rise between peaks of unequal height. The default.

EveryPeak 

Every peak's reduction is held for the hold time after it has passed (an exact sliding minimum over lookahead plus hold). The gain stops rising and falling between unequal peaks: the 60 Hz + 7 kHz intermodulation of a two-tone driven 6 dB over the ceiling falls from -61.7 to -87.1 dBc at the defaults (from -69.4 to -84.3 dBc at 5 ms lookahead, 15 ms hold, 40 ms release). The price is loudness: dense material driven 12 dB over the ceiling comes out 0.45 dB lower at those settings, 0.10 dB at 6 dB over. The required-gain history prepare() allocates spans the lookahead plus the 50 ms maximum hold in either mode (64 KB at 48 kHz).

Definition at line 746 of file Limiter.h.

◆ Precision

template<FloatType T>
enum class dspark::Limiter::Precision
strong

How finely the gain computer reads the sample-peak signal.

Enumerator
Standard 

One reading and one step of the gain computer per sample. The default.

High 

Eight readings per sample from a windowed-sinc interpolation, and the window, hold, release and ramp of the gain computer taking eight steps per sample. See setPrecision().

Definition at line 655 of file Limiter.h.

◆ TruePeakPrecision

template<FloatType T>
enum class dspark::Limiter::TruePeakPrecision
strong

Which reading true-peak mode feeds the sidechain with.

Enumerator
Standard 

The 64-tap reading that answers within 33 samples, taken out of the lookahead: accurate up to 0.45 of the sample rate. The default.

High 

The reading of TruePeakAnalyzer (an 8x grid from a 512-tap first stage), which also follows content between 0.45 of the sample rate and Nyquist. It reaches 262 samples back and they are added to the latency, so the lookahead is all attack ramp as in sample-peak mode.

Definition at line 603 of file Limiter.h.

Constructor & Destructor Documentation

◆ ~Limiter()

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

Member Function Documentation

◆ advanceGain()

template<FloatType T>
void dspark::Limiter< T >::advanceGain ( T  peak,
T  ceiling,
bool  adaptive,
T  relMs 
)
inlineprotectednoexcept

One frame of the gain computer; leaves the gain to apply in currentGain_.

Definition at line 1284 of file Limiter.h.

◆ advanceGainPoints()

template<FloatType T>
void dspark::Limiter< T >::advanceGainPoints ( const T *  points,
T  ceiling,
bool  adaptive,
T  relMs 
)
inlineprotectednoexcept

One frame at Precision::High: the eight points' requirements, one step each, in time order; the gain heard is the last step's.

Definition at line 1298 of file Limiter.h.

◆ alignHighReadings()

template<FloatType T>
T dspark::Limiter< T >::alignHighReadings ( T  samplePeak,
T  annex,
T  slow 
)
inlineprotectednoexcept

One frame of the high-precision alignment: takes this frame's sample peak, Annex 2 reading and analyzer reading (loudest channel) and returns the peak that concerns the sample kTpHighDelay frames back: its own magnitude, every Annex 2 reading formed from it (the twelve that follow it) and the three analyzer readings around it.

Definition at line 936 of file Limiter.h.

◆ applyLookaheadTarget()

template<FloatType T>
void dspark::Limiter< T >::applyLookaheadTarget ( )
inlineprotectednoexcept

Consumes the published lookahead and true-peak parameters (audio/setup thread). Processing uses the detection mode applied here, so the detector and the ramp sized for it always match.

Definition at line 1092 of file Limiter.h.

◆ applySafetyClipper()

template<FloatType T>
T dspark::Limiter< T >::applySafetyClipper ( T  out,
T  clipCeil 
) const
inlineprotectednoexcept

Symmetric soft-knee clipper for the region above the clip threshold, with a hard backstop at 1.05x the threshold.

Definition at line 1417 of file Limiter.h.

◆ configureGainComputer()

template<FloatType T>
void dspark::Limiter< T >::configureGainComputer ( )
inlineprotectednoexcept

Sizes the hold window and the two moving averages for the current lookahead / ISP mode and rebuilds their running sums from history.

Definition at line 1182 of file Limiter.h.

◆ detectTruePeak()

template<FloatType T>
void dspark::Limiter< T >::detectTruePeak ( const T *  x,
int  n,
int  ch,
T *  peak,
T *  annex,
T *  slow 
)
inlineprotectednoexcept

True-peak readings of n (<= kChunk) samples of channel ch. Standard precision raises peak[i] to the 64-tap estimate and the ITU-R BS.1770 Annex 2 one. High precision raises slow[i] to the analyzer's reading and annex[i] to the Annex 2 one, for alignHighReadings(). The per-sample path calls it with n == 1; every output runs the same arithmetic either way.

Definition at line 923 of file Limiter.h.

◆ getGainReductionDb()

template<FloatType T>
T dspark::Limiter< T >::getGainReductionDb ( ) const
inlinenoexcept

Current gain reduction in dB (metering).

Safe from any thread: it loads a published atomic word, so off the audio thread it may be up to one block behind. It used to read currentGain_ directly – a plain word the audio thread writes every sample, read from another thread, which is a data race and not merely an approximate number.

Definition at line 822 of file Limiter.h.

◆ getHold()

template<FloatType T>
T dspark::Limiter< T >::getHold ( ) const
inlinenoexcept
Returns
The hold time in milliseconds.

Definition at line 742 of file Limiter.h.

◆ getHoldMode()

template<FloatType T>
HoldMode dspark::Limiter< T >::getHoldMode ( ) const
inlinenoexcept
Returns
The hold mode.

Definition at line 774 of file Limiter.h.

◆ getLatency()

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

Reports the processing latency (the lookahead) in samples.

Derived from the published lookahead and true-peak parameters, so it is correct immediately after setLookahead() or setTruePeak() from any thread (the audio thread may consume the change one block later; the glide covers the transition). In true-peak mode the lookahead is at least 49 samples (about 1 ms at 48 kHz); with its high-precision reading it is the set lookahead plus 262 samples. With setMaxLookahead() it is the latency kept, while the lookahead stays under it.

Definition at line 806 of file Limiter.h.

◆ getLookahead()

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

Definition at line 792 of file Limiter.h.

◆ getMaxLookahead()

template<FloatType T>
T dspark::Limiter< T >::getMaxLookahead ( ) const
inlinenoexcept

Latency kept for the lookahead in milliseconds (0: none; see setMaxLookahead()).

Definition at line 573 of file Limiter.h.

◆ getPrecision()

template<FloatType T>
Precision dspark::Limiter< T >::getPrecision ( ) const
inlinenoexcept
Returns
The selected precision.

Definition at line 708 of file Limiter.h.

◆ getState()

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

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

Definition at line 829 of file Limiter.h.

◆ getTruePeakPrecision()

template<FloatType T>
TruePeakPrecision dspark::Limiter< T >::getTruePeakPrecision ( ) const
inlinenoexcept
Returns
The selected true-peak reading.

Definition at line 648 of file Limiter.h.

◆ heldGain()

template<FloatType T>
T dspark::Limiter< T >::heldGain ( int  look,
int &  delay 
)
inlineprotectednoexcept

One frame with a latency kept for the lookahead: glides the delay of the audio towards it (never under the lookahead), stores the gain just computed and returns the one that is heard, older by the difference.

Parameters
lookLookahead of this frame in samples.
delayReceives the delay of the audio for this frame.

Definition at line 1152 of file Limiter.h.

◆ isAdaptiveReleaseEnabled()

template<FloatType T>
bool dspark::Limiter< T >::isAdaptiveReleaseEnabled ( ) const
inlinenoexcept

Definition at line 790 of file Limiter.h.

◆ isSafetyClipEnabled()

template<FloatType T>
bool dspark::Limiter< T >::isSafetyClipEnabled ( ) const
inlinenoexcept

Definition at line 791 of file Limiter.h.

◆ isTruePeakEnabled()

template<FloatType T>
bool dspark::Limiter< T >::isTruePeakEnabled ( ) const
inlinenoexcept

Definition at line 789 of file Limiter.h.

◆ latencyFor()

template<FloatType T>
int dspark::Limiter< T >::latencyFor ( int  lookahead,
bool  truePeak,
bool  highPrecision,
bool  points 
) const
inlineprotectednoexcept

Delay of the audio for a lookahead in samples: the latency kept for it (setMaxLookahead()) when that is longer, the lookahead otherwise. Shared by the audio side and getLatency(), like lookaheadSamplesFor().

Definition at line 1121 of file Limiter.h.

◆ lookaheadSamplesFor()

template<FloatType T>
int dspark::Limiter< T >::lookaheadSamplesFor ( T  ms,
bool  truePeak,
bool  highPrecision,
bool  points 
) const
inlineprotectednoexcept

Lookahead in samples for a given ms parameter and detection mode (shared by the audio-side recompute and getLatency() so both always agree exactly). The product is capped in double before the int cast (out-of-range casts are UB). True-peak mode needs the estimator's kTpDelay samples plus a ramp of at least 16 samples; its high-precision reading adds its whole reach on top, so the lookahead parameter is all ramp, as in sample-peak mode.

Definition at line 1031 of file Limiter.h.

◆ prepare() [1/2]

template<FloatType T>
void dspark::Limiter< T >::prepare ( const AudioSpec &  spec)
inline

Prepares from AudioSpec (unified API).

Preserves the configured lookahead parameter (it does NOT reset it to the constructor default), so a host re-activation keeps the latency the user dialled in.

Definition at line 249 of file Limiter.h.

◆ prepare() [2/2]

template<FloatType T>
void dspark::Limiter< T >::prepare ( double  sampleRate,
int  numChannels = 2,
double  initialLookaheadMs = -1.0 
)
inline

Allocates memory and prepares the limiter for processing.

Invalid arguments are release-safe: a non-positive or non-finite sample rate makes this call a no-op (the previous state, if any, is kept). Configured parameters (ceiling, release, lookahead, toggles) survive re-preparation.

Warning
Must be called from the main/setup thread, NEVER from the audio thread.
Parameters
sampleRateSample rate in Hz (must be > 0).
numChannelsNumber of channels to process (clamped to [1, 16]).
initialLookaheadMsOptional lookahead override in ms; any non-positive or non-finite value (the default) keeps the current lookahead parameter.

Definition at line 149 of file Limiter.h.

◆ processBlock()

template<FloatType T>
void dspark::Limiter< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes an AudioBufferView in-place.

RT-Safe: Yes. Lock-free and allocation-free.

The gain envelope is linked: the loudest channel drives the reduction applied to all channels. Channels beyond the prepared count pass through untouched (and undelayed).

Parameters
bufferAudio buffer view.

Definition at line 265 of file Limiter.h.

◆ processSample()

template<FloatType T>
T dspark::Limiter< T >::processSample ( T  input,
int  channel 
)
inlinenoexcept

Processes a single sample of one channel.

The shared state (ceiling smoother, lookahead glide and gain computer) advances on channel 0, so call channel 0 first within each sample frame. For mono streams (channel 0 only) this path is bit-identical to processBlock(). Peaks of the other channels enter the gain computer one frame late; for properly linked multi-channel limiting prefer processBlock().

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

Definition at line 389 of file Limiter.h.

◆ readPoints()

template<FloatType T>
void dspark::Limiter< T >::readPoints ( T  x,
int  ch,
T *  points 
)
inlineprotectednoexcept

Feeds one sample of channel ch to its interpolation history and raises points[0 .. kSteps - 1] to the magnitudes of this frame's points.

Definition at line 1058 of file Limiter.h.

◆ reset()

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

Resets the internal state (delays, gain reduction). RT-Safe.

Definition at line 473 of file Limiter.h.

◆ resetGainComputer()

template<FloatType T>
void dspark::Limiter< T >::resetGainComputer ( )
inlineprotectednoexcept

Clears the gain computer to unity gain (history included).

Definition at line 1250 of file Limiter.h.

◆ resetHighAlignment()

template<FloatType T>
void dspark::Limiter< T >::resetHighAlignment ( )
inlineprotectednoexcept

Clears the alignment histories.

Definition at line 957 of file Limiter.h.

◆ restartGainComputerAt()

template<FloatType T>
void dspark::Limiter< T >::restartGainComputerAt ( double  g)
inlineprotectednoexcept

Fills the gain computer's histories with the gain g, so it continues from there with windows of another length (a change of precision).

Definition at line 1269 of file Limiter.h.

◆ restartHoldBlock()

template<FloatType T>
DSPARK_NOINLINE void dspark::Limiter< T >::restartHoldBlock ( int64_t  firstFrame)
inlineprotectednoexcept

Sliding minimum (van Herk / Gil-Werman, streaming form): the frames are cut into blocks of holdLen_. Once a block is complete its suffix minima are stored; the window ending at a frame of the next block is then the minimum of one stored suffix and the running prefix of that block. Branch-free per frame, one backward pass per block (amortised O(1)). This stores the suffix minima of the block starting at firstFrame and starts a new block at the following frame.

Definition at line 1236 of file Limiter.h.

◆ resumBoxes()

template<FloatType T>
DSPARK_NOINLINE void dspark::Limiter< T >::resumBoxes ( )
inlineprotectednoexcept

Recomputes both moving-average sums exactly from their histories.

Definition at line 1219 of file Limiter.h.

◆ seedHighTruePeakHistory()

template<FloatType T>
void dspark::Limiter< T >::seedHighTruePeakHistory ( )
inlineprotectednoexcept

Rebuilds the high-precision histories when that reading is switched on mid-stream: the last samples the delay lines hold run through the analyzer and the alignment (the peaks are discarded), so the first readings are not formed from stale history and the samples still waiting in the delay lines keep their sample peaks.

Definition at line 971 of file Limiter.h.

◆ seedPointHistory()

template<FloatType T>
void dspark::Limiter< T >::seedPointHistory ( bool  fromDelayLines)
inlineprotectednoexcept

Clears the interpolation histories, or refills them from the delay lines (which hold every recent input sample) when the points are switched on mid-stream.

Definition at line 1074 of file Limiter.h.

◆ seedTruePeakHistory()

template<FloatType T>
void dspark::Limiter< T >::seedTruePeakHistory ( )
inlineprotectednoexcept

Refills the estimator histories from the delay lines when true-peak detection is switched on mid-stream (they hold every recent input sample), so the first readings are not formed from stale history.

Definition at line 1004 of file Limiter.h.

◆ setAdaptiveRelease()

template<FloatType T>
void dspark::Limiter< T >::setAdaptiveRelease ( bool  enabled)
inlinenoexcept

Enables program-dependent adaptive release. RT-Safe. The release time grows with how long peaks have been asking for reduction: up to 3x after 200 ms of sustained limiting.

Definition at line 716 of file Limiter.h.

◆ setCeiling()

template<FloatType T>
void dspark::Limiter< T >::setCeiling ( T  dB)
inlinenoexcept

Sets the absolute output ceiling.

Parameters
dBCeiling in dBFS (e.g., -1.0 for streaming). RT-Safe. Non-finite values are ignored.

Definition at line 508 of file Limiter.h.

◆ setHold()

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

Sets how long the reduction is held after the last peak that asked for it, before the release starts. RT-Safe.

Without a hold the gain recovers between the crests of a low tone and dips again at the next one, and that ripple is distortion: a 50 Hz sine driven 6 dB over the ceiling (5 ms lookahead, 50 ms release) measures -56.8 dB THD+N with no hold and -149.6 dB with the default 10 ms, and 40 Hz goes from -47.4 to -149.7 dB (30 Hz: -38.4 to -84.7); the 60 Hz + 7 kHz intermodulation products fall from -62.4 to -74.2 dB. The price is loudness after isolated peaks: 0.21 dB of integrated loudness on a dense mix driven 12 dB over the ceiling.

Parameters
msHold in milliseconds, clamped to [0, 50] (default 10; 0 is the previous release-only behaviour). Non-finite values are ignored.

Definition at line 735 of file Limiter.h.

◆ setHoldMode()

template<FloatType T>
void dspark::Limiter< T >::setHoldMode ( HoldMode  mode)
inlinenoexcept

Selects the hold behaviour (see HoldMode). RT-Safe.

Parameters
modeHold mode; out-of-range values fall back to Deepest.

Definition at line 768 of file Limiter.h.

◆ setLookahead()

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

Sets the lookahead time dynamically.

Note
RT-Safe (atomic publication from any thread). It only adjusts read pointers up to the max memory allocated during prepare(); the read offset glides to the new value at one sample per sample. Non-finite values are ignored. getLatency() reflects the new value immediately. In true-peak mode the lookahead is at least 49 samples (standard precision) or 262 samples longer than set (high precision).
Parameters
msLookahead in milliseconds (clamped to 0.5 to 10.0 ms).

Definition at line 539 of file Limiter.h.

◆ setMaxLookahead()

template<FloatType T>
void dspark::Limiter< T >::setMaxLookahead ( T  ms)
inlinenoexcept

Keeps a latency for the lookahead to move inside.

With a maximum set, the audio always waits that long and getLatency() reports it, whatever setLookahead() says below it: the lookahead can then be automated without the host having to align anything again, the gain being held back by the difference. 0 (default) keeps no latency of its own: the latency is the lookahead, as before. A maximum under the lookahead changes nothing. In true-peak mode the maximum is raised like a lookahead of the same length. Set it before playback; a change during playback glides the audio to the new delay at one sample per sample.

State key "maxLookahead" (absent = 0).

Parameters
msLatency in milliseconds, 0 to 10 (0 turns it off). Non-finite values are ignored.

Definition at line 564 of file Limiter.h.

◆ setPrecision()

template<FloatType T>
void dspark::Limiter< T >::setPrecision ( Precision  precision)
inlinenoexcept

Selects how finely the gain computer works (see Precision). RT-Safe.

With High the requirement is read at eight points per sample (a 16-tap Kaiser-windowed sinc gives the seven between the samples) and the sliding minimum, hold, release and the two moving averages run at eight steps per sample; the gain heard is the one at each sample. The corners of the gain then fall where the crests are, not on the sample grid, which is what puts lines that are no harmonics of a tone into the output. A crest within 0.01 dB of the reduction held counts as keeping it down and restarts the hold (the readings of equal crests differ by their interpolation error; in Standard the comparison is exact, and which crest restarts the hold decides when the gain rises). Measured at 48 kHz on a tone 6 dB over a -6 dB ceiling, as the largest line that is no harmonic of it (Standard to High, release 20 and 100 ms, with the default 10 ms hold and without one): 100 Hz -62 to -108 dBc to -145 to -146, 1 kHz -75 to -85 to -117 to -126, 5 kHz -75 to -85 to -123 to -128; the level of the tone moves by 0.03 dB at most. The readings concern the sample 7 frames back: getLatency() is 7 samples longer and the lookahead stays all ramp. Every sample still leaves at or below the ceiling (the eight points include the sample itself). Only acts in sample-peak mode: with setTruePeak() on the true-peak reading feeds the gain computer, one step per sample. A stereo frame costs 105 to 159 ns against 10 to 17 in Standard (by compiler). Switching it during playback moves the latency like a lookahead change and the gain computer continues from the gain in effect. prepare() allocates the gain computer's histories for eight steps per sample whatever the precision (about 0.6 MB at 48 kHz with the 50 ms maximum hold).

State key "precision" (absent = Standard).

Parameters
precisionPrecision to use; out-of-range values fall back to Standard.

Definition at line 701 of file Limiter.h.

◆ setRelease()

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

Sets the base release time.

Parameters
msRelease time in milliseconds (floored to 1 ms). RT-Safe. Non-finite values are ignored.

Definition at line 521 of file Limiter.h.

◆ setSafetyClip()

template<FloatType T>
void dspark::Limiter< T >::setSafetyClip ( bool  enabled)
inlinenoexcept

Enables the post-limiter soft-knee safety clipper. RT-Safe.

Softens the region above -0.3 dBFS up to the ceiling; it only has an effect when the ceiling is set above -0.3 dBFS (below that, the brickwall clamp already keeps the output under the clipper threshold).

Definition at line 786 of file Limiter.h.

◆ setState()

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

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

Definition at line 847 of file Limiter.h.

◆ setTruePeak()

template<FloatType T>
void dspark::Limiter< T >::setTruePeak ( bool  enabled)
inlinenoexcept

Enables ISP true-peak detection. RT-Safe.

The sidechain reads the larger of a 64-tap 4x reconstruction refined to its local maxima and the ITU-R BS.1770 Annex 2 estimate (see the file description for the measured overshoot). A reading reaches 33 samples back, so the attack ramp shortens by 33 samples and the lookahead is raised to at least 49 samples (about 1 ms at 48 kHz); getLatency() reports it. The intermodulation of a limiter follows the length of that ramp: at the 2 ms default (96 samples, 63 of ramp) a 60 Hz + 7 kHz pair reads -59.1 dBc against -61.9 in sample-peak mode (double: -60.5 and -61.5), and setLookahead(2.7), which gives the ramp its 96 samples back for 129 of latency, -64.1 dBc (HoldMode EveryPeak at the default: -99.7 dBc). Detection costs about 12 ns per sample per channel more than sample-peak mode; processSample() runs it one sample at a time and is several times slower per sample than processBlock().

Parameters
enabledtrue to limit inter-sample peaks.

Definition at line 596 of file Limiter.h.

◆ setTruePeakPrecision()

template<FloatType T>
void dspark::Limiter< T >::setTruePeakPrecision ( TruePeakPrecision  precision)
inlinenoexcept

Selects the true-peak reading (see TruePeakPrecision). RT-Safe.

Only acts while setTruePeak() is on. With High, getLatency() is the lookahead plus 262 samples (5.5 ms more at 48 kHz) and the 49-sample floor of Standard does not apply. Every reading is held back until the slowest one of its sample has arrived, so none turns the gain down early: where both precisions read the same the output is as loud as in Standard or louder (a dense mix driven 12 dB over the ceiling, 0.05 dB), and where Standard reads low High is quieter by what Standard let through (white noise 0.25 dB); the file description gives the overshoot of both. The intermodulation is that of sample-peak mode at the same lookahead (60 Hz + 7 kHz at the default: -63.0 dBc, double -58.9, against -61.9 and -61.5). A frame costs 2.1 to 2.7 times what it costs in Standard, by compiler, and prepare() allocates its kernels (5 KB in float, 10 KB in double) and 6 KB (11 KB) of history per channel whether or not it is used. Switching it during playback moves the latency like a lookahead change; the reading's histories are rebuilt from the delay lines, so the output afterwards is that of a limiter that had it on all along.

Parameters
precisionReading to use; out-of-range values fall back to Standard.

Definition at line 641 of file Limiter.h.

◆ stepGain()

template<FloatType T>
void dspark::Limiter< T >::stepGain ( double  required,
bool  adaptive,
T  relMs 
)
inlineprotectednoexcept

One step of the gain computer for a required gain.

Definition at line 1305 of file Limiter.h.

◆ syncKeptLatency()

template<FloatType T>
void dspark::Limiter< T >::syncKeptLatency ( )
inlineprotectednoexcept

Engages the held-back gain when a latency longer than the lookahead is asked for, and lets go of it once the audio has glided back (audio thread). On engaging, the gain line starts full of the gain that is sounding and the audio glides out from the lookahead.

Definition at line 1132 of file Limiter.h.

◆ syncParameters()

template<FloatType T>
void dspark::Limiter< T >::syncParameters ( )
inlineprotectednoexcept

Definition at line 1373 of file Limiter.h.

◆ updateHoldSamples()

template<FloatType T>
void dspark::Limiter< T >::updateHoldSamples ( )
inlineprotectednoexcept

Definition at line 1402 of file Limiter.h.

◆ updateReleaseCoefficient()

template<FloatType T>
void dspark::Limiter< T >::updateReleaseCoefficient ( )
inlineprotectednoexcept

Definition at line 1408 of file Limiter.h.

Member Data Documentation

◆ adaptiveRelease_

template<FloatType T>
std::atomic<bool> dspark::Limiter< T >::adaptiveRelease_ { false }
protected

Definition at line 1444 of file Limiter.h.

◆ alignAnnex_

template<FloatType T>
T dspark::Limiter< T >::alignAnnex_[kAlignRecent] = {}
protected

Recent Annex 2 readings.

Definition at line 1510 of file Limiter.h.

◆ alignFast_

template<FloatType T>
T dspark::Limiter< T >::alignFast_[kAlignRing] = {}
protected

Fast readings per sample, waiting for the analyzer.

Definition at line 1511 of file Limiter.h.

◆ alignFrame_

template<FloatType T>
int dspark::Limiter< T >::alignFrame_ = 0
protected

Frame counter modulo kAlignRing.

Definition at line 1513 of file Limiter.h.

◆ alignSample_

template<FloatType T>
T dspark::Limiter< T >::alignSample_[kAlignRecent] = {}
protected

Recent sample peaks.

Definition at line 1509 of file Limiter.h.

◆ alignSlow_

template<FloatType T>
T dspark::Limiter< T >::alignSlow_[2] = {}
protected

Last two analyzer readings.

Definition at line 1512 of file Limiter.h.

◆ avgHist_

template<FloatType T>
std::vector<double> dspark::Limiter< T >::avgHist_
protected

First moving-average output history.

Definition at line 1489 of file Limiter.h.

◆ blockPos_

template<FloatType T>
int dspark::Limiter< T >::blockPos_ = 0
protected

Position inside the current hold block.

Definition at line 1492 of file Limiter.h.

◆ boxA_

template<FloatType T>
int dspark::Limiter< T >::boxA_ = 1
protected

Definition at line 1498 of file Limiter.h.

◆ boxB_

template<FloatType T>
int dspark::Limiter< T >::boxB_ = 1
protected

Definition at line 1499 of file Limiter.h.

◆ ceilingDb_

template<FloatType T>
std::atomic<T> dspark::Limiter< T >::ceilingDb_ { T(-0.3) }
protected

Definition at line 1438 of file Limiter.h.

◆ ceilingSmooth_

template<FloatType T>
SmoothedValue<T> dspark::Limiter< T >::ceilingSmooth_
protected

Definition at line 1447 of file Limiter.h.

◆ chunkAnnex_

template<FloatType T>
T dspark::Limiter< T >::chunkAnnex_[kChunk] = {}
protected

Definition at line 1516 of file Limiter.h.

◆ chunkCeiling_

template<FloatType T>
T dspark::Limiter< T >::chunkCeiling_[kChunk] = {}
protected

Definition at line 1519 of file Limiter.h.

◆ chunkDelay_

template<FloatType T>
int dspark::Limiter< T >::chunkDelay_[kChunk] = {}
protected

Delay of the audio per frame (the lookahead, or the latency kept).

Definition at line 1523 of file Limiter.h.

◆ chunkGain_

template<FloatType T>
T dspark::Limiter< T >::chunkGain_[kChunk] = {}
protected

Definition at line 1520 of file Limiter.h.

◆ chunkLook_

template<FloatType T>
int dspark::Limiter< T >::chunkLook_[kChunk] = {}
protected

Definition at line 1521 of file Limiter.h.

◆ chunkPeak_

template<FloatType T>
T dspark::Limiter< T >::chunkPeak_[kChunk] = {}
protected

Definition at line 1518 of file Limiter.h.

◆ chunkPoints_

template<FloatType T>
T dspark::Limiter< T >::chunkPoints_[kChunk][kSteps] = {}
protected

processBlock() points per frame (loudest channel).

Definition at line 1469 of file Limiter.h.

◆ chunkSlow_

template<FloatType T>
T dspark::Limiter< T >::chunkSlow_[kChunk] = {}
protected

Definition at line 1517 of file Limiter.h.

◆ counterHold_

template<FloatType T>
int dspark::Limiter< T >::counterHold_ = 0
protected

Hold-counter restart value (Deepest mode).

Definition at line 1455 of file Limiter.h.

◆ currentGain_

template<FloatType T>
T dspark::Limiter< T >::currentGain_ = T(1)
protected

Definition at line 1472 of file Limiter.h.

◆ delayLines_

template<FloatType T>
std::vector<RingBuffer<T> > dspark::Limiter< T >::delayLines_
protected

Definition at line 1539 of file Limiter.h.

◆ eHist_

template<FloatType T>
std::vector<double> dspark::Limiter< T >::eHist_
protected

Released envelope history.

Definition at line 1488 of file Limiter.h.

◆ envelope_

template<FloatType T>
double dspark::Limiter< T >::envelope_ = 1.0
protected

Definition at line 1495 of file Limiter.h.

◆ frame_

template<FloatType T>
int64_t dspark::Limiter< T >::frame_ = 0
protected

Definition at line 1494 of file Limiter.h.

◆ gainLine_

template<FloatType T>
RingBuffer<T> dspark::Limiter< T >::gainLine_
protected

Gains waiting for the audio they belong to.

Definition at line 1537 of file Limiter.h.

◆ gainSpan_

template<FloatType T>
int dspark::Limiter< T >::gainSpan_ = 0
protected

Length of the gain line.

Definition at line 1536 of file Limiter.h.

◆ histMask_

template<FloatType T>
int dspark::Limiter< T >::histMask_ = 0
protected

Moving-average histories (lookahead).

Definition at line 1485 of file Limiter.h.

◆ histSize_

template<FloatType T>
int dspark::Limiter< T >::histSize_ = 0
protected

Definition at line 1484 of file Limiter.h.

◆ holdHistSize_

template<FloatType T>
int dspark::Limiter< T >::holdHistSize_ = 0
protected

Definition at line 1486 of file Limiter.h.

◆ holdLeft_

template<FloatType T>
int dspark::Limiter< T >::holdLeft_ = 0
protected

Hold samples left before the release may act.

Definition at line 1456 of file Limiter.h.

◆ holdLen_

template<FloatType T>
int dspark::Limiter< T >::holdLen_ = 97
protected

Definition at line 1502 of file Limiter.h.

◆ holdMask_

template<FloatType T>
int dspark::Limiter< T >::holdMask_ = 0
protected

Required-gain history (lookahead + hold).

Definition at line 1487 of file Limiter.h.

◆ holdMode_

template<FloatType T>
std::atomic<int> dspark::Limiter< T >::holdMode_ { 0 }
protected

Definition at line 1458 of file Limiter.h.

◆ holdMs_

template<FloatType T>
std::atomic<T> dspark::Limiter< T >::holdMs_ { T(10) }
protected

Definition at line 1440 of file Limiter.h.

◆ holdSamples_

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

Hold length in samples.

Definition at line 1453 of file Limiter.h.

◆ holdSlack_

template<FloatType T>
double dspark::Limiter< T >::holdSlack_ = 1.0
protected

Factor of the held reduction a crest restarts the hold within.

Definition at line 1465 of file Limiter.h.

◆ invBoxA_

template<FloatType T>
double dspark::Limiter< T >::invBoxA_ = 1.0
protected

Definition at line 1500 of file Limiter.h.

◆ invBoxB_

template<FloatType T>
double dspark::Limiter< T >::invBoxB_ = 1.0
protected

Definition at line 1501 of file Limiter.h.

◆ invSampleRate_

template<FloatType T>
T dspark::Limiter< T >::invSampleRate_ = T(1.0 / 48000.0)
protected

Definition at line 1433 of file Limiter.h.

◆ ispApplied_

template<FloatType T>
bool dspark::Limiter< T >::ispApplied_ = false
protected

Detection mode the gain computer is sized for.

Definition at line 1460 of file Limiter.h.

◆ kAlignFast

template<FloatType T>
constexpr int dspark::Limiter< T >::kAlignFast = kTpHighDelay - (kAnnexWindow - 1)
staticconstexprprotected

Delay of the fast readings.

Definition at line 909 of file Limiter.h.

◆ kAlignRecent

template<FloatType T>
constexpr int dspark::Limiter< T >::kAlignRecent = 16
staticconstexprprotected

Power of two holding kAnnexWindow frames.

Definition at line 911 of file Limiter.h.

◆ kAlignRing

template<FloatType T>
constexpr int dspark::Limiter< T >::kAlignRing = 256
staticconstexprprotected

Power of two above kAlignFast.

Definition at line 910 of file Limiter.h.

◆ kAnnexWindow

template<FloatType T>
constexpr int dspark::Limiter< T >::kAnnexWindow = TruePeakDetector<T, 1>::getTaps()
staticconstexprprotected

Samples one Annex 2 reading is formed from.

Definition at line 908 of file Limiter.h.

◆ kChunk

template<FloatType T>
constexpr int dspark::Limiter< T >::kChunk = 128
staticconstexprprotected

Definition at line 874 of file Limiter.h.

◆ kept_

template<FloatType T>
bool dspark::Limiter< T >::kept_ = false
protected

The gain is being held back.

Definition at line 1535 of file Limiter.h.

◆ kHoldTolerance

template<FloatType T>
constexpr double dspark::Limiter< T >::kHoldTolerance = 1.0011520
staticconstexprprotected

0.01 dB: crests that close restart the hold (Precision::High).

Definition at line 1053 of file Limiter.h.

◆ kMaxChannels

template<FloatType T>
constexpr int dspark::Limiter< T >::kMaxChannels = 16
staticconstexprprotected

Definition at line 868 of file Limiter.h.

◆ kMaxHoldMs

template<FloatType T>
constexpr double dspark::Limiter< T >::kMaxHoldMs = 50.0
staticconstexprprotected

Definition at line 870 of file Limiter.h.

◆ kMaxLookaheadMs

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

Definition at line 869 of file Limiter.h.

◆ kPointBeta

template<FloatType T>
constexpr double dspark::Limiter< T >::kPointBeta = 9.0
staticconstexprprotected

Kaiser beta of the interpolation.

Definition at line 1052 of file Limiter.h.

◆ kPointDelay

template<FloatType T>
constexpr int dspark::Limiter< T >::kPointDelay = 7
staticconstexprprotected

Samples the points reach back.

Definition at line 1051 of file Limiter.h.

◆ kPointTaps

template<FloatType T>
constexpr int dspark::Limiter< T >::kPointTaps = 16
staticconstexprprotected

Taps of the interpolation.

Definition at line 1050 of file Limiter.h.

◆ kResumPeriod

template<FloatType T>
constexpr int dspark::Limiter< T >::kResumPeriod = 1 << 16
staticconstexprprotected

Definition at line 1483 of file Limiter.h.

◆ kSafetyClipCeiling

template<FloatType T>
constexpr T dspark::Limiter< T >::kSafetyClipCeiling = T(0.96605)
staticconstexprprotected

-0.3 dBFS

Definition at line 871 of file Limiter.h.

◆ kSteps

template<FloatType T>
constexpr int dspark::Limiter< T >::kSteps = 8
staticconstexprprotected

Steps of the gain computer per sample at Precision::High.

Definition at line 1049 of file Limiter.h.

◆ kTpDelay

template<FloatType T>
constexpr int dspark::Limiter< T >::kTpDelay = TpEstimator::getDelay()
staticconstexprprotected

Samples a reading reaches back.

Definition at line 889 of file Limiter.h.

◆ kTpHighDelay

template<FloatType T>
constexpr int dspark::Limiter< T >::kTpHighDelay = TpAnalyzer::getDelay() + 1
staticconstexprprotected

Samples a high-precision reading reaches back.

Definition at line 907 of file Limiter.h.

◆ kTpMinLookahead

template<FloatType T>
constexpr int dspark::Limiter< T >::kTpMinLookahead = kTpDelay + 16
staticconstexprprotected

Leaves at least a 16-sample ramp.

Definition at line 890 of file Limiter.h.

◆ lastCeilingDb_

template<FloatType T>
T dspark::Limiter< T >::lastCeilingDb_ = T(-0.3)
protected

Change detector for the ceiling pow skip.

Definition at line 1448 of file Limiter.h.

◆ lastHoldMode_

template<FloatType T>
int dspark::Limiter< T >::lastHoldMode_ = 0
protected

Applied HoldMode (0 Deepest, 1 EveryPeak).

Definition at line 1457 of file Limiter.h.

◆ lastHoldMs_

template<FloatType T>
T dspark::Limiter< T >::lastHoldMs_ = T(-1)
protected

Definition at line 1452 of file Limiter.h.

◆ lastReleaseMs_

template<FloatType T>
T dspark::Limiter< T >::lastReleaseMs_ = T(-1)
protected

Definition at line 1451 of file Limiter.h.

◆ latencyCurrent_

template<FloatType T>
T dspark::Limiter< T >::latencyCurrent_ = T(96)
protected

Its smoothed value while kept.

Definition at line 1534 of file Limiter.h.

◆ latencySamples_

template<FloatType T>
int dspark::Limiter< T >::latencySamples_ = 96
protected

Delay the audio is asked to have (audio thread).

Definition at line 1533 of file Limiter.h.

◆ limitingDuration_

template<FloatType T>
int dspark::Limiter< T >::limitingDuration_ = 0
protected

Definition at line 1478 of file Limiter.h.

◆ lookaheadCurrent_

template<FloatType T>
T dspark::Limiter< T >::lookaheadCurrent_ = T(96)
protected

Smoothed read offset (glides on live changes).

Definition at line 1479 of file Limiter.h.

◆ lookaheadDirty_

template<FloatType T>
std::atomic<bool> dspark::Limiter< T >::lookaheadDirty_ { false }
protected

Definition at line 1442 of file Limiter.h.

◆ lookaheadMs_

template<FloatType T>
std::atomic<T> dspark::Limiter< T >::lookaheadMs_ { T(2) }
protected

Definition at line 1441 of file Limiter.h.

◆ lookaheadSamples_

template<FloatType T>
int dspark::Limiter< T >::lookaheadSamples_ = 96
protected

Audio-side lookahead (consumed from lookaheadMs_).

Definition at line 1435 of file Limiter.h.

◆ maxHoldSamples_

template<FloatType T>
int dspark::Limiter< T >::maxHoldSamples_ = 2400
protected

Hold length of kMaxHoldMs.

Definition at line 1454 of file Limiter.h.

◆ maxLimitSamples_

template<FloatType T>
int dspark::Limiter< T >::maxLimitSamples_ = 96000
protected

Adaptive-release duration cap (2 s).

Definition at line 1436 of file Limiter.h.

◆ maxLookaheadMs_

template<FloatType T>
std::atomic<T> dspark::Limiter< T >::maxLookaheadMs_ { T(0) }
protected

Latency kept (0: none).

Definition at line 1532 of file Limiter.h.

◆ numChannels_

template<FloatType T>
int dspark::Limiter< T >::numChannels_ = 2
protected

Definition at line 1434 of file Limiter.h.

◆ pendingAnnex_

template<FloatType T>
T dspark::Limiter< T >::pendingAnnex_ = T(0)
protected

The same for their Annex 2 readings (high precision).

Definition at line 1505 of file Limiter.h.

◆ pendingPeak_

template<FloatType T>
T dspark::Limiter< T >::pendingPeak_ = T(0)
protected

Other channels' peaks for the next processSample() frame.

Definition at line 1504 of file Limiter.h.

◆ pendingPoints_

template<FloatType T>
T dspark::Limiter< T >::pendingPoints_[kSteps] = {}
protected

Other channels' points for the next processSample() frame.

Definition at line 1470 of file Limiter.h.

◆ pendingSlow_

template<FloatType T>
T dspark::Limiter< T >::pendingSlow_ = T(0)
protected

The same for their analyzer readings (high precision).

Definition at line 1506 of file Limiter.h.

◆ pointAt_

template<FloatType T>
int dspark::Limiter< T >::pointAt_[kMaxChannels] = {}
protected

Next write position in it.

Definition at line 1468 of file Limiter.h.

◆ pointHist_

template<FloatType T>
T dspark::Limiter< T >::pointHist_[kMaxChannels][2 *kPointTaps] = {}
protected

Mirrored interpolation history per channel.

Definition at line 1467 of file Limiter.h.

◆ pointPhase_

template<FloatType T>
T dspark::Limiter< T >::pointPhase_[kSteps - 1][kPointTaps] = {}
protected

Interpolation phases (prepare()).

Definition at line 1466 of file Limiter.h.

◆ pointsApplied_

template<FloatType T>
bool dspark::Limiter< T >::pointsApplied_ = false
protected

Readings at eight points per sample applied (sample-peak mode).

Definition at line 1463 of file Limiter.h.

◆ precision_

template<FloatType T>
std::atomic<int> dspark::Limiter< T >::precision_ { 0 }
protected

Published Precision (0 Standard, 1 High).

Definition at line 1462 of file Limiter.h.

◆ prefixMin_

template<FloatType T>
double dspark::Limiter< T >::prefixMin_ = 1.0
protected

Running minimum of the current hold block.

Definition at line 1493 of file Limiter.h.

◆ prepared_

template<FloatType T>
bool dspark::Limiter< T >::prepared_ = false
protected

Definition at line 1431 of file Limiter.h.

◆ publishedGain_

template<FloatType T>
std::atomic<T> dspark::Limiter< T >::publishedGain_ { T(1) }
protected

Cross-thread metering readout of currentGain_: published once per processBlock() and once per processSample() call. processSample() is the per-sample entry point, so there the store does run once per sample – what it never does is sit inside processBlock()'s own sample loop.

Definition at line 1477 of file Limiter.h.

◆ releaseCoeff_

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

Definition at line 1450 of file Limiter.h.

◆ releaseMs_

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

Definition at line 1439 of file Limiter.h.

◆ rHist_

template<FloatType T>
std::vector<double> dspark::Limiter< T >::rHist_
protected

Required-gain history.

Definition at line 1490 of file Limiter.h.

◆ safetyClipEnabled_

template<FloatType T>
std::atomic<bool> dspark::Limiter< T >::safetyClipEnabled_ { false }
protected

Definition at line 1445 of file Limiter.h.

◆ sampleCeiling_

template<FloatType T>
T dspark::Limiter< T >::sampleCeiling_ = T(0.96605)
protected

Definition at line 1526 of file Limiter.h.

◆ sampleDelayNow_

template<FloatType T>
int dspark::Limiter< T >::sampleDelayNow_ = 96
protected

Delay of the audio for the frame.

Definition at line 1528 of file Limiter.h.

◆ sampleGainNow_

template<FloatType T>
T dspark::Limiter< T >::sampleGainNow_ = T(1)
protected

Gain heard in the frame.

Definition at line 1529 of file Limiter.h.

◆ sampleLookNow_

template<FloatType T>
int dspark::Limiter< T >::sampleLookNow_ = 96
protected

Definition at line 1527 of file Limiter.h.

◆ sampleRate_

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

Definition at line 1432 of file Limiter.h.

◆ sinceResum_

template<FloatType T>
int dspark::Limiter< T >::sinceResum_ = 0
protected

Definition at line 1503 of file Limiter.h.

◆ stepsPerSample_

template<FloatType T>
int dspark::Limiter< T >::stepsPerSample_ = 1
protected

Steps of the gain computer per sample (1 or kSteps).

Definition at line 1464 of file Limiter.h.

◆ sufMin_

template<FloatType T>
std::vector<double> dspark::Limiter< T >::sufMin_
protected

Suffix minima of the last complete hold block (+1 empty).

Definition at line 1491 of file Limiter.h.

◆ sum1_

template<FloatType T>
double dspark::Limiter< T >::sum1_ = 1.0
protected

Definition at line 1496 of file Limiter.h.

◆ sum2_

template<FloatType T>
double dspark::Limiter< T >::sum2_ = 1.0
protected

Definition at line 1497 of file Limiter.h.

◆ tpAnalyzer_

template<FloatType T>
std::unique_ptr<TpAnalyzer> dspark::Limiter< T >::tpAnalyzer_
protected

High-precision kernels and scratch (prepare()).

Definition at line 1021 of file Limiter.h.

◆ tpChannels_

template<FloatType T>
std::vector<typename TpEstimator::Channel> dspark::Limiter< T >::tpChannels_
protected

Per channel history.

Definition at line 1020 of file Limiter.h.

◆ tpEstimator_

template<FloatType T>
TpEstimator dspark::Limiter< T >::tpEstimator_
protected

Kernel and phase scratch.

Definition at line 1019 of file Limiter.h.

◆ tpHighApplied_

template<FloatType T>
bool dspark::Limiter< T >::tpHighApplied_ = false
protected

High-precision reading applied (implies ispApplied_).

Definition at line 1461 of file Limiter.h.

◆ tpHighChannels_

template<FloatType T>
std::vector<typename TpAnalyzer::Channel> dspark::Limiter< T >::tpHighChannels_
protected

Per channel history of the high-precision reading.

Definition at line 1022 of file Limiter.h.

◆ truePeakEnabled_

template<FloatType T>
std::atomic<bool> dspark::Limiter< T >::truePeakEnabled_ { false }
protected

Definition at line 1443 of file Limiter.h.

◆ truePeakPrecision_

template<FloatType T>
std::atomic<int> dspark::Limiter< T >::truePeakPrecision_ { 0 }
protected

Published TruePeakPrecision (0 Standard, 1 High).

Definition at line 1459 of file Limiter.h.


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