Gin
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ValueSmoother< T > Class Template Reference

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.
 
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.
 
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.
 

Detailed Description

template<class T>
class ValueSmoother< T >

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:

gainSmoother.setSampleRate (44100.0);
gainSmoother.setTime (0.05); // 50ms smoothing time
// In parameter change callback
// In audio processing loop
for (int i = 0; i < numSamples; ++i)
{
float smoothedGain = gainSmoother.getNextValue();
output[i] = input[i] * smoothedGain;
}
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
Template Parameters
TThe numeric type for values (typically float or double)

Member Function Documentation

◆ setSampleRate()

template<class T >
void ValueSmoother< T >::setSampleRate ( double  sr)

Sets the sample rate for smoothing calculations.

This resets the smoother's delta value.

Parameters
srThe sample rate in Hz

References ValueSmoother< T >::reset().

◆ setTime()

template<class T >
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.

Parameters
tSmoothing time in seconds

References ValueSmoother< T >::reset().

◆ isSmoothing()

template<class T >
bool ValueSmoother< T >::isSmoothing ( )

Checks if the smoother is currently transitioning to the target value.

Returns
true if the current value hasn't reached the target yet

◆ reset()

template<class T >
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().

◆ getCurrentValue()

template<class T >
T ValueSmoother< T >::getCurrentValue ( )

Returns the current smoothed value without advancing.

Returns
The current value

◆ getValuePtr()

template<class T >
T * ValueSmoother< T >::getValuePtr ( )

Returns a pointer to the current value for direct access.

Returns
Pointer to the internal current value

◆ setValue()

template<class T >
void ValueSmoother< T >::setValue ( v)

Sets the target value to smooth towards.

The current value will gradually move toward this target.

Parameters
vThe new target value

◆ snapToValue()

template<class T >
void ValueSmoother< T >::snapToValue ( )

Immediately snaps the current value to the target value.

Useful for initializing or when you want to skip smoothing.

◆ process()

template<class T >
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.

Parameters
nNumber of samples to process

References ValueSmoother< T >::updateValue().

◆ updateValue()

template<class T >
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().

◆ getNextValue()

template<class T >
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.

Returns
The next smoothed value

◆ setValueUnsmoothed()

template<class T >
void ValueSmoother< T >::setValueUnsmoothed ( v)

Sets both target and current value immediately without smoothing.

Useful for initialization or when you need to jump to a value instantly.

Parameters
vThe value to set immediately

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