robert@464: // robert@464: // Biquad.h robert@464: // robert@464: // Created by Nigel Redmon on 11/24/12 robert@464: // EarLevel Engineering: earlevel.com robert@464: // Copyright 2012 Nigel Redmon robert@464: // robert@464: // For a complete explanation of the Biquad code: robert@464: // http://www.earlevel.com/main/2012/11/25/biquad-c-source-code/ robert@464: // robert@464: // License: robert@464: // robert@464: // This source code is provided as is, without warranty. robert@464: // You may copy and distribute verbatim copies of this document. robert@464: // You may modify and use this source code to create binary code robert@464: // for your own purposes, free or commercial. robert@464: // robert@464: robert@464: #ifndef Biquad_h robert@464: #define Biquad_h robert@464: robert@464: enum { robert@464: bq_type_lowpass = 0, robert@464: bq_type_highpass, robert@464: bq_type_bandpass, robert@464: bq_type_notch, robert@464: bq_type_peak, robert@464: bq_type_lowshelf, robert@464: bq_type_highshelf robert@464: }; robert@464: robert@464: class Biquad { robert@464: public: robert@464: Biquad(); robert@464: Biquad(int type, double Fc, double Q, double peakGainDB); robert@464: ~Biquad(); robert@464: void setType(int type); robert@464: void setQ(double Q); robert@464: void setFc(double Fc); robert@464: void setPeakGain(double peakGainDB); robert@464: void setBiquad(int type, double Fc, double Q, double peakGain); robert@464: float process(float in); robert@464: robert@464: double getQ(); robert@464: double getFc(); robert@464: double getPeakGain(); robert@464: robert@464: double getStartingQ(); robert@464: double getStartingFc(); robert@464: double getStartingPeakGain(); robert@464: robert@464: protected: robert@464: void calcBiquad(void); robert@464: robert@464: int type; robert@464: double a0, a1, a2, b1, b2; robert@464: double Fc, Q, peakGain; robert@464: double startFc, startQ, startPeakGain; robert@464: double z1, z2; robert@464: }; robert@464: robert@464: inline double Biquad::getQ() robert@464: { robert@464: return Q; robert@464: } robert@464: robert@464: inline double Biquad::getFc() robert@464: { robert@464: return Fc; robert@464: } robert@464: robert@464: inline double Biquad::getPeakGain() robert@464: { robert@464: return peakGain; robert@464: } robert@464: robert@464: inline double Biquad::getStartingQ() robert@464: { robert@464: return startQ; robert@464: } robert@464: robert@464: inline double Biquad::getStartingFc() robert@464: { robert@464: return startFc; robert@464: } robert@464: robert@464: inline double Biquad::getStartingPeakGain() robert@464: { robert@464: return startPeakGain; robert@464: } robert@464: robert@464: inline float Biquad::process(float in) { robert@464: double out = in * a0 + z1; robert@464: z1 = in * a1 + z2 - b1 * out; robert@464: z2 = in * a2 - b2 * out; robert@464: return out; robert@464: } robert@464: robert@464: #endif // Biquad_h