YSE sound engine  1.0
cross platform sound engine
 All Classes Namespaces Functions Pages
filters.hpp
1 /*
2  ==============================================================================
3 
4  filters.hpp
5  Created: 31 Jan 2014 2:53:30pm
6  Author: yvan
7 
8  ==============================================================================
9 */
10 
11 #ifndef FILTERS_H_INCLUDED
12 #define FILTERS_H_INCLUDED
13 
14 #include "sample.hpp"
15 #include "../headers/enums.hpp"
16 
17 namespace YSE {
18  namespace DSP {
19 
20  // base class for all filters - don't use
21  class API filterBase {
22  public:
23  filterBase();
25 
26  virtual AUDIOBUFFER & operator()(AUDIOBUFFER & in) = 0;
27 
28  protected:
29  aFlt freq;
30  aFlt gain;
31  Flt q;
32  Flt last;
33  Flt previous;
34  aFlt coef1, coef2;
35  aFlt ff1, ff2, ff3, fb1, fb2;
36  sample buffer;
37  };
38 
39  /*******************************************************************************************/
40 
41  // highpass filter
42  class API highPass : public filterBase {
43  public:
44  highPass& setFrequency(Flt f);
45  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
46  };
47 
48  /*******************************************************************************************/
49 
50  // lowpass filter
51  class API lowPass : public filterBase {
52  public:
53  lowPass& setFrequency(Flt f);
54  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
55  };
56 
57  /*******************************************************************************************/
58 
59  // bandpass filter
60  class API bandPass : public filterBase {
61  public:
62  bandPass& set(Flt freq, Flt q);
63  bandPass& setFrequency(Flt freq);
64  bandPass& setQ(Flt q);
65  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
66  bandPass();
67 
68  private:
69  void calcCoef();
70  static float qCos(Flt omega);
71  };
72 
73  /*******************************************************************************************/
74 
75  // for visualizing biquad parameters, see: http://www.earlevel.com/main/2010/12/20/biquad-calculator/
76  class API biQuad : public filterBase {
77  public:
78  biQuad& set(BQ_TYPE type, Flt frequency, Flt Q, Flt peakGain = 4);
79  biQuad& setType(BQ_TYPE type);
80  biQuad& setFreq(Flt frequency);
81  biQuad& setQ(Flt Q);
82  biQuad& setPeak(Flt peakGain);
83 
84  // use this for masochism
85  biQuad& setRaw(Flt fb1, Flt fb2, Flt ff1, Flt ff2, Flt ff3);
86  AUDIOBUFFER & operator()(AUDIOBUFFER & in);
87 
88  private:
89  void calc();
90  BQ_TYPE type;
91  };
92 
93  /*******************************************************************************************/
94  class API sampleHold {
95  public:
96  sampleHold& reset(Flt value = 1e20);
97  sampleHold& set(Flt value);
98  AUDIOBUFFER & operator()(AUDIOBUFFER & in, AUDIOBUFFER & signal);
99 
100  sampleHold();
101 
102  private:
103  aFlt lastIn, lastOut;
104  sample buffer;
105  };
106 
107  // looking for vcf? It is in oscillators because it shares a lot of that code
108 
109 
110 
111  }
112 }
113 
114 
115 
116 
117 #endif // FILTERS_H_INCLUDED