| Mozzi version v1.1.0 sound synthesis library for Arduino |

Public Member Functions | Protected Member Functions | List of all members
RollingAverage< T, WINDOW_LENGTH > Class Template Reference

Calculates a running average over a specified number of the most recent readings. More...

`#include <RollingAverage.h>`

## Public Member Functions
| RollingAverage ()
| Constructor. More...
T | next (T input)
| Give the average of the last WINDOW_LENGTH. More...

## Protected Member Functions
T | add (T input)

## Detailed Description

### template<class T, int WINDOW_LENGTH>
class RollingAverage< T, WINDOW_LENGTH >

Calculates a running average over a specified number of the most recent readings.

Like Smooth(), this is good for smoothing analog inputs in updateControl().

Template Parameters

  WINDOW_LENGTH | the number of readings to include in the rolling average. It must be a power of two (unless you're averaging floats). The higher the number, the more the readings will be smoothed, but the slower the output will respond to the input.

Definition at line 37 of file RollingAverage.h.

## Constructor & Destructor Documentation

## ◆ RollingAverage()

template<class T, int WINDOW_LENGTH>

RollingAverage< T, WINDOW_LENGTH >::RollingAverage | ( |  | ) |
| inline

Constructor.

Template Parameters

  T | the type of numbers to average, eg. int, unsigned int, float etc. It will be relatively slow with floating point numbers, as it will use a divide operation for the averaging. Nevertheless, there might be a time when it's useful.
  WINDOW_LENGTH | the number of readings to keep track of. It must be a power of two (unless you're averaging floats). The higher the number, the more the readings will be smoothed, but the slower the output will respond to the input.

Note
  Watch out for overflows!

Definition at line 51 of file RollingAverage.h.

## Member Function Documentation

## ◆ next()

template<class T, int WINDOW_LENGTH>

T RollingAverage< T, WINDOW_LENGTH >::next | ( | T | input | ) |
| inline

Give the average of the last WINDOW_LENGTH.

Parameters

  input | a control signal such as an analog input which needs smoothing.

Returns
  the smoothed result.

Note
  unsigned int timing 5.7us

Definition at line 64 of file RollingAverage.h.