12 #ifndef RESONANTFILTER_H_
13 #define RESONANTFILTER_H_
15 #include "IntegerType.h"
16 #include "AudioOutput.h"
70 enum filter_types { LOWPASS, BANDPASS, HIGHPASS, NOTCH };
74 template<
int8_t FILTER_TYPE,
typename su=u
int8_t>
94 fb = q + ucfxmul(q, (
typename IntegerType<
sizeof(su)+
sizeof(su)>::unsigned_type) SHIFTED_1 + cutoff);
119 fb = q + ucfxmul(q,(
typename IntegerType<
sizeof(su)+
sizeof(su)>::unsigned_type) SHIFTED_1 + cutoff);
128 inline AudioOutputStorage_t
next(AudioOutputStorage_t in)
137 typename IntegerType<
sizeof(su)+
sizeof(su)>::unsigned_type fb;
138 AudioOutputStorage_t buf0, buf1;
139 const uint8_t FX_SHIFT =
sizeof(su) << 3;
140 const uint8_t FX_SHIFT_M_1 = FX_SHIFT-1;
141 const su SHIFTED_1 = (1<<FX_SHIFT)-1;
150 inline void advanceBuffers(AudioOutputStorage_t in)
152 buf0 += fxmul(((in - buf0) + fxmul(fb, buf0 - buf1)), f);
153 buf1 += ifxmul(buf0 - buf1, f);
156 inline AudioOutputStorage_t current(AudioOutputStorage_t in,
Int2Type<LOWPASS>) {
return buf1;}
158 inline AudioOutputStorage_t current(AudioOutputStorage_t in,
Int2Type<HIGHPASS>) {
return in - buf0;}
160 inline AudioOutputStorage_t current(AudioOutputStorage_t in,
Int2Type<BANDPASS>) {
return buf0-buf1;}
162 inline AudioOutputStorage_t current(AudioOutputStorage_t in,
Int2Type<NOTCH>) {
return in - buf0 + buf1;}
165 inline typename IntegerType<
sizeof(su)+
sizeof(su)>::unsigned_type ucfxmul(su a,
typename IntegerType<
sizeof(su)+
sizeof(su)>::unsigned_type b)
167 return (((
typename IntegerType<
sizeof(su)+
sizeof(su)>::unsigned_type)a * (b >> 1)) >> (FX_SHIFT_M_1));
171 inline typename IntegerType<
sizeof(AudioOutputStorage_t)+
sizeof(su)-1>::signed_type ifxmul(
typename IntegerType<
sizeof(AudioOutputStorage_t )+
sizeof(su)-1>::signed_type a, su b) {
return ((a * b) >> FX_SHIFT); }
174 inline typename IntegerType<
sizeof(AudioOutputStorage_t)+
sizeof(AudioOutputStorage_t)>::signed_type fxmul(
typename IntegerType<
sizeof(AudioOutputStorage_t)+
sizeof(AudioOutputStorage_t)>::signed_type a,
typename IntegerType<
sizeof(AudioOutputStorage_t)+
sizeof(su)-1>::signed_type b) {
return ((a * b) >> FX_SHIFT); }
183 template<
typename su=u
int8_t>
190 inline void next (AudioOutputStorage_t in)
213 AudioOutputStorage_t last_in;
A generic filter for audio signals that can produce lowpass, highpass, bandpass and notch outputs at ...
AudioOutputStorage_t high()
Return the input filtered with a highpass filter.
void next(AudioOutputStorage_t in)
Compute the filters, given an input signal.
AudioOutputStorage_t notch()
Return the input filtered with a notch filter.
AudioOutputStorage_t band()
Return the input filtered with a bandpass filter.
AudioOutputStorage_t low()
Return the input filtered with a lowpass filter.
A generic resonant filter for audio signals.
AudioOutputStorage_t next(AudioOutputStorage_t in)
Calculate the next sample, given an input signal.
void setResonance(su resonance)
deprecated.
void setCutoffFreq(su cutoff)
deprecated.
void setCutoffFreqAndResonance(su cutoff, su resonance)
Set the cut off frequency and resonance.
ResonantFilter()
Constructor.
Enables you to instantiate a template based on an integer value.
Provides appropriate integer types that can bit the given number of bytes on this platform (at most 6...