|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
High-performance brickwall lookahead limiter. More...
#include <Limiter.h>

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 | setTruePeak (bool enabled) noexcept |
| Enables 4x oversampled ISP true-peak detection. RT-Safe. | |
| void | setAdaptiveRelease (bool enabled) noexcept |
| Enables program-dependent adaptive release. RT-Safe. | |
| 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; unsynchronized read). | |
| 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 | |
| int | lookaheadSamplesFor (T ms) const noexcept |
| void | applyLookaheadTarget () noexcept |
| void | syncParameters () noexcept |
| void | updateReleaseCoefficient () noexcept |
| void | smoothGain (T targetGain, bool adaptive, T relMs) noexcept |
| T | applySafetyClipper (T out, T clipCeil) const noexcept |
Protected Attributes | |
| TruePeakDetector< T, kMaxChannels > | truePeak_ |
| 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 > | 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 | attackCoeff_ = T(1) |
| T | lastReleaseMs_ = T(-1) |
| T | currentGain_ = T(1) |
| int | limitingDuration_ = 0 |
| T | lookaheadCurrent_ = T(96) |
| Smoothed read offset (glides on live changes). | |
| T | heldPeak_ = T(0) |
| int | peakHoldCounter_ = 0 |
| T | sampleCeiling_ = T(0.96605) |
| int | sampleLookNow_ = 96 |
| std::vector< RingBuffer< T > > | delayLines_ |
Static Protected Attributes | |
| static constexpr int | kMaxChannels = 16 |
| static constexpr double | kMaxLookaheadMs = 10.0 |
| static constexpr T | kSafetyClipCeiling = T(0.96605) |
| -0.3 dBFS | |
High-performance brickwall lookahead limiter.
| T | Sample type (float or double). |
|
default |
|
inlineprotectednoexcept |
|
inlineprotectednoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Reports the processing latency (the lookahead) in samples.
Derived from the published lookahead parameter, so it is correct immediately after setLookahead() from any thread (the audio thread may consume the change one block later; the glide covers the transition).
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineprotectednoexcept |
Lookahead in samples for a given ms parameter (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).
|
inline |
|
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.
| sampleRate | Sample rate in Hz (must be > 0). |
| numChannels | Number of channels to process (clamped to [1, 16]). |
| initialLookaheadMs | Optional lookahead override in ms; any non-positive or non-finite value (the default) keeps the current lookahead parameter. |
|
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).
| buffer | Audio buffer view. |
|
inlinenoexcept |
Processes a single sample of one channel.
The shared state (ceiling smoother, lookahead glide, peak hold decay and gain envelope) 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(). Any channel's peak can raise the shared peak hold, but only channel 0 detects into the envelope; for properly linked multi-channel limiting prefer processBlock().
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Sets the lookahead time dynamically.
| ms | Lookahead in milliseconds (clamped to 0.5 to 10.0 ms). |
|
inlinenoexcept |
|
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).
|
inline |
|
inlinenoexcept |
|
inlineprotectednoexcept |
|
inlineprotectednoexcept |
|
inlineprotectednoexcept |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |