A utility class to smooth discrete values over a given period. More...
#include <marvin_SmoothedValue.h>
Public Member Functions | |
void | reset (int stepsSamples, bool skipRemaining=true) |
void | reset (double sampleRate, double timeMs, bool skipRemaining=true) |
void | setCurrentAndTargetValue (SampleType newValue) |
void | setTargetValue (SampleType newValue) |
SampleType | operator() () noexcept |
bool | isSmoothing () const noexcept |
int | getRemainingSamples () const noexcept |
SampleType | getTargetValue () const noexcept |
A utility class to smooth discrete values over a given period.
Mainly useful to help with zippering caused by discrete parameter updates. Can be configured to either smooth linearly or exponentially to the target value.
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscardnoexcept |
Checks if the smoother has reached its target value.
|
nodiscardnoexcept |
Performs a single tick of the smoothing function.
If the SmoothedValue is configured to use SmoothingType::Linear, the formula is v = v+slew
, where slew has been calculated based on the target value.
If the SmoothedValue is configured to use SmoothingType::Exponential, the formula is v = v + (target = v) * slew
.
void marvin::utils::SmoothedValue< SampleType, Type >::reset | ( | double | sampleRate, |
double | timeMs, | ||
bool | skipRemaining = true ) |
Sets the period of the smoothing, and optionally sets the current value to the target value.
sampleRate | The currently configured sample rate. |
timeMs | The period of the smoothing, in milliseconds. |
skipRemaining | If true, sets the current value to the target value. |
void marvin::utils::SmoothedValue< SampleType, Type >::reset | ( | int | stepsSamples, |
bool | skipRemaining = true ) |
Sets the period of the smoothing, and optionally sets the current value to the target value. If Type == SmoothingType::Linear, the interpolation will take exactly this many samples. If Type == SmoothingType::Exponential, then the period actually specifies the time (in samples) it will take for the smoother to reach 63.2% (approx 1 - 1/e
) of the target value. This is the mathematical definition of an exponential smoother's time constant, so was chosen for that reason. If you'd instead like to set the time taken to reach some arbitary percent distance from the target value, then you can calculate the value for it with something like the below snippet.
stepsSamples | The period of the smoothing, in samples. |
skipRemaining | If true, sets the current value to the target value. |
void marvin::utils::SmoothedValue< SampleType, Type >::setCurrentAndTargetValue | ( | SampleType | newValue | ) |
Sets both the current value, and the target value to interpolate to.
newValue | The new target (and current) value. |
void marvin::utils::SmoothedValue< SampleType, Type >::setTargetValue | ( | SampleType | newValue | ) |
Sets the value the smoother should interpolate to.
newValue | The new target value. |