DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
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.
 
T getAttackMs () const noexcept
 Returns the peak attack time in milliseconds.
 
T getReleaseMs () const noexcept
 Returns the peak release time in milliseconds.
 
T getRmsWindowMs () const noexcept
 Returns the RMS integration time constant in milliseconds.
 
void setVuEnabled (bool on) noexcept
 Runs the volume-unit needle too (see the file notes; off by default, when it costs nothing). Setup or control thread.
 
bool isVuEnabled () const noexcept
 
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.
 
T getVuLevel (int channel) const noexcept
 The volume-unit needle (setVuEnabled()), linear: a steady sine reads its RMS.
 
T getVuLevelDb (int channel) const noexcept
 The needle in decibels (floored at -100).
 
T getPeakLevel (int channel) const noexcept
 Returns the current peak level for the given channel safely.
 
T getRmsLevel (int channel) const noexcept
 Returns the current RMS level for the given channel safely.
 
T getPeakLevelDb (int channel) const noexcept
 Returns the current peak level in decibels.
 
T 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 82 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 153 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 293 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 316 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 159 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 304 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 326 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 165 of file LevelFollower.h.

◆ getVuLevel()

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

The volume-unit needle (setVuEnabled()), linear: a steady sine reads its RMS.

Parameters
channelChannel index (0-based; out-of-range returns 0).

Definition at line 279 of file LevelFollower.h.

◆ getVuLevelDb()

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

The needle in decibels (floored at -100).

Definition at line 286 of file LevelFollower.h.

◆ isVuEnabled()

template<FloatType T, int MaxChannels = 16>
bool dspark::LevelFollower< T, MaxChannels >::isVuEnabled ( ) const
inlinenoexcept
Returns
Whether the needle runs.

Definition at line 176 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 94 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 198 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 179 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 113 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 126 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 144 of file LevelFollower.h.

◆ setVuEnabled()

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

Runs the volume-unit needle too (see the file notes; off by default, when it costs nothing). Setup or control thread.

Definition at line 174 of file LevelFollower.h.


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