A utility class for values that need smoothing to avoid audio glitches. More...
#include <juce_SmoothedValue.h>


Public Types | |
| using | FloatType = typename FloatTypeHelper< SmoothedValueType >::Type |
Public Member Functions | |
| SmoothedValue () noexcept | |
| Constructor. | |
| SmoothedValue (FloatType initialValue) noexcept | |
| Constructor. | |
| void | applyGain (AudioBuffer< FloatType > &buffer, int numSamples) noexcept |
| Applies a smoothed gain to a buffer. | |
| void | applyGain (FloatType *samples, int numSamples) noexcept |
| Applies a smoothed gain to a stream of samples S[i] *= gain. | |
| void | applyGain (FloatType *samplesOut, const FloatType *samplesIn, int numSamples) noexcept |
| Computes output as a smoothed gain applied to a stream of samples. | |
| FloatType | getCurrentValue () const noexcept |
| Returns the current value of the ramp. | |
| FloatType | getNextValue () noexcept |
| Compute the next value. | |
| FloatType | getTargetValue () const noexcept |
| Returns the target value towards which the smoothed value is currently moving. | |
| bool | isSmoothing () const noexcept |
| Returns true if the current value is currently being interpolated. | |
| void | reset (double sampleRate, double rampLengthInSeconds) noexcept |
| Reset to a new sample rate and ramp length. | |
| void | reset (int numSteps) noexcept |
| Set a new ramp length directly in samples. | |
| void | setCurrentAndTargetValue (FloatType newValue) |
| Sets the current value and the target value. | |
| void | setTargetValue (FloatType newValue) noexcept |
| Set the next value to ramp towards. | |
| FloatType | skip (int numSamples) noexcept |
| Skip the next numSamples samples. | |
Protected Attributes | |
| int | countdown = 0 |
| FloatType | currentValue = 0 |
| FloatType | target = currentValue |
Private Member Functions | |
| FloatType | getNextSmoothedValue () noexcept |
| template<typename T = SmoothingType> | |
| void | setNextValue () noexcept |
| template<typename T = SmoothingType> | |
| void | setStepSize () noexcept |
| template<typename T = SmoothingType> | |
| void | skipCurrentValue (int numSamples) noexcept |
Private Attributes | |
| FloatType | step = FloatType() |
| int | stepsToTarget = 0 |
A utility class for values that need smoothing to avoid audio glitches.
A ValueSmoothingTypes::Linear template parameter selects linear smoothing, which increments the SmoothedValue linearly towards its target value.
A ValueSmoothingTypes::Multiplicative template parameter selects multiplicative smoothing increments towards the target value.
Multiplicative smoothing is useful when you are dealing with exponential/logarithmic values like volume in dB or frequency in Hz. For example a 12 step ramp from 440.0 Hz (A4) to 880.0 Hz (A5) will increase the frequency with an equal temperament tuning across the octave. A 10 step smoothing from 1.0 (0 dB) to 3.16228 (10 dB) will increase the value in increments of 1 dB.
Note that when you are using multiplicative smoothing you cannot ever reach a target value of zero!
@tags{Audio}
|
inherited |
|
inlinenoexcept |
Constructor.
|
inlinenoexcept |
|
inlinenoexceptinherited |
Applies a smoothed gain to a buffer.
References juce::SmoothedValueBase< SmoothedValueType >::getNextSmoothedValue(), juce::SmoothedValueBase< SmoothedValueType >::isSmoothing(), jassert, and juce::SmoothedValueBase< SmoothedValueType >::target.
|
inlinenoexceptinherited |
Applies a smoothed gain to a stream of samples S[i] *= gain.
| samples | Pointer to a raw array of samples |
| numSamples | Length of array of samples |
References juce::SmoothedValueBase< SmoothedValueType >::getNextSmoothedValue(), juce::SmoothedValueBase< SmoothedValueType >::isSmoothing(), jassert, and juce::SmoothedValueBase< SmoothedValueType >::target.
|
inlinenoexceptinherited |
Computes output as a smoothed gain applied to a stream of samples.
Sout[i] = Sin[i] * gain
| samplesOut | A pointer to a raw array of output samples |
| samplesIn | A pointer to a raw array of input samples |
| numSamples | The length of the array of samples |
References juce::SmoothedValueBase< SmoothedValueType >::getNextSmoothedValue(), juce::SmoothedValueBase< SmoothedValueType >::isSmoothing(), jassert, and juce::SmoothedValueBase< SmoothedValueType >::target.
|
inlinenoexceptinherited |
Returns the current value of the ramp.
References juce::SmoothedValueBase< SmoothedValueType >::currentValue.
|
inlineprivatenoexceptinherited |
|
inlinenoexcept |
Compute the next value.
References juce::SmoothedValueBase< SmoothedValueType >::countdown, juce::SmoothedValueBase< SmoothedValueType >::currentValue, juce::SmoothedValueBase< SmoothedValueType >::isSmoothing(), juce::SmoothedValue< FloatType, SmoothingType >::setNextValue(), and juce::SmoothedValueBase< SmoothedValueType >::target.
Referenced by juce::dsp::Oscillator< SampleType >::process(), juce::Reverb::processMono(), juce::dsp::Oscillator< SampleType >::processSample(), and juce::Reverb::processStereo().
|
inlinenoexceptinherited |
Returns the target value towards which the smoothed value is currently moving.
References juce::SmoothedValueBase< SmoothedValueType >::target.
Referenced by juce::dsp::Oscillator< SampleType >::getFrequency().
|
inlinenoexceptinherited |
Returns true if the current value is currently being interpolated.
References juce::SmoothedValueBase< SmoothedValueType >::countdown.
Referenced by juce::SmoothedValueBase< SmoothedValueType >::applyGain(), juce::SmoothedValueBase< SmoothedValueType >::applyGain(), juce::SmoothedValueBase< SmoothedValueType >::applyGain(), juce::SmoothedValue< FloatType, SmoothingType >::getNextValue(), and juce::dsp::Oscillator< SampleType >::process().
|
inlinenoexcept |
Reset to a new sample rate and ramp length.
| sampleRate | The sample rate |
| rampLengthInSeconds | The duration of the ramp in seconds |
References jassert, and juce::SmoothedValue< FloatType, SmoothingType >::reset().
Referenced by juce::dsp::Oscillator< SampleType >::reset(), juce::SmoothedValue< FloatType, SmoothingType >::reset(), and juce::Reverb::setSampleRate().
|
inlinenoexcept |
Set a new ramp length directly in samples.
| numSteps | The number of samples over which the ramp should be active |
References juce::SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::stepsToTarget, and juce::SmoothedValueBase< SmoothedValueType >::target.
|
inlineinherited |
Sets the current value and the target value.
| newValue | the new value to take |
References juce::SmoothedValueBase< SmoothedValueType >::countdown, juce::SmoothedValueBase< SmoothedValueType >::currentValue, and juce::SmoothedValueBase< SmoothedValueType >::target.
Referenced by juce::SmoothedValue< FloatType, SmoothingType >::reset(), juce::dsp::Oscillator< SampleType >::setFrequency(), juce::SmoothedValue< FloatType, SmoothingType >::setTargetValue(), and juce::SmoothedValue< FloatType, SmoothingType >::skip().
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
References juce::SmoothedValueBase< SmoothedValueType >::countdown, juce::SmoothedValueBase< SmoothedValueType >::currentValue, juce::SmoothedValue< FloatType, SmoothingType >::step, and juce::SmoothedValueBase< SmoothedValueType >::target.
Referenced by juce::SmoothedValue< FloatType, SmoothingType >::setTargetValue().
|
inlinenoexcept |
Set the next value to ramp towards.
| newValue | The new target value |
References juce::approximatelyEqual(), juce::SmoothedValueBase< SmoothedValueType >::countdown, jassert, juce::SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::setStepSize(), juce::SmoothedValue< FloatType, SmoothingType >::stepsToTarget, and juce::SmoothedValueBase< SmoothedValueType >::target.
Referenced by juce::Reverb::setDamping(), juce::dsp::Oscillator< SampleType >::setFrequency(), juce::Reverb::setParameters(), juce::dsp::LadderFilter< SampleType >::updateCutoffFreq(), and juce::dsp::LadderFilter< SampleType >::updateResonance().
|
inlinenoexcept |
Skip the next numSamples samples.
This is identical to calling getNextValue numSamples times. It returns the new current value.
References juce::SmoothedValueBase< SmoothedValueType >::countdown, juce::SmoothedValueBase< SmoothedValueType >::currentValue, juce::SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::skipCurrentValue(), and juce::SmoothedValueBase< SmoothedValueType >::target.
Referenced by juce::dsp::Oscillator< SampleType >::process().
|
inlineprivatenoexcept |
|
protectedinherited |
Referenced by juce::SmoothedValue< FloatType, SmoothingType >::getNextValue(), juce::SmoothedValueBase< SmoothedValueType >::isSmoothing(), juce::SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::setStepSize(), juce::SmoothedValue< FloatType, SmoothingType >::setTargetValue(), and juce::SmoothedValue< FloatType, SmoothingType >::skip().
|
protectedinherited |
Referenced by juce::SmoothedValue< FloatType, SmoothingType >::SmoothedValue(), juce::SmoothedValueBase< SmoothedValueType >::getCurrentValue(), juce::SmoothedValue< FloatType, SmoothingType >::getNextValue(), juce::SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::setNextValue(), juce::SmoothedValue< FloatType, SmoothingType >::setStepSize(), juce::SmoothedValue< FloatType, SmoothingType >::skip(), and juce::SmoothedValue< FloatType, SmoothingType >::skipCurrentValue().
|
private |
|
private |
|
protectedinherited |
Referenced by juce::SmoothedValue< FloatType, SmoothingType >::SmoothedValue(), juce::SmoothedValueBase< SmoothedValueType >::applyGain(), juce::SmoothedValueBase< SmoothedValueType >::applyGain(), juce::SmoothedValueBase< SmoothedValueType >::applyGain(), juce::SmoothedValue< FloatType, SmoothingType >::getNextValue(), juce::SmoothedValueBase< SmoothedValueType >::getTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::reset(), juce::SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), juce::SmoothedValue< FloatType, SmoothingType >::setStepSize(), juce::SmoothedValue< FloatType, SmoothingType >::setTargetValue(), and juce::SmoothedValue< FloatType, SmoothingType >::skip().