Biquad filter library in C++ template form. On mbed LPC1768, can run about 100K operations per second with double precision float, or about 200K with single precision float.
biquad.h
- Committer:
- mhowellaz
- Date:
- 2012-02-14
- Revision:
- 0:f8ed62dbacbc
- Child:
- 1:9c0546cd518e
File content as of revision 0:f8ed62dbacbc:
/* * biquad.cpp * * Original source material from Robert Bristow Johnson at * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt * * Derived from public domain C implementation by Tom St. Denis * * Thanks gents! * * C++-ification by Mark J. Howell * */ #include <math.h> #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif #ifndef M_PI #define M_PI 3.14159265358979323846 #endif /* filter types */ typedef enum { LPF, /* low pass filter */ HPF, /* High pass filter */ BPF, /* band pass filter */ NOTCH, /* Notch Filter */ PEQ, /* Peaking band EQ filter */ LSH, /* Low shelf filter */ HSH /* High shelf filter */ } BIQUAD_FILTER_TYPE; template <typename T> class Biquad { public: Biquad(BIQUAD_FILTER_TYPE type, T dbGain, /* gain of filter */ T freq, /* center frequency */ T srate, /* sampling rate */ T bandwidth); /* bandwidth in octaves */ void Reset(BIQUAD_FILTER_TYPE type, T dbGain, T freq, T srate, T bandwidth); T Calculate(T sample); T a0, a1, a2, a3, a4; T x1, x2, y1, y2; };