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.

Custom.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #pragma once
  27. #include "Common.h"
  28. #include "Biquad.h"
  29. #include "Design.h"
  30. #include "Filter.h"
  31. namespace Dsp
  32. {
  33. /*
  34. * Single pole and Biquad with parameters allowing
  35. * for directly setting the poles and zeros
  36. *
  37. */
  38. namespace Custom
  39. {
  40. //
  41. // Raw filters
  42. //
  43. struct OnePole : Biquad
  44. {
  45. void setup(double scale, double pole, double zero);
  46. };
  47. struct TwoPole : Biquad
  48. {
  49. void setup(double scale, double poleRho, double poleTheta, double zeroRho, double zeroTheta);
  50. };
  51. //------------------------------------------------------------------------------
  52. //
  53. // Gui-friendly Design layer
  54. //
  55. namespace Design
  56. {
  57. struct OnePole : DesignBase, Custom::OnePole
  58. {
  59. enum
  60. {
  61. NumParams = 4
  62. };
  63. static int getNumParams() { return 4; }
  64. static ParamInfo getParamInfo_1() { return ParamInfo::defaultGainParam(); }
  65. static ParamInfo getParamInfo_2() { return ParamInfo::defaultPoleRealParam(); }
  66. static ParamInfo getParamInfo_3() { return ParamInfo::defaultZeroRealParam(); }
  67. static Kind getKind() { return kindOther; }
  68. static const char* getName() { return "Custom One-Pole"; }
  69. void setParams(const Params& params) { setup(pow(10., params[1] / 20), params[2], params[3]); }
  70. };
  71. struct TwoPole : DesignBase, Custom::TwoPole
  72. {
  73. enum
  74. {
  75. NumParams = 6
  76. };
  77. static int getNumParams() { return 6; }
  78. static ParamInfo getParamInfo_1() { return ParamInfo::defaultGainParam(); }
  79. static ParamInfo getParamInfo_2() { return ParamInfo::defaultPoleRhoParam(); }
  80. static ParamInfo getParamInfo_3() { return ParamInfo::defaultPoleThetaParam(); }
  81. static ParamInfo getParamInfo_4() { return ParamInfo::defaultZeroRhoParam(); }
  82. static ParamInfo getParamInfo_5() { return ParamInfo::defaultZeroThetaParam(); }
  83. static Kind getKind() { return kindOther; }
  84. static const char* getName() { return "Custom Two-Pole"; }
  85. void setParams(const Params& params) { setup(pow(10., params[1] / 20), params[2], params[3], params[4], params[5]); }
  86. };
  87. } // namespace Design
  88. } // namespace Custom
  89. } // namespace Dsp