annotate projects/d-box/Biquad.h @ 39:638bc1ae2500 staging

Improved readibility of the DIGITAL code in the PRU, using register names instead of aliases and expanding some of the macros, removing unused macros. Binaries were not modified
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 13 May 2015 12:18:10 +0100
parents 8a575ba3ab52
children
rev   line source
andrewm@0 1 //
andrewm@0 2 // Biquad.h
andrewm@0 3 //
andrewm@0 4 // Created by Nigel Redmon on 11/24/12
andrewm@0 5 // EarLevel Engineering: earlevel.com
andrewm@0 6 // Copyright 2012 Nigel Redmon
andrewm@0 7 //
andrewm@0 8 // For a complete explanation of the Biquad code:
andrewm@0 9 // http://www.earlevel.com/main/2012/11/25/biquad-c-source-code/
andrewm@0 10 //
andrewm@0 11 // License:
andrewm@0 12 //
andrewm@0 13 // This source code is provided as is, without warranty.
andrewm@0 14 // You may copy and distribute verbatim copies of this document.
andrewm@0 15 // You may modify and use this source code to create binary code
andrewm@0 16 // for your own purposes, free or commercial.
andrewm@0 17 //
andrewm@0 18
andrewm@0 19 #ifndef Biquad_h
andrewm@0 20 #define Biquad_h
andrewm@0 21
andrewm@0 22 enum {
andrewm@0 23 bq_type_lowpass = 0,
andrewm@0 24 bq_type_highpass,
andrewm@0 25 bq_type_bandpass,
andrewm@0 26 bq_type_notch,
andrewm@0 27 bq_type_peak,
andrewm@0 28 bq_type_lowshelf,
andrewm@0 29 bq_type_highshelf
andrewm@0 30 };
andrewm@0 31
andrewm@0 32 class Biquad {
andrewm@0 33 public:
andrewm@0 34 Biquad();
andrewm@0 35 Biquad(int type, double Fc, double Q, double peakGainDB);
andrewm@0 36 ~Biquad();
andrewm@0 37 void setType(int type);
andrewm@0 38 void setQ(double Q);
andrewm@0 39 void setFc(double Fc);
andrewm@0 40 void setPeakGain(double peakGainDB);
andrewm@0 41 void setBiquad(int type, double Fc, double Q, double peakGain);
andrewm@0 42 float process(float in);
andrewm@0 43
andrewm@0 44 double getQ();
andrewm@0 45 double getFc();
andrewm@0 46 double getPeakGain();
andrewm@0 47
andrewm@0 48 double getStartingQ();
andrewm@0 49 double getStartingFc();
andrewm@0 50 double getStartingPeakGain();
andrewm@0 51
andrewm@0 52 protected:
andrewm@0 53 void calcBiquad(void);
andrewm@0 54
andrewm@0 55 int type;
andrewm@0 56 double a0, a1, a2, b1, b2;
andrewm@0 57 double Fc, Q, peakGain;
andrewm@0 58 double startFc, startQ, startPeakGain;
andrewm@0 59 double z1, z2;
andrewm@0 60 };
andrewm@0 61
andrewm@0 62 inline double Biquad::getQ()
andrewm@0 63 {
andrewm@0 64 return Q;
andrewm@0 65 }
andrewm@0 66
andrewm@0 67 inline double Biquad::getFc()
andrewm@0 68 {
andrewm@0 69 return Fc;
andrewm@0 70 }
andrewm@0 71
andrewm@0 72 inline double Biquad::getPeakGain()
andrewm@0 73 {
andrewm@0 74 return peakGain;
andrewm@0 75 }
andrewm@0 76
andrewm@0 77 inline double Biquad::getStartingQ()
andrewm@0 78 {
andrewm@0 79 return startQ;
andrewm@0 80 }
andrewm@0 81
andrewm@0 82 inline double Biquad::getStartingFc()
andrewm@0 83 {
andrewm@0 84 return startFc;
andrewm@0 85 }
andrewm@0 86
andrewm@0 87 inline double Biquad::getStartingPeakGain()
andrewm@0 88 {
andrewm@0 89 return startPeakGain;
andrewm@0 90 }
andrewm@0 91
andrewm@0 92 inline float Biquad::process(float in) {
andrewm@0 93 double out = in * a0 + z1;
andrewm@0 94 z1 = in * a1 + z2 - b1 * out;
andrewm@0 95 z2 = in * a2 - b2 * out;
andrewm@0 96 return out;
andrewm@0 97 }
andrewm@0 98
andrewm@0 99 #endif // Biquad_h