JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | List of all members
SmoothedValue< FloatType, SmoothingType > Class Template Reference
juce_audio_basics » utilities

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

`#include <juce_SmoothedValue.h>`

Inheritance diagram for SmoothedValue< FloatType, SmoothingType >:

## Public Member Functions
| SmoothedValue () noexcept
| Constructor.
| SmoothedValue (FloatType initialValue) noexcept
| Constructor.
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 | setTargetValue (FloatType newValue) noexcept
| Set the next value to ramp towards.
FloatType | getNextValue () noexcept
| Compute the next value.
FloatType | skip (int numSamples) noexcept
| Skip the next numSamples samples.
Public Member Functions inherited from SmoothedValueBase< SmoothedValueType >
| SmoothedValueBase ()=default
| Constructor.
bool | isSmoothing () const noexcept
| Returns true if the current value is currently being interpolated.
FloatType | getCurrentValue () const noexcept
| Returns the current value of the ramp.
FloatType | getTargetValue () const noexcept
| Returns the target value towards which the smoothed value is currently moving.
void | setCurrentAndTargetValue (FloatType newValue)
| Sets the current value and the target value.
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.
void | applyGain (AudioBuffer< FloatType > &buffer, int numSamples) noexcept
| Applies a smoothed gain to a buffer.

## Additional Inherited Members
Public Types inherited from SmoothedValueBase< SmoothedValueType >
using | FloatType = typename FloatTypeHelper<SmoothedValueType>::Type
Protected Attributes inherited from SmoothedValueBase< SmoothedValueType >
FloatType | currentValue = 0
FloatType | target = currentValue
int | countdown = 0

## Detailed Description

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
class 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;
SmoothedValue
A utility class for values that need smoothing to avoid audio glitches.
Definition juce_SmoothedValue.h:228

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!

## Constructor & Destructor Documentation

## ◆ SmoothedValue() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

SmoothedValue< FloatType, SmoothingType >::SmoothedValue | ( |  | ) |
| noexcept

Constructor.

## ◆ SmoothedValue() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

SmoothedValue< FloatType, SmoothingType >::SmoothedValue | ( | FloatType | initialValue | ) |
| noexcept

Constructor.

References approximatelyEqual(), SmoothedValueBase< SmoothedValueType >::currentValue, jassert, and SmoothedValueBase< SmoothedValueType >::target.

## Member Function Documentation

## ◆ reset() [1/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

void SmoothedValue< FloatType, SmoothingType >::reset | ( | double | sampleRate,
|  | double | rampLengthInSeconds )
| noexcept

Reset to a new sample rate and ramp length.

Parameters

  sampleRate | The sample rate
  rampLengthInSeconds | The duration of the ramp in seconds

References jassert, and SmoothedValue< FloatType, SmoothingType >::reset().

Referenced by juce::dsp::Oscillator< SampleType >::reset(), SmoothedValue< FloatType, SmoothingType >::reset(), and Reverb::setSampleRate().

## ◆ reset() [2/2]

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

void SmoothedValue< FloatType, SmoothingType >::reset | ( | int | numSteps | ) |
| noexcept

Set a new ramp length directly in samples.

Parameters

  numSteps | The number of samples over which the ramp should be active

References SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), and SmoothedValueBase< SmoothedValueType >::target.

## ◆ setTargetValue()

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

void SmoothedValue< FloatType, SmoothingType >::setTargetValue | ( | FloatType | newValue | ) |
| noexcept

Set the next value to ramp towards.

Parameters

  newValue | The new target value

References approximatelyEqual(), SmoothedValueBase< SmoothedValueType >::countdown, jassert, SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), and SmoothedValueBase< SmoothedValueType >::target.

Referenced by juce::dsp::Oscillator< SampleType >::setFrequency(), and Reverb::setParameters().

## ◆ getNextValue()

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

FloatType SmoothedValue< FloatType, SmoothingType >::getNextValue | ( |  | ) |
| noexcept

Compute the next value.

Returns
  Smoothed value

References SmoothedValueBase< SmoothedValueType >::countdown, SmoothedValueBase< SmoothedValueType >::currentValue, SmoothedValueBase< SmoothedValueType >::isSmoothing(), and SmoothedValueBase< SmoothedValueType >::target.

Referenced by juce::dsp::Oscillator< SampleType >::process(), Reverb::processMono(), juce::dsp::Oscillator< SampleType >::processSample(), and Reverb::processStereo().

## ◆ skip()

template<typename FloatType , typename SmoothingType = ValueSmoothingTypes::Linear>

FloatType SmoothedValue< FloatType, SmoothingType >::skip | ( | int | numSamples | ) |
| noexcept

Skip the next numSamples samples.

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

See also
  getNextValue

References SmoothedValueBase< SmoothedValueType >::countdown, SmoothedValueBase< SmoothedValueType >::currentValue, SmoothedValueBase< SmoothedValueType >::setCurrentAndTargetValue(), and SmoothedValueBase< SmoothedValueType >::target.

Referenced by juce::dsp::Oscillator< SampleType >::process().

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

- juce_SmoothedValue.h