External plugins for Carla
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.

85 lines
2.8KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Analog Filter.h - Several analog filters (lowpass, highpass...)
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Copyright (C) 2010-2010 Mark McCurry
  6. Author: Nasca Octavian Paul
  7. Mark McCurry
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. */
  13. #ifndef ANALOG_FILTER_H
  14. #define ANALOG_FILTER_H
  15. #include "../globals.h"
  16. #include "Filter.h"
  17. namespace zyncarla {
  18. /**Implementation of Several analog filters (lowpass, highpass...)
  19. * Implemented with IIR filters
  20. * Coefficients generated with "Cookbook formulae for audio EQ"*/
  21. class AnalogFilter:public Filter
  22. {
  23. public:
  24. AnalogFilter(unsigned char Ftype, float Ffreq, float Fq,
  25. unsigned char Fstages, unsigned int srate, int bufsize);
  26. ~AnalogFilter();
  27. void filterout(float *smp);
  28. void setfreq(float frequency);
  29. void setfreq_and_q(float frequency, float q_);
  30. void setq(float q_);
  31. void settype(int type_);
  32. void setgain(float dBgain);
  33. void setstages(int stages_);
  34. void cleanup();
  35. float H(float freq); //Obtains the response for a given frequency
  36. struct Coeff {
  37. float c[3], //Feed Forward
  38. d[3]; //Feed Back
  39. } coeff, oldCoeff;
  40. static Coeff computeCoeff(int type, float cutoff, float q, int stages,
  41. float gain, float fs, int &order);
  42. private:
  43. struct fstage {
  44. float x1, x2; //Input History
  45. float y1, y2; //Output History
  46. } history[MAX_FILTER_STAGES + 1], oldHistory[MAX_FILTER_STAGES + 1];
  47. //old coeffs are used for interpolation when paremeters change quickly
  48. //Apply IIR filter to Samples, with coefficients, and past history
  49. void singlefilterout(float *smp, fstage &hist, const Coeff &coeff);
  50. //Update coeff and order
  51. void computefiltercoefs(void);
  52. int type; //The type of the filter (LPF1,HPF1,LPF2,HPF2...)
  53. int stages; //how many times the filter is applied (0->1,1->2,etc.)
  54. float freq; //Frequency given in Hz
  55. float q; //Q factor (resonance or Q factor)
  56. float gain; //the gain of the filter (if are shelf/peak) filters
  57. int order; //the order of the filter (number of poles)
  58. bool needsinterpolation, //Interpolation between coeff changes
  59. firsttime; //First Iteration of filter
  60. bool abovenq, //if the frequency is above the nyquist
  61. oldabovenq; //if the last time was above nyquist
  62. //(used to see if it needs interpolation)
  63. };
  64. }
  65. #endif