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

Block-adaptive automatic gain compensation with SIMD-friendly linear interpolation. More...

#include <AutoGain.h>

Public Member Functions

void prepare (const AudioSpec &spec) noexcept
 Prepares the auto-gain processor.
 
void pushReference (AudioBufferView< T > buffer) noexcept
 Snapshots the input level. Must be called BEFORE processing.
 
void compensate (AudioBufferView< T > buffer) noexcept
 Measures output level and applies smoothed gain compensation. Must be called AFTER processing.
 
void reset () noexcept
 Hard resets the internal state to avoid feedback loops or stale measurements.
 
getCompensationDb () const noexcept
 Returns the current internal compensation in dB. Useful for UI metering.
 
void setMaxCompensation (T dB) noexcept
 Thread-safe assignment of the maximum allowed compensation limit.
 
void setSmoothingTime (T ms) noexcept
 Sets the smoothing time constant.
 
getMaxCompensation () const noexcept
 
getSmoothingTime () const noexcept
 
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).
 

Detailed Description

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

Block-adaptive automatic gain compensation with SIMD-friendly linear interpolation.

Levels are measured across the channels passed to prepare(); channels beyond those are neither measured nor compensated (pass-through), and both calls are no-ops before prepare().

Note on silence: when BOTH the reference and the output are below -90 dB the compensation target is held at 0 dB (nothing meaningful to match). If only the reference is silent while the effect produces output (e.g. a reverb tail), the match pulls the output down, bounded by the max compensation clamp.

Template Parameters
TSample type (float or double). Must be lock-free atomic compatible if modified concurrently.

Definition at line 63 of file AutoGain.h.

Member Function Documentation

◆ compensate()

template<FloatType T>
void dspark::AutoGain< T >::compensate ( AudioBufferView< T >  buffer)
inlinenoexcept

Measures output level and applies smoothed gain compensation. Must be called AFTER processing.

Parameters
bufferProcessed audio (modified in-place).

Definition at line 108 of file AutoGain.h.

◆ getCompensationDb()

template<FloatType T>
T dspark::AutoGain< T >::getCompensationDb ( ) const
inlinenoexcept

Returns the current internal compensation in dB. Useful for UI metering.

Returns
Current gain offset in decibels.

Definition at line 170 of file AutoGain.h.

◆ getMaxCompensation()

template<FloatType T>
T dspark::AutoGain< T >::getMaxCompensation ( ) const
inlinenoexcept
Returns
The maximum allowed compensation in dB (positive).

Definition at line 197 of file AutoGain.h.

◆ getSmoothingTime()

template<FloatType T>
T dspark::AutoGain< T >::getSmoothingTime ( ) const
inlinenoexcept
Returns
The smoothing time constant in milliseconds.

Definition at line 203 of file AutoGain.h.

◆ getState()

template<FloatType T>
std::vector< uint8_t > dspark::AutoGain< T >::getState ( ) const
inline

Serializes the parameter state (setup/UI threads; allocates).

Definition at line 209 of file AutoGain.h.

◆ prepare()

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

Prepares the auto-gain processor.

An invalid spec (non-positive or non-finite fields) is a no-op that keeps the previous state.

Parameters
specAudio environment specification containing sample rate and channels.

Definition at line 78 of file AutoGain.h.

◆ pushReference()

template<FloatType T>
void dspark::AutoGain< T >::pushReference ( AudioBufferView< T >  buffer)
inlinenoexcept

Snapshots the input level. Must be called BEFORE processing.

An empty view (or one with no prepared channels) keeps the previous reference instead of degrading it.

Parameters
bufferInput audio (read-only measurement).

Definition at line 95 of file AutoGain.h.

◆ reset()

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

Hard resets the internal state to avoid feedback loops or stale measurements.

Definition at line 160 of file AutoGain.h.

◆ setMaxCompensation()

template<FloatType T>
void dspark::AutoGain< T >::setMaxCompensation ( dB)
inlinenoexcept

Thread-safe assignment of the maximum allowed compensation limit.

Parameters
dBMax gain change in decibels (absolute value used symmetrically). Non-finite values are ignored (a NaN would silently disable the clamp).

Definition at line 177 of file AutoGain.h.

◆ setSmoothingTime()

template<FloatType T>
void dspark::AutoGain< T >::setSmoothingTime ( ms)
inlinenoexcept

Sets the smoothing time constant.

Parameters
msSmoothing time in milliseconds, floored at 1 ms. Non-finite values are ignored (a NaN would poison the compensation state permanently).

Definition at line 189 of file AutoGain.h.

◆ setState()

template<FloatType T>
bool dspark::AutoGain< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores parameters from a blob (tolerant; rejects foreign ids).

Definition at line 220 of file AutoGain.h.


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