annotate examples/10-Instruments/d-box/Biquad.h @ 556:ce391098f321 prerelease tip

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