Reference > twoPointAverage
Wave
Spectrum
twoPointAverage()
creates a two point average filter.
.apply
returns a function that applies the filter equation and updates the filter state.
Filter equation
output[i] = 0.5 * (input[i] + input[i - 1])
In synthesine, filters are functions with methods for applying and setting the filter, and an internal memory that keeps track of the state of the filter. The technical term for the kind of object is a closure. Every time you create a filter, the state is erased, so it’s a good idea to define your filters only once, in the setup function.
You can find the code for twoPointAverage
in the synthesine library.