JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::SmoothedValue< FloatType, SmoothingType > Class Template Reference

A utility class for values that need smoothing to avoid audio glitches. More...

#include <juce_SmoothedValue.h>

Inheritance diagram for juce::SmoothedValue< FloatType, SmoothingType >:
Collaboration diagram for juce::SmoothedValue< FloatType, SmoothingType >:

Public Types

using FloatType = typename FloatTypeHelper< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::Type
 

Public Member Functions

 SmoothedValue () noexcept
 Constructor. More...
 
 SmoothedValue (FloatType initialValue) noexcept
 Constructor. More...
 
void applyGain (AudioBuffer< FloatType > &buffer, int numSamples) noexcept
 Applies a smoothed gain to a buffer. More...
 
void applyGain (FloatType *samples, int numSamples) noexcept
 Applies a smoothed gain to a stream of samples S[i] *= gain. More...
 
void applyGain (FloatType *samplesOut, const FloatType *samplesIn, int numSamples) noexcept
 Computes output as a smoothed gain applied to a stream of samples. More...
 
FloatType getCurrentValue () const noexcept
 Returns the current value of the ramp. More...
 
FloatType getNextValue () noexcept
 Compute the next value. More...
 
FloatType getTargetValue () const noexcept
 Returns the target value towards which the smoothed value is currently moving. More...
 
bool isSmoothing () const noexcept
 Returns true if the current value is currently being interpolated. More...
 
void reset (double sampleRate, double rampLengthInSeconds) noexcept
 Reset to a new sample rate and ramp length. More...
 
void reset (int numSteps) noexcept
 Set a new ramp length directly in samples. More...
 
void setCurrentAndTargetValue (FloatType newValue)
 Sets the current value and the target value. More...
 
void setTargetValue (FloatType newValue) noexcept
 Set the next value to ramp towards. More...
 
FloatType skip (int numSamples) noexcept
 Skip the next numSamples samples. More...
 

Protected Attributes

int countdown
 
FloatType currentValue
 
FloatType target
 

Private Types

template<typename T >
using LinearVoid = typename std::enable_if< std::is_same< T, ValueSmoothingTypes::Linear >::value, void >::type
 
template<typename T >
using MultiplicativeVoid = typename std::enable_if< std::is_same< T, ValueSmoothingTypes::Multiplicative >::value, void >::type
 

Private Member Functions

FloatType getNextSmoothedValue () noexcept
 
template<typename T = SmoothingType>
LinearVoid< T > setNextValue () noexcept
 
template<typename T = SmoothingType>
MultiplicativeVoid< T > setNextValue () noexcept
 
template<typename T = SmoothingType>
MultiplicativeVoid< T > setStepSize ()
 
template<typename T = SmoothingType>
LinearVoid< T > setStepSize () noexcept
 
template<typename T = SmoothingType>
MultiplicativeVoid< T > skipCurrentValue (int numSamples)
 
template<typename T = SmoothingType>
LinearVoid< T > skipCurrentValue (int numSamples) noexcept
 

Private Attributes

FloatType step = FloatType()
 
int stepsToTarget = 0
 

Detailed Description

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
class juce::SmoothedValue< FloatType, SmoothingType >

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.

SmoothedValue<float, ValueSmoothingTypes::Linear> yourSmoothedValue;

A ValueSmoothingTypes::Multiplicative template parameter selects multiplicative smoothing increments towards the target value.

SmoothedValue<float, ValueSmoothingTypes::Multiplicative> yourSmoothedValue;

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}

Member Typedef Documentation

◆ FloatType

◆ LinearVoid

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T >
using juce::SmoothedValue< FloatType, SmoothingType >::LinearVoid = typename std::enable_if <std::is_same <T, ValueSmoothingTypes::Linear>::value, void>::type
private

◆ MultiplicativeVoid

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T >
using juce::SmoothedValue< FloatType, SmoothingType >::MultiplicativeVoid = typename std::enable_if <std::is_same <T, ValueSmoothingTypes::Multiplicative>::value, void>::type
private

