|
Gin
|
Linearly smooths parameter changes over time at a constant rate. More...
#include <gin_valuesmoother.h>
Public Member Functions | |
| void | setSampleRate (double sr) |
| Sets the sample rate for smoothing calculations. | |
| void | setTime (double t) |
| Sets the smoothing time - duration for a full 0 to 1 transition. | |
| bool | isSmoothing () |
| Checks if the smoother is currently transitioning to the target value. | |
| void | reset () |
| Recalculates the delta value based on current sample rate and time. | |
| T | getCurrentValue () |
| Returns the current smoothed value without advancing. | |
| T * | getValuePtr () |
| Returns a pointer to the current value for direct access. | |
| void | setValue (T v) |
| Sets the target value to smooth towards. | |
| void | snapToValue () |
| Immediately snaps the current value to the target value. | |
| void | process (int n) |
| Processes multiple samples, advancing the smoother by n steps. | |
| void | updateValue () |
| Advances the current value one step toward the target. | |
| T | getNextValue () |
| Advances the smoother by one sample and returns the new value. | |
| void | setValueUnsmoothed (T v) |
| Sets both target and current value immediately without smoothing. | |
Linearly smooths parameter changes over time at a constant rate.
ValueSmoother provides linear interpolation between parameter values, smoothing transitions to prevent zipper noise and clicks in audio processing. It operates by moving the current value toward the target value at a constant rate per sample, defined by the smoothing time.
The smoother is designed for normalized values (0 to 1 range) but can work with any numeric type. The time parameter specifies how long it takes to transition from 0 to 1 (or 1 to 0), regardless of the actual range used.
Common Use Cases:
Thread Safety:
Example usage:
| T | The numeric type for values (typically float or double) |
| void ValueSmoother< T >::setSampleRate | ( | double | sr | ) |
Sets the sample rate for smoothing calculations.
This resets the smoother's delta value.
| sr | The sample rate in Hz |
References ValueSmoother< T >::reset().
| void ValueSmoother< T >::setTime | ( | double | t | ) |
Sets the smoothing time - duration for a full 0 to 1 transition.
This resets the smoother's delta value.
| t | Smoothing time in seconds |
References ValueSmoother< T >::reset().
| bool ValueSmoother< T >::isSmoothing | ( | ) |
Checks if the smoother is currently transitioning to the target value.
| void ValueSmoother< T >::reset | ( | ) |
Recalculates the delta value based on current sample rate and time.
Called automatically when sample rate or time changes.
Referenced by ValueSmoother< T >::setSampleRate(), and ValueSmoother< T >::setTime().
| T ValueSmoother< T >::getCurrentValue | ( | ) |
Returns the current smoothed value without advancing.
| T * ValueSmoother< T >::getValuePtr | ( | ) |
Returns a pointer to the current value for direct access.
| void ValueSmoother< T >::setValue | ( | T | v | ) |
Sets the target value to smooth towards.
The current value will gradually move toward this target.
| v | The new target value |
| void ValueSmoother< T >::snapToValue | ( | ) |
Immediately snaps the current value to the target value.
Useful for initializing or when you want to skip smoothing.
| void ValueSmoother< T >::process | ( | int | n | ) |
Processes multiple samples, advancing the smoother by n steps.
Updates the current value n times, moving it toward the target.
| n | Number of samples to process |
References ValueSmoother< T >::updateValue().
| void ValueSmoother< T >::updateValue | ( | ) |
Advances the current value one step toward the target.
This is the core smoothing function, called internally by process() and getNextValue().
Referenced by ValueSmoother< T >::process().
| T ValueSmoother< T >::getNextValue | ( | ) |
Advances the smoother by one sample and returns the new value.
This is the typical method to call in per-sample audio processing.
| void ValueSmoother< T >::setValueUnsmoothed | ( | T | v | ) |
Sets both target and current value immediately without smoothing.
Useful for initialization or when you need to jump to a value instantly.
| v | The value to set immediately |