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

Real-time safe EBU R128 loudness meter. More...

#include <LoudnessMeter.h>

Public Member Functions

void prepare (double sampleRate, int numChannels=2) noexcept
 Prepares the meter and pre-calculates filter coefficients.
 
void prepare (const AudioSpec &spec) noexcept
 Unified API preparation.
 
void processBlock (AudioBufferView< const T > buffer) noexcept
 Processes a non-interleaved buffer view (read-only).
 
void process (const T *data, int numSamples) noexcept
 Processes a mono block of samples.
 
void process (const T *left, const T *right, int numSamples) noexcept
 Processes a stereo block of samples.
 
getMomentaryLUFS () const noexcept
 Reads the Momentary loudness (400 ms window).
 
getShortTermLUFS () const noexcept
 Reads the Short-term loudness (3 second window).
 
getIntegratedLUFS () const noexcept
 Computes the Integrated loudness using standard two-pass gating.
 
getTruePeakDb () const noexcept
 Returns the maximum true peak observed since the last reset.
 
getLoudnessRange () const noexcept
 Computes the EBU R128 Loudness Range (EBU Tech 3342).
 
void reset () noexcept
 Clears all measurements and resets filters.
 

Detailed Description

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

Real-time safe EBU R128 loudness meter.

Implements Momentary (400ms), Short-Term (3s), and Integrated (gated) measurements. Utilizes a constant-memory histogram for infinite integrated loudness tracking without memory allocation or O(N) CPU scaling, ensuring strict RT compliance.

All readout methods (getMomentaryLUFS, etc.) are lock-free and thread-safe to be called from GUI threads while the audio thread is processing.

Template Parameters
TSample type (float or double).

Definition at line 56 of file LoudnessMeter.h.

Member Function Documentation

◆ getIntegratedLUFS()

template<FloatType T>
T dspark::LoudnessMeter< T >::getIntegratedLUFS ( ) const
inlinenoexcept

Computes the Integrated loudness using standard two-pass gating.

Note
O(bins) with a constant bin count (no per-block cost growth). Safe to call from any thread.
Returns
Loudness in LUFS (minimum -100.0).

Definition at line 199 of file LoudnessMeter.h.

◆ getLoudnessRange()

template<FloatType T>
T dspark::LoudnessMeter< T >::getLoudnessRange ( ) const
inlinenoexcept

Computes the EBU R128 Loudness Range (EBU Tech 3342).

Short-term (3 s) loudness sampled once per second, gated at -70 LUFS absolute and -20 LU relative; LRA is the spread between the 10th and 95th percentiles. O(bins) and real-time safe like the integrated gate.

Returns
Loudness range in LU (0 if not enough material yet).

Definition at line 263 of file LoudnessMeter.h.

◆ getMomentaryLUFS()

template<FloatType T>
T dspark::LoudnessMeter< T >::getMomentaryLUFS ( ) const
inlinenoexcept

Reads the Momentary loudness (400 ms window).

Returns
Loudness in LUFS (minimum -100.0).

Definition at line 179 of file LoudnessMeter.h.

◆ getShortTermLUFS()

template<FloatType T>
T dspark::LoudnessMeter< T >::getShortTermLUFS ( ) const
inlinenoexcept

Reads the Short-term loudness (3 second window).

Returns
Loudness in LUFS (minimum -100.0).

Definition at line 188 of file LoudnessMeter.h.

◆ getTruePeakDb()

template<FloatType T>
T dspark::LoudnessMeter< T >::getTruePeakDb ( ) const
inlinenoexcept

Returns the maximum true peak observed since the last reset.

Returns
True peak in dBTP (ITU-R BS.1770-4, 4x oversampled estimate).

Definition at line 249 of file LoudnessMeter.h.

◆ prepare() [1/2]

template<FloatType T>
void dspark::LoudnessMeter< T >::prepare ( const AudioSpec spec)
inlinenoexcept

Unified API preparation.

Definition at line 88 of file LoudnessMeter.h.

◆ prepare() [2/2]

template<FloatType T>
void dspark::LoudnessMeter< T >::prepare ( double  sampleRate,
int  numChannels = 2 
)
inlinenoexcept

Prepares the meter and pre-calculates filter coefficients.

A non-finite or non-positive sample rate is ignored (conservative no-op keeping the previous state).

Parameters
sampleRateSample rate in Hz (must be > 0 and finite).
numChannelsAccepted for API symmetry; the channel layout is taken from each processed buffer (up to 2 channels are measured).

Definition at line 70 of file LoudnessMeter.h.

◆ process() [1/2]

template<FloatType T>
void dspark::LoudnessMeter< T >::process ( const T *  data,
int  numSamples 
)
inlinenoexcept

Processes a mono block of samples.

Parameters
dataPointer to mono audio data.
numSamplesNumber of samples to process.

Definition at line 116 of file LoudnessMeter.h.

◆ process() [2/2]

template<FloatType T>
void dspark::LoudnessMeter< T >::process ( const T *  left,
const T *  right,
int  numSamples 
)
inlinenoexcept

Processes a stereo block of samples.

Parameters
leftPointer to left channel data.
rightPointer to right channel data.
numSamplesNumber of samples per channel.

Definition at line 148 of file LoudnessMeter.h.

◆ processBlock()

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

Processes a non-interleaved buffer view (read-only).

The first two channels are measured; additional channels are ignored (multichannel spatial weighting is not implemented).

Parameters
bufferAudioBufferView to analyze.

Definition at line 101 of file LoudnessMeter.h.

◆ reset()

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

Clears all measurements and resets filters.

Call from the stream owner or a setup thread, not concurrently with the process calls: the accumulators and filter states are plain writer-owned members.

Definition at line 319 of file LoudnessMeter.h.


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