|
| | SmoothedValue (const SmoothedValue &)=delete |
| | Prevents accidental copying of stateful DSP objects.
|
| |
| SmoothedValue & | operator= (const SmoothedValue &)=delete |
| |
| | SmoothedValue () noexcept |
| |
| void | prepare (double sampleRate, double rampTimeMs=20.0) noexcept |
| | Precalculates internal coefficients based on sample rate and timing.
|
| |
| void | setSmoothingType (SmoothingType type) noexcept |
| | Sets the smoothing algorithm.
|
| |
| SmoothingType | getSmoothingType () const noexcept |
| | Returns the current smoothing algorithm.
|
| |
| void | setAdaptiveRamp (double span, double fastMs, double slowMs) noexcept |
| | Makes the duration of every Linear ramp depend on its step.
|
| |
| bool | hasAdaptiveRamp () const noexcept |
| | Whether step-dependent ramps are on (see setAdaptiveRamp()).
|
| |
| void | setTargetValue (T newTarget) noexcept |
| | Updates the target value. Safe to call continuously (e.g., from host automation).
|
| |
| T | getNextValue () noexcept |
| | Calculates and returns the next smoothed value.
|
| |
| void | processBlock (std::span< T > buffer) noexcept |
| | Computes a block of smoothed values into an output buffer.
|
| |
| T | getCurrentValue () const noexcept |
| | Returns the current internal value without advancing the state.
|
| |
| T | getTargetValue () const noexcept |
| | Returns the set target value.
|
| |
| bool | isSmoothing () const noexcept |
| | Evaluates if the smoother is actively transitioning.
|
| |
| void | skip () noexcept |
| | Forces the current value to instantly match the target, bypassing time.
|
| |
| void | reset (T value=T(0)) noexcept |
| | Hard-resets both current and target states to a specific value.
|
| |
| void | setRampTime (double sampleRate, double rampTimeMs) noexcept |
| | Updates sample rate and/or ramp time, recalculating internal steps.
|
| |
template<FloatType T>
class dspark::SmoothedValue< T >
Zero-allocation parameter smoother for real-time audio.
Provides click-free parameter transitions using various curves, processed per-sample or per-block in the audio thread. A default-constructed smoother is functional at 44.1 kHz with a 20 ms ramp; prepare() adapts it to the real rate.
Timing semantics of rampTimeMs per curve:
- Exponential: one-pole time constant (63% arrival). The value snaps exactly onto the target once within a relative epsilon, about 16 time constants after a unit step, and isSmoothing() then reports false.
- Linear: constant velocity chosen at each retarget so that ANY step, whatever its size or unit (a gain, a frequency in Hz), arrives exactly on target after rampTimeMs.
- Chase: adaptive (not clocked): gentle right after a target change, accelerating as it settles. rampTimeMs is the time to cover 99% of any step (measured within 0.2% at 44.1 to 192 kHz and 5 ms to 1 s); the value then snaps onto the target after about 2.06 times that. The curve is the same at every sample rate. (It used to ignore rampTimeMs and always take 171 ms to 99%.)
Step-dependent ramps (opt-in, Linear only). setAdaptiveRamp() makes the duration of each linear ramp depend on the size of the step that starts it: a small move (fine automation, a knob nudged) glides over the slow time and hides its steps, a large jump (a preset, a switch) lands in the fast time. In between the duration follows a square law of how close the step is to nothing. An edit in mid ramp starts from the value already reached.
The recursion state is double regardless of T (the framework rule for recursive state): in float the one-pole stalls hundreds of epsilons short of the target when the per-sample increment rounds to zero, which would leave isSmoothing() true forever (and callers that gate work on it, like Gain's bulk path or CrossoverFilter's coefficient updates, stuck on their slow path).
- Note
- Thread Safety: This class is not inherently thread-safe to avoid atomic memory barriers in the DSP hot-path. Parameter updates via
setTargetValue() should occur synchronously within the audio thread (e.g., processing an event queue at the start of a block).
- Template Parameters
-
| T | Value type (float or double, constrained by FloatType). |
Definition at line 71 of file SmoothedValue.h.