Mozzi  version v2.0
sound synthesis library for Arduino
Smooth< T > Class Template Reference

A simple infinite impulse response low pass filter for smoothing control or audio signals. More...

#include <Smooth.h>

Detailed Description

template<class T>
class Smooth< T >

A simple infinite impulse response low pass filter for smoothing control or audio signals.

This algorithm comes from http://en.wikipedia.org/wiki/Low-pass_filter: y[i] := y[i-1] + α * (x[i] - y[i-1]), translated as out = last_out + a * (in - last_out). It's not calibrated to any real-world update rate, so if you use it at MOZZI_CONTROL_RATE and you change MOZZI_CONTROL_RATE, you'll need to adjust the smoothness value to suit.

Template Parameters
Tthe type of numbers being smoothed. Watch out for numbers overflowing the internal calculations. Some experimentation is recommended.
Note
Timing: ~5us for 16 bit types, ~1us for 8 bit types.

Definition at line 35 of file Smooth.h.

Public Member Functions

 Smooth (float smoothness)
 Constructor. More...
 
 Smooth ()
 Constructor. More...
 
T next (T in)
 Filters the input and returns the filtered value. More...
 
T operator() (T n)
 Filters the input and returns the filtered value. More...
 
void setSmoothness (float smoothness)
 Sets how much smoothing the filter will apply to its input. More...
 

Constructor & Destructor Documentation

◆ Smooth() [1/2]

template<class T >
Smooth< T >::Smooth ( float  smoothness)
inline

Constructor.

Parameters
smoothnesssets how much smoothing the filter will apply to its input. Use a float in the range 0~1, where 0 is not very smooth and 0.99 is very smooth.

Definition at line 47 of file Smooth.h.

◆ Smooth() [2/2]

template<class T >
Smooth< T >::Smooth ( )
inline

Constructor.

This constructor which doesn't take a smoothness parameter is useful when you incorporate Smooth into another class definition. You need to call setSmoothness(float) for your object before using Smooth.

Note
there's probably a better way to do this...

Definition at line 57 of file Smooth.h.

Member Function Documentation

◆ next()

template<class T >
T Smooth< T >::next ( T  in)
inline

Filters the input and returns the filtered value.

You can also use the operator() function, eg. something like mySmoother(input-value).

Parameters
inthe signal to be smoothed.
Returns
the filtered signal.

Definition at line 66 of file Smooth.h.

◆ operator()()

template<class T >
T Smooth< T >::operator() ( T  n)
inline

Filters the input and returns the filtered value.

Same as next(input-value).

Parameters
inthe signal to be smoothed.
Returns
the filtered signal.

Definition at line 79 of file Smooth.h.

◆ setSmoothness()

template<class T >
void Smooth< T >::setSmoothness ( float  smoothness)
inline

Sets how much smoothing the filter will apply to its input.

Parameters
smoothnesssets how much smoothing the filter will apply to its input. Use a float in the range 0~1, where 0 is not very smooth and 0.99 is very smooth.

Definition at line 90 of file Smooth.h.