DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::LevelFollower< T, MaxChannels > Class Template Reference

Per-channel peak and RMS envelope follower with lock-free readout. More...

#include <LevelFollower.h>

Public Member Functions

void prepare (const AudioSpec &spec) noexcept
 Prepares the follower for the given audio environment.
 
void setAttackMs (float ms) noexcept
 Sets the attack time for peak metering.
 
void setReleaseMs (float ms) noexcept
 Sets the release time for peak metering.
 
void setRmsWindowMs (float ms) noexcept
 Sets the integration time constant for RMS metering.
 
getAttackMs () const noexcept
 Returns the peak attack time in milliseconds.
 
getReleaseMs () const noexcept
 Returns the peak release time in milliseconds.
 
getRmsWindowMs () const noexcept
 Returns the RMS integration time constant in milliseconds.
 
void reset () noexcept
 Resets all envelope states to zero safely.
 
void process (AudioBufferView< const T > buffer) noexcept
 Processes a block of audio and updates level tracking.
 
getPeakLevel (int channel) const noexcept
 Returns the current peak level for the given channel safely.
 
getRmsLevel (int channel) const noexcept
 Returns the current RMS level for the given channel safely.
 
getPeakLevelDb (int channel) const noexcept
 Returns the current peak level in decibels.
 
getRmsLevelDb (int channel) const noexcept
 Returns the current RMS level in decibels (optimized).
 

Detailed Description

template<FloatType T, int MaxChannels = 16>
class dspark::LevelFollower< T, MaxChannels >

Per-channel peak and RMS envelope follower with lock-free readout.

One-pole envelope followers with a branchless attack/release selector in the hot loop (avoids branch mispredictions on noisy program material; the per-sample recursion itself is inherently serial). Channels beyond the prepared count (or beyond MaxChannels) are not metered. A non-finite input sample would stick in the recursions forever, so the published state is sanitized once per block: the meter recovers on the next block instead of reporting NaN until reset().

Template Parameters
TSample type (float or double).
MaxChannelsMaximum number of channels supported.

Definition at line 74 of file LevelFollower.h.

Member Function Documentation

◆ getAttackMs()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getAttackMs ( ) const
inlinenoexcept

Returns the peak attack time in milliseconds.

Definition at line 142 of file LevelFollower.h.

◆ getPeakLevel()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getPeakLevel ( int  channel) const
inlinenoexcept

Returns the current peak level for the given channel safely.

Parameters
channelChannel index (0-based; out-of-range returns 0).
Returns
Peak level (linear, >= 0).

Definition at line 235 of file LevelFollower.h.

◆ getPeakLevelDb()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getPeakLevelDb ( int  channel) const
inlinenoexcept

Returns the current peak level in decibels.

Parameters
channelChannel index (0-based).
Returns
Peak level in dB (floored at -100).

Definition at line 258 of file LevelFollower.h.

◆ getReleaseMs()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getReleaseMs ( ) const
inlinenoexcept

Returns the peak release time in milliseconds.

Definition at line 148 of file LevelFollower.h.

◆ getRmsLevel()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getRmsLevel ( int  channel) const
inlinenoexcept

Returns the current RMS level for the given channel safely.

Parameters
channelChannel index (0-based; out-of-range returns 0).
Returns
RMS level (linear, >= 0).

Definition at line 246 of file LevelFollower.h.

◆ getRmsLevelDb()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getRmsLevelDb ( int  channel) const
inlinenoexcept

Returns the current RMS level in decibels (optimized).

Parameters
channelChannel index (0-based).
Returns
RMS level in dB (floored at -100).

Definition at line 268 of file LevelFollower.h.

◆ getRmsWindowMs()

template<FloatType T, int MaxChannels = 16>
T dspark::LevelFollower< T, MaxChannels >::getRmsWindowMs ( ) const
inlinenoexcept

Returns the RMS integration time constant in milliseconds.

Definition at line 154 of file LevelFollower.h.

◆ prepare()

template<FloatType T, int MaxChannels = 16>
void dspark::LevelFollower< T, MaxChannels >::prepare ( const AudioSpec spec)
inlinenoexcept

Prepares the follower for the given audio environment.

Recomputes coefficients for the new sample rate and resets all envelope states. An invalid spec (non-positive or non-finite fields) is ignored, keeping the previous state.

Parameters
specAudio specification (sample rate, block size, channels).

Definition at line 86 of file LevelFollower.h.

◆ process()

template<FloatType T, int MaxChannels = 16>
void dspark::LevelFollower< T, MaxChannels >::process ( AudioBufferView< const T >  buffer)
inlinenoexcept

Processes a block of audio and updates level tracking.

No-op before prepare(). Channels beyond the prepared count are not metered.

Parameters
bufferRead-only audio buffer view.

Definition at line 177 of file LevelFollower.h.

◆ reset()

template<FloatType T, int MaxChannels = 16>
void dspark::LevelFollower< T, MaxChannels >::reset ( )
inlinenoexcept

Resets all envelope states to zero safely.

Definition at line 160 of file LevelFollower.h.

◆ setAttackMs()

template<FloatType T, int MaxChannels = 16>
void dspark::LevelFollower< T, MaxChannels >::setAttackMs ( float  ms)
inlinenoexcept

Sets the attack time for peak metering.

Parameters
msAttack time in milliseconds (floored to 0.001; non-finite values are ignored).

Definition at line 102 of file LevelFollower.h.

◆ setReleaseMs()

template<FloatType T, int MaxChannels = 16>
void dspark::LevelFollower< T, MaxChannels >::setReleaseMs ( float  ms)
inlinenoexcept

Sets the release time for peak metering.

Parameters
msRelease time in milliseconds (floored to 0.001; non-finite values are ignored).

Definition at line 115 of file LevelFollower.h.

◆ setRmsWindowMs()

template<FloatType T, int MaxChannels = 16>
void dspark::LevelFollower< T, MaxChannels >::setRmsWindowMs ( float  ms)
inlinenoexcept

Sets the integration time constant for RMS metering.

The RMS detector is a one-pole exponential integrator over the squared signal; this is its time constant (63% settling on a level step), not the length of a rectangular window.

Parameters
msTime constant in milliseconds (floored to 0.001; non-finite values are ignored).

Definition at line 133 of file LevelFollower.h.


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