|
DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
|
Block-adaptive automatic gain compensation with SIMD-friendly linear interpolation. More...
#include <AutoGain.h>
Public Types | |
| enum class | Weighting { KWeighted , Flat } |
| Level measurement used for the match. More... | |
Public Member Functions | |
| void | prepare (const AudioSpec &spec) |
| 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. | |
| void | setWeighting (Weighting w) noexcept |
| Selects the level measurement (K-weighted loudness by default). RT-safe. | |
| Weighting | getWeighting () const noexcept |
| T | 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. | |
| T | getMaxCompensation () const noexcept |
| T | 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). | |
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.
| T | Sample type (float or double). Must be lock-free atomic compatible if modified concurrently. |
Definition at line 78 of file AutoGain.h.
|
strong |
Level measurement used for the match.
| Enumerator | |
|---|---|
| KWeighted | ITU-R BS.1770 K-weighting (loudness, LUFS filter). Default. |
| Flat | Unweighted mean square (plain RMS). |
Definition at line 86 of file AutoGain.h.
|
inlinenoexcept |
Measures output level and applies smoothed gain compensation. Must be called AFTER processing.
| buffer | Processed audio (modified in-place). |
Definition at line 134 of file AutoGain.h.
|
inlinenoexcept |
Returns the current internal compensation in dB. Useful for UI metering.
Safe from any thread: it loads a published atomic word, not the audio thread's working state. The value is the one the last completed compensate() left, so it may be up to one block old.
Definition at line 221 of file AutoGain.h.
|
inlinenoexcept |
Definition at line 251 of file AutoGain.h.
|
inlinenoexcept |
Definition at line 257 of file AutoGain.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 263 of file AutoGain.h.
|
inlinenoexcept |
Definition at line 207 of file AutoGain.h.
|
inline |
Prepares the auto-gain processor.
An invalid spec (non-positive or non-finite fields) is a no-op that keeps the previous state. Allocates the per-channel weighting state.
| spec | Audio environment specification containing sample rate and channels. |
Definition at line 100 of file AutoGain.h.
|
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.
| buffer | Input audio (read-only measurement). |
Definition at line 121 of file AutoGain.h.
|
inlinenoexcept |
Hard resets the internal state to avoid feedback loops or stale measurements.
Definition at line 189 of file AutoGain.h.
|
inlinenoexcept |
Thread-safe assignment of the maximum allowed compensation limit.
| dB | Max gain change in decibels (absolute value used symmetrically). Non-finite values are ignored (a NaN would silently disable the clamp). |
Definition at line 231 of file AutoGain.h.
|
inlinenoexcept |
Sets the smoothing time constant.
| ms | Smoothing time in milliseconds, floored at 1 ms. Non-finite values are ignored (a NaN would poison the compensation state permanently). |
Definition at line 243 of file AutoGain.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition at line 275 of file AutoGain.h.
|
inlinenoexcept |
Selects the level measurement (K-weighted loudness by default). RT-safe.
Definition at line 200 of file AutoGain.h.