You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3KB

  1. //
  2. // Biquad.h
  3. //
  4. // Created by Nigel Redmon on 11/24/12
  5. // EarLevel Engineering: earlevel.com
  6. // Copyright 2012 Nigel Redmon
  7. //
  8. // For a complete explanation of the Biquad code:
  9. // http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
  10. //
  11. // License:
  12. //
  13. // This source code is provided as is, without warranty.
  14. // You may copy and distribute verbatim copies of this document.
  15. // You may modify and use this source code to create binary code
  16. // for your own purposes, free or commercial.
  17. //
  18. #ifndef Biquad_h
  19. #define Biquad_h
  20. namespace rack_plugin_Autodafe {
  21. enum {
  22. bq_type_lowpass = 0,
  23. bq_type_highpass,
  24. bq_type_bandpass,
  25. bq_type_notch,
  26. bq_type_peak,
  27. bq_type_lowshelf,
  28. bq_type_highshelf
  29. };
  30. class Biquad {
  31. public:
  32. Biquad();
  33. Biquad(int type, double Fc, double Q, double peakGainDB);
  34. ~Biquad();
  35. void setType(int type);
  36. void setQ(double Q);
  37. void setFc(double Fc);
  38. void setPeakGain(double peakGainDB);
  39. void setBiquad(int type, double Fc, double Q, double peakGain);
  40. float process(float in);
  41. protected:
  42. void calcBiquad(void);
  43. int type;
  44. double a0, a1, a2, b1, b2;
  45. double Fc, Q, peakGain;
  46. double z1, z2;
  47. };
  48. inline float Biquad::process(float in) {
  49. double out = in * a0 + z1;
  50. z1 = in * a1 + z2 - b1 * out;
  51. z2 = in * a2 - b2 * out;
  52. return out;
  53. }
  54. } // namespace rack_plugin_Autodafe
  55. #endif // Biquad_h