Mozzi  version v1.1.0
sound synthesis library for Arduino
StateVariable< FILTER_TYPE > Class Template Reference



State Variable Filter (approximation of Chamberlin version) Informed by pseudocode at http://www.musicdsp.org/showone.php?id=23 and http://www.musicdsp.org/showone.php?id=142. More...

#include <StateVariable.h>

Public Member Functions

 StateVariable ()
 Constructor.
 
void setResonance (Q0n8 resonance)
 Set how resonant the filter will be. More...
 
void setCentreFreq (unsigned int centre_freq)
 Set the centre or corner frequency of the filter. More...
 
int next (int input)
 Calculate the next sample, given an input signal. More...
 

Detailed Description

template<int8_t FILTER_TYPE>
class StateVariable< FILTER_TYPE >



State Variable Filter (approximation of Chamberlin version) Informed by pseudocode at http://www.musicdsp.org/showone.php?id=23 and http://www.musicdsp.org/showone.php?id=142.

Here's the original:

cutoff = cutoff freq in Hz fs = sampling frequency //(e.g. 44100Hz) f = 2 sin (pi * cutoff / fs) //[approximately] q = resonance/bandwidth [0 < q <= 1] most res: q=1, less: q=0 low = lowpass output high = highpass output band = bandpass output notch = notch output

scale = q

low=high=band=0;

–beginloop low = low + f * band; high = scale * input - low - q*band; band = f * high + band; notch = high + low;

–endloop

References : Hal Chamberlin, Musical Applications of Microprocessors, 2nd Ed, Hayden Book Company 1985. pp 490-492. Jon Dattorro, Effect Design Part 1, J. Audio Eng. Soc., Vol 45, No. 9, 1997 September A State Variable filter which offers 12db resonant low, high, bandpass and notch modes.

Template Parameters
FILTER_TYPEchoose between LOWPASS, BANDPASS, HIGHPASS and NOTCH.
Note
To save processing time, this version of the filter does not saturate internally, so any resonant peaks are unceremoniously truncated. It may be worth adding code to constrain the internal variables to enable resonant saturating effects.

Definition at line 66 of file StateVariable.h.

Member Function Documentation

◆ next()

template<int8_t FILTER_TYPE>
int StateVariable< FILTER_TYPE >::next ( int  input)
inline

Calculate the next sample, given an input signal.

Parameters
inputthe signal input.
Returns
the signal output.
Note
Timing: 16 - 20 us

Definition at line 113 of file StateVariable.h.

◆ setCentreFreq()

template<int8_t FILTER_TYPE>
void StateVariable< FILTER_TYPE >::setCentreFreq ( unsigned int  centre_freq)
inline

Set the centre or corner frequency of the filter.

Parameters
centre_freq20 - 4096 Hz (AUDIO_RATE/4). This will be the cut-off frequency for LOWPASS and HIGHPASS, and the centre frequency to pass or reduce for BANDPASS and NOTCH.
Note
Timing 25-30us
The frequency calculation is VERY "approximate". This really needs to be fixed.

Definition at line 95 of file StateVariable.h.

◆ setResonance()

template<int8_t FILTER_TYPE>
void StateVariable< FILTER_TYPE >::setResonance ( Q0n8  resonance)
inline

Set how resonant the filter will be.

Parameters
resonancea byte value between 1 and 255. The lower this value is, the more resonant the filter. At very low values, the filter can output loud peaks which can exceed Mozzi's output range, so you may need to attenuate the output in your sketch.
Note
Timing < 500 ns

Definition at line 80 of file StateVariable.h.