Open Ephys GUI
 All Classes Functions Variables
RBJ.h
1 /*******************************************************************************
2 
3 "A Collection of Useful C++ Classes for Digital Signal Processing"
4  By Vincent Falco
5 
6 Official project location:
7 http://code.google.com/p/dspfilterscpp/
8 
9 See Documentation.cpp for contact information, notes, and bibliography.
10 
11 --------------------------------------------------------------------------------
12 
13 License: MIT License (http://www.opensource.org/licenses/mit-license.php)
14 Copyright (c) 2009 by Vincent Falco
15 
16 Permission is hereby granted, free of charge, to any person obtaining a copy
17 of this software and associated documentation files (the "Software"), to deal
18 in the Software without restriction, including without limitation the rights
19 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 copies of the Software, and to permit persons to whom the Software is
21 furnished to do so, subject to the following conditions:
22 
23 The above copyright notice and this permission notice shall be included in
24 all copies or substantial portions of the Software.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 THE SOFTWARE.
33 
34 *******************************************************************************/
35 
36 #ifndef DSPFILTERS_RBJ_H
37 #define DSPFILTERS_RBJ_H
38 
39 #include "Common.h"
40 #include "Biquad.h"
41 #include "Design.h"
42 #include "Filter.h"
43 
44 namespace Dsp {
45 
46 /*
47  * Filter realizations based on Robert Bristol-Johnson formulae:
48  *
49  * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
50  *
51  */
52 
53 namespace RBJ {
54 
55 //
56 // Raw filters
57 //
58 
60 {
61  void setup (double sampleRate,
62  double cutoffFrequency,
63  double q);
64 };
65 
67 {
68  void setup (double sampleRate,
69  double cutoffFrequency,
70  double q);
71 };
72 
74 {
75  // (constant skirt gain, peak gain = Q)
76  void setup (double sampleRate,
77  double centerFrequency,
78  double bandWidth);
79 };
80 
82 {
83  // (constant 0 dB peak gain)
84  void setup (double sampleRate,
85  double centerFrequency,
86  double bandWidth);
87 };
88 
90 {
91  void setup (double sampleRate,
92  double centerFrequency,
93  double bandWidth);
94 };
95 
97 {
98  void setup (double sampleRate,
99  double cutoffFrequency,
100  double gainDb,
101  double shelfSlope);
102 };
103 
105 {
106  void setup (double sampleRate,
107  double cutoffFrequency,
108  double gainDb,
109  double shelfSlope);
110 };
111 
113 {
114  void setup (double sampleRate,
115  double centerFrequency,
116  double gainDb,
117  double bandWidth);
118 };
119 
121 {
122  void setup (double sampleRate,
123  double phaseFrequency,
124  double q);
125 };
126 
127 //------------------------------------------------------------------------------
128 
129 //
130 // Gui-friendly Design layer
131 //
132 
133 namespace Design {
134 
136 {
137  enum
138  {
139  NumParams = 3
140  };
141 
142  static int getNumParams ()
143  {
144  return 3;
145  }
146 
147  static const ParamInfo getParamInfo_1 ()
148  {
149  return ParamInfo::defaultCutoffFrequencyParam ();
150  }
151 
152  static const ParamInfo getParamInfo_2 ()
153  {
154  return ParamInfo::defaultQParam ();
155  }
156 };
157 
158 template <class FilterClass>
159 struct TypeI : TypeIBase, FilterClass
160 {
161  void setParams (const Params& params)
162  {
163  FilterClass::setup (params[0], params[1], params[2]);
164  }
165 };
166 
168 {
169  enum
170  {
171  NumParams = 3
172  };
173 
174  static int getNumParams ()
175  {
176  return 3;
177  }
178 
179  static const ParamInfo getParamInfo_1 ()
180  {
181  return ParamInfo::defaultCenterFrequencyParam ();
182  }
183 
184  static const ParamInfo getParamInfo_2 ()
185  {
186  return ParamInfo::defaultBandwidthParam ();
187  }
188 };
189 
190 template <class FilterClass>
191 struct TypeII : TypeIIBase, FilterClass
192 {
193  void setParams (const Params& params)
194  {
195  FilterClass::setup (params[0], params[1], params[2]);
196  }
197 };
198 
200 {
201  enum
202  {
203  NumParams = 4
204  };
205 
206  static int getNumParams ()
207  {
208  return 4;
209  }
210 
211  static const ParamInfo getParamInfo_1 ()
212  {
213  return ParamInfo::defaultCutoffFrequencyParam ();
214  }
215 
216  static const ParamInfo getParamInfo_2 ()
217  {
218  return ParamInfo::defaultGainParam ();
219  }
220 
221  static const ParamInfo getParamInfo_3 ()
222  {
223  return ParamInfo::defaultSlopeParam ();
224  }
225 };
226 
227 template <class FilterClass>
228 struct TypeIII : TypeIIIBase, FilterClass
229 {
230  void setParams (const Params& params)
231  {
232  FilterClass::setup (params[0], params[1], params[2], params[3]);
233  }
234 };
235 
237 {
238  enum
239  {
240  NumParams = 4
241  };
242 
243  static int getNumParams ()
244  {
245  return 4;
246  }
247 
248  static const ParamInfo getParamInfo_1 ()
249  {
250  return ParamInfo::defaultCenterFrequencyParam ();
251  }
252 
253  static const ParamInfo getParamInfo_2 ()
254  {
255  return ParamInfo::defaultGainParam ();
256  }
257 
258  static const ParamInfo getParamInfo_3 ()
259  {
260  return ParamInfo::defaultBandwidthParam ();
261  }
262 };
263 
264 template <class FilterClass>
265 struct TypeIV : TypeIVBase , FilterClass
266 {
267  void setParams (const Params& params)
268  {
269  FilterClass::setup (params[0], params[1], params[2], params[3]);
270  }
271 };
272 
273 //------------------------------------------------------------------------------
274 
275 struct LowPass : TypeI <RBJ::LowPass>
276 {
277  static Kind getKind () { return kindLowPass; }
278  static const char* getName() { return "RBJ Low Pass"; }
279 };
280 
281 struct HighPass : TypeI <RBJ::HighPass>
282 {
283  static Kind getKind () { return kindHighPass; }
284  static const char* getName() { return "RBJ High Pass"; }
285 };
286 
287 struct BandPass1 : TypeII <RBJ::BandPass1>
288 {
289  static Kind getKind () { return kindBandPass; }
290  static const char* getName() { return "RBJ Band Pass 1"; }
291 };
292 
293 struct BandPass2 : TypeII <RBJ::BandPass2>
294 {
295  static Kind getKind () { return kindBandPass; }
296  static const char* getName() { return "RBJ Band Pass 2"; }
297 };
298 
299 struct BandStop : TypeII <RBJ::BandStop>
300 {
301  static Kind getKind () { return kindBandStop; }
302  static const char* getName() { return "RBJ Band Stop"; }
303 };
304 
305 struct LowShelf : TypeIII <RBJ::LowShelf>
306 {
307  static Kind getKind () { return kindLowShelf; }
308  static const char* getName() { return "RBJ Low Shelf"; }
309 };
310 
311 struct HighShelf : TypeIII <RBJ::HighShelf>
312 {
313  static Kind getKind () { return kindHighShelf; }
314  static const char* getName() { return "RBJ High Shelf"; }
315 };
316 
317 struct BandShelf : TypeIV <RBJ::BandShelf>
318 {
319  static Kind getKind () { return kindBandShelf; }
320  static const char* getName() { return "RBJ Band Shelf"; }
321 };
322 
323 struct AllPass : TypeI <RBJ::AllPass>
324 {
325  static Kind getKind () { return kindOther; }
326  static const char* getName() { return "RBJ All Pass"; }
327 };
328 
329 }
330 
331 }
332 
333 }
334 
335 #endif