Class thl::dsp::dynamics::LookaheadLimiterImpl#
-
class LookaheadLimiterImpl : public thl::dsp::BaseProcessor#
Inheritance diagram for thl::dsp::dynamics::LookaheadLimiterImpl:
Collaboration diagram for thl::dsp::dynamics::LookaheadLimiterImpl:
A brickwall lookahead limiter: no output sample above the ceiling, without clipping.
For every key sample the gain that keeps it at the ceiling, min(1, ceiling / peak), goes through a minimum over the lookahead (L samples: the gain is down before a peak arrives and held while it passes), a release in dB, and a moving average over L (the gain ramps down linearly instead of jumping). The audio is delayed by L - 1, which puts every peak where the average has fully reached its gain: the output stays at the ceiling exactly, a hard clip at the ceiling only catches rounding (and the moments after a lookahead change).
True peak: the key is interpolated 4x (a 97-tap Kaiser-windowed sinc), so the peaks between the samples count too (ITU-R BS.1770’s true peak). Measured 16x, the output stays at the ceiling for content up to 0.44 fs (21 kHz at 48 kHz); only content right at Nyquist (white noise) overshoots, by about 1 dB. Adds k_true_peak_delay samples of latency.
Link: Linked (the default; StereoLink::Average counts as linked) gives all channels the loudest’s gain, DualMono each its own.
Input gain drives into the limiter (and glides over k_ramp_seconds).
latency_samples() is L - 1 (+ k_true_peak_delay); max_latency_samples() its maximum.
A derived class gives every Parameter through get_parameter_float(), read at the start of every process() call at
modulation_offset; a NaN becomes the default (k_parameter_ranges), the rest is clamped. A lookahead change restarts the gain’s averaging (the audio delay crossfades); a link change hands the gain over. Up to k_max_channels channels; further ones pass delayed and driven by the input gain, unlimited.Threads: prepare() allocates (audio stopped); process() and reset() are real-time safe.
Public Functions
-
virtual void prepare(const double &sample_rate, const size_t &samples_per_block, const size_t &num_channels) override#
-
virtual void process(thl::core::BufferView buffer, uint32_t modulation_offset = 0) override#
-
virtual void reset() override#
Clears the lookahead, the interpolator and the gain (none held).
-
inline float gain_reduction_db() const#
The last block’s deepest gain reduction in dB (<= 0).
-
inline float input_peak_db() const#
The last block’s input peak in dBFS, after the input gain.
-
inline float output_peak_db() const#
The last block’s output sample peak in dBFS.
Public Static Attributes
-
static constexpr size_t k_max_channels = 16#
-
static constexpr float k_max_lookahead_ms = 10.0f#
-
static constexpr double k_ramp_seconds = 0.02#
-
static constexpr size_t k_true_peak_factor = 4#
-
static constexpr size_t k_true_peak_taps_per_phase = 25#
-
static constexpr uint32_t k_true_peak_delay = static_cast<uint32_t>((k_true_peak_taps_per_phase - 1) / 2)#
The interpolator’s group delay.
Protected Types
Protected Functions
Protected Static Attributes
- static constexpr std::array< utils::ParameterRange, NumParameters > k_parameter_ranges {{{.m_default = 0.0f, .m_min = -24.0f, .m_max = 24.0f},{.m_default = -1.0f, .m_min = -30.0f, .m_max = 0.0f},{.m_default = 2.0f, .m_min = 0.0f, .m_max =k_max_lookahead_ms},{.m_default = 100.0f, .m_min = 0.0f, .m_max = 2000.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 1.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 2.0f},}}
Every parameter’s default and range (Link: StereoLink as a float), e.g.
for a host’s parameter definitions. A NaN reads as the default, the rest is clamped.