44 #ifndef STATEVARIABLE_H_ 45 #define STATEVARIABLE_H_ 53 enum filter_types { LOWPASS, BANDPASS, HIGHPASS, NOTCH };
83 scale = (Q0n8)sqrt((
unsigned int)resonance << 8);
99 (AUDIO_RATE_AS_LSHIFT));
116 return next(input,
Int2Type<FILTER_TYPE>());
129 inline int next(
int input,
Int2Type<LOWPASS>) {
131 low += ((f * band) >> 16);
132 int high = (((
long)input - low - (((
long)band * q) >> 8)) * scale) >> 8;
133 band += ((f * high) >> 16);
144 inline int next(
int input,
Int2Type<BANDPASS>) {
146 low += ((f * band) >> 16);
147 int high = (((
long)input - low - (((
long)band * q) >> 8)) * scale) >> 8;
148 band += ((f * high) >> 16);
159 inline int next(
int input,
Int2Type<HIGHPASS>) {
161 low += ((f * band) >> 16);
162 int high = (((
long)input - low - (((
long)band * q) >> 8)) * scale) >> 8;
163 band += ((f * high) >> 16);
174 inline int next(
int input,
Int2Type<NOTCH>) {
176 low += ((f * band) >> 16);
177 int high = (((
long)input - low - (((
long)band * q) >> 8)) * scale) >> 8;
178 band += ((f * high) >> 16);
179 int notch = high + low;
int32_t Q15n16
signed fractional number using 15 integer bits and 16 fractional bits, represents -32767...
void setResonance(Q0n8 resonance)
Set how resonant the filter will be.
Enables you to instantiate a template based on an integer value.
StateVariable()
Constructor.
int next(int input)
Calculate the next sample, given an input signal.
A State Variable filter which offers 12db resonant low, high, bandpass and notch modes.
#define Q16n16_2PI
2*PI in Q16n16 format
uint8_t Q0n8
unsigned fractional number using 8 fractional bits, represents 0.0 to 0.996
void setCentreFreq(unsigned int centre_freq)
Set the centre or corner frequency of the filter.