Constructor & Destructor Documentation

◆ SmoothedValue() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
juce::SmoothedValue< FloatType, SmoothingType >::SmoothedValue ( )
inlinenoexcept

Constructor.

◆ SmoothedValue() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
juce::SmoothedValue< FloatType, SmoothingType >::SmoothedValue ( FloatType  initialValue)
inlinenoexcept

Constructor.

Member Function Documentation

◆ applyGain() [1/3]

void juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::applyGain ( AudioBuffer< FloatType > &  buffer,
int  numSamples 
)
inlinenoexceptinherited

Applies a smoothed gain to a buffer.

◆ applyGain() [2/3]

void juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::applyGain ( FloatType samples,
int  numSamples 
)
inlinenoexceptinherited

Applies a smoothed gain to a stream of samples S[i] *= gain.

Parameters
samplesPointer to a raw array of samples
numSamplesLength of array of samples

◆ applyGain() [3/3]

void juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::applyGain ( FloatType samplesOut,
const FloatType samplesIn,
int  numSamples 
)
inlinenoexceptinherited

Computes output as a smoothed gain applied to a stream of samples.

Sout[i] = Sin[i] * gain

Parameters
samplesOutA pointer to a raw array of output samples
samplesInA pointer to a raw array of input samples
numSamplesThe length of the array of samples

◆ getCurrentValue()

FloatType juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::getCurrentValue
inlinenoexceptinherited

Returns the current value of the ramp.

◆ getNextSmoothedValue()

FloatType juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::getNextSmoothedValue
inlineprivatenoexceptinherited

◆ getNextValue()

◆ getTargetValue()

Returns the target value towards which the smoothed value is currently moving.

◆ isSmoothing()

Returns true if the current value is currently being interpolated.

◆ reset() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::reset ( double  sampleRate,
double  rampLengthInSeconds 
)
inlinenoexcept

◆ reset() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::reset ( int  numSteps)
inlinenoexcept

Set a new ramp length directly in samples.

Parameters
numStepsThe number of samples over which the ramp should be active

◆ setCurrentAndTargetValue()

void juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >::setCurrentAndTargetValue ( FloatType  newValue)
inlineinherited

Sets the current value and the target value.

Parameters
newValuethe new value to take

◆ setNextValue() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
LinearVoid<T> juce::SmoothedValue< FloatType, SmoothingType >::setNextValue ( )
inlineprivatenoexcept

◆ setNextValue() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
MultiplicativeVoid<T> juce::SmoothedValue< FloatType, SmoothingType >::setNextValue ( )
inlineprivatenoexcept

◆ setStepSize() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
MultiplicativeVoid<T> juce::SmoothedValue< FloatType, SmoothingType >::setStepSize ( )
inlineprivate

◆ setStepSize() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
LinearVoid<T> juce::SmoothedValue< FloatType, SmoothingType >::setStepSize ( )
inlineprivatenoexcept

◆ setTargetValue()

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::setTargetValue ( FloatType  newValue)
inlinenoexcept

◆ skip()

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
FloatType juce::SmoothedValue< FloatType, SmoothingType >::skip ( int  numSamples)
inlinenoexcept

Skip the next numSamples samples.

This is identical to calling getNextValue numSamples times. It returns the new current value.

See also
getNextValue

Referenced by juce::dsp::Gain< FloatType >::process(), juce::dsp::Bias< FloatType >::process(), and juce::dsp::Oscillator< SampleType >::process().

◆ skipCurrentValue() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
MultiplicativeVoid<T> juce::SmoothedValue< FloatType, SmoothingType >::skipCurrentValue ( int  numSamples)
inlineprivate

◆ skipCurrentValue() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
LinearVoid<T> juce::SmoothedValue< FloatType, SmoothingType >::skipCurrentValue ( int  numSamples)
inlineprivatenoexcept

Member Data Documentation

◆ countdown

◆ currentValue

◆ step

◆ stepsToTarget

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>
int juce::SmoothedValue< FloatType, SmoothingType >::stepsToTarget = 0
private

◆ target


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