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.

RBJ.h 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*******************************************************************************
  2. "A Collection of Useful C++ Classes for Digital Signal Processing"
  3. By Vinnie Falco
  4. Official project location:
  5. https://github.com/vinniefalco/DSPFilters
  6. See Documentation.cpp for contact information, notes, and bibliography.
  7. --------------------------------------------------------------------------------
  8. License: MIT License (http://www.opensource.org/licenses/mit-license.php)
  9. Copyright (c) 2009 by Vinnie Falco
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16. The above copyright notice and this permission notice shall be included in
  17. all copies or substantial portions of the Software.
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. THE SOFTWARE.
  25. *******************************************************************************/
  26. #ifndef DSPFILTERS_RBJ_H
  27. #define DSPFILTERS_RBJ_H
  28. #include "Common.h"
  29. #include "Biquad.h"
  30. #include "Design.h"
  31. #include "Filter.h"
  32. namespace Dsp
  33. {
  34. /*
  35. * Filter realizations based on Robert Bristol-Johnson formulae:
  36. *
  37. * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
  38. *
  39. */
  40. namespace RBJ
  41. {
  42. //
  43. // Raw filters
  44. //
  45. struct LowPass : BiquadBase
  46. {
  47. void setup(double sampleRate, double cutoffFrequency, double q);
  48. };
  49. struct HighPass : BiquadBase
  50. {
  51. void setup(double sampleRate, double cutoffFrequency, double q);
  52. };
  53. struct BandPass1 : BiquadBase
  54. {
  55. // (constant skirt gain, peak gain = Q)
  56. void setup(double sampleRate, double centerFrequency, double bandWidth);
  57. };
  58. struct BandPass2 : BiquadBase
  59. {
  60. // (constant 0 dB peak gain)
  61. void setup(double sampleRate, double centerFrequency, double bandWidth);
  62. };
  63. struct BandStop : BiquadBase
  64. {
  65. void setup(double sampleRate, double centerFrequency, double bandWidth);
  66. };
  67. struct LowShelf : BiquadBase
  68. {
  69. void setup(double sampleRate, double cutoffFrequency, double gainDb, double shelfSlope);
  70. };
  71. struct HighShelf : BiquadBase
  72. {
  73. void setup(double sampleRate, double cutoffFrequency, double gainDb, double shelfSlope);
  74. };
  75. struct BandShelf : BiquadBase
  76. {
  77. void setup(double sampleRate, double centerFrequency, double gainDb, double bandWidth);
  78. };
  79. struct AllPass : BiquadBase
  80. {
  81. void setup(double sampleRate, double phaseFrequency, double q);
  82. };
  83. //------------------------------------------------------------------------------
  84. //
  85. // Gui-friendly Design layer
  86. //
  87. namespace Design
  88. {
  89. struct TypeIBase : DesignBase
  90. {
  91. enum
  92. {
  93. NumParams = 3
  94. };
  95. static int getNumParams() { return 3; }
  96. static ParamInfo getParamInfo_1() { return ParamInfo::defaultCutoffFrequencyParam(); }
  97. static ParamInfo getParamInfo_2() { return ParamInfo::defaultQParam(); }
  98. };
  99. template <class FilterClass>
  100. struct TypeI : TypeIBase, FilterClass
  101. {
  102. void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2]); }
  103. };
  104. struct TypeIIBase : DesignBase
  105. {
  106. enum
  107. {
  108. NumParams = 3
  109. };
  110. static int getNumParams() { return 3; }
  111. static ParamInfo getParamInfo_1() { return ParamInfo::defaultCenterFrequencyParam(); }
  112. static ParamInfo getParamInfo_2() { return ParamInfo::defaultBandwidthParam(); }
  113. };
  114. template <class FilterClass>
  115. struct TypeII : TypeIIBase, FilterClass
  116. {
  117. void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2]); }
  118. };
  119. struct TypeIIIBase : DesignBase
  120. {
  121. enum
  122. {
  123. NumParams = 4
  124. };
  125. static int getNumParams() { return 4; }
  126. static ParamInfo getParamInfo_1() { return ParamInfo::defaultCutoffFrequencyParam(); }
  127. static ParamInfo getParamInfo_2() { return ParamInfo::defaultGainParam(); }
  128. static ParamInfo getParamInfo_3() { return ParamInfo::defaultSlopeParam(); }
  129. };
  130. template <class FilterClass>
  131. struct TypeIII : TypeIIIBase, FilterClass
  132. {
  133. void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2], params[3]); }
  134. };
  135. struct TypeIVBase : DesignBase
  136. {
  137. enum
  138. {
  139. NumParams = 4
  140. };
  141. static int getNumParams() { return 4; }
  142. static ParamInfo getParamInfo_1() { return ParamInfo::defaultCenterFrequencyParam(); }
  143. static ParamInfo getParamInfo_2() { return ParamInfo::defaultGainParam(); }
  144. static ParamInfo getParamInfo_3() { return ParamInfo::defaultBandwidthParam(); }
  145. };
  146. template <class FilterClass>
  147. struct TypeIV : TypeIVBase, FilterClass
  148. {
  149. void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2], params[3]); }
  150. };
  151. //------------------------------------------------------------------------------
  152. struct LowPass : TypeI<RBJ::LowPass>
  153. {
  154. static Kind getKind() { return kindLowPass; }
  155. static const char* getName() { return "RBJ Low Pass"; }
  156. };
  157. struct HighPass : TypeI<RBJ::HighPass>
  158. {
  159. static Kind getKind() { return kindHighPass; }
  160. static const char* getName() { return "RBJ High Pass"; }
  161. };
  162. struct BandPass1 : TypeII<RBJ::BandPass1>
  163. {
  164. static Kind getKind() { return kindBandPass; }
  165. static const char* getName() { return "RBJ Band Pass 1"; }
  166. };
  167. struct BandPass2 : TypeII<RBJ::BandPass2>
  168. {
  169. static Kind getKind() { return kindBandPass; }
  170. static const char* getName() { return "RBJ Band Pass 2"; }
  171. };
  172. struct BandStop : TypeII<RBJ::BandStop>
  173. {
  174. static Kind getKind() { return kindBandStop; }
  175. static const char* getName() { return "RBJ Band Stop"; }
  176. };
  177. struct LowShelf : TypeIII<RBJ::LowShelf>
  178. {
  179. static Kind getKind() { return kindLowShelf; }
  180. static const char* getName() { return "RBJ Low Shelf"; }
  181. };
  182. struct HighShelf : TypeIII<RBJ::HighShelf>
  183. {
  184. static Kind getKind() { return kindHighShelf; }
  185. static const char* getName() { return "RBJ High Shelf"; }
  186. };
  187. struct BandShelf : TypeIV<RBJ::BandShelf>
  188. {
  189. static Kind getKind() { return kindBandShelf; }
  190. static const char* getName() { return "RBJ Band Shelf"; }
  191. };
  192. struct AllPass : TypeI<RBJ::AllPass>
  193. {
  194. static Kind getKind() { return kindOther; }
  195. static const char* getName() { return "RBJ All Pass"; }
  196. };
  197. } // namespace Design
  198. } // namespace RBJ
  199. }
  200. #endif