|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /*******************************************************************************
-
- "A Collection of Useful C++ Classes for Digital Signal Processing"
- By Vinnie Falco
-
- Official project location:
- https://github.com/vinniefalco/DSPFilters
-
- See Documentation.cpp for contact information, notes, and bibliography.
-
- --------------------------------------------------------------------------------
-
- License: MIT License (http://www.opensource.org/licenses/mit-license.php)
- Copyright (c) 2009 by Vinnie Falco
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
- *******************************************************************************/
-
- #ifndef DSPFILTERS_RBJ_H
- #define DSPFILTERS_RBJ_H
-
- #include "Common.h"
- #include "Biquad.h"
- #include "Design.h"
- #include "Filter.h"
-
- namespace Dsp
- {
-
- /*
- * Filter realizations based on Robert Bristol-Johnson formulae:
- *
- * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
- *
- */
-
- namespace RBJ
- {
-
- //
- // Raw filters
- //
-
- struct LowPass : BiquadBase
- {
- void setup(double sampleRate, double cutoffFrequency, double q);
- };
-
- struct HighPass : BiquadBase
- {
- void setup(double sampleRate, double cutoffFrequency, double q);
- };
-
- struct BandPass1 : BiquadBase
- {
- // (constant skirt gain, peak gain = Q)
- void setup(double sampleRate, double centerFrequency, double bandWidth);
- };
-
- struct BandPass2 : BiquadBase
- {
- // (constant 0 dB peak gain)
- void setup(double sampleRate, double centerFrequency, double bandWidth);
- };
-
- struct BandStop : BiquadBase
- {
- void setup(double sampleRate, double centerFrequency, double bandWidth);
- };
-
- struct LowShelf : BiquadBase
- {
- void setup(double sampleRate, double cutoffFrequency, double gainDb, double shelfSlope);
- };
-
- struct HighShelf : BiquadBase
- {
- void setup(double sampleRate, double cutoffFrequency, double gainDb, double shelfSlope);
- };
-
- struct BandShelf : BiquadBase
- {
- void setup(double sampleRate, double centerFrequency, double gainDb, double bandWidth);
- };
-
- struct AllPass : BiquadBase
- {
- void setup(double sampleRate, double phaseFrequency, double q);
- };
-
- //------------------------------------------------------------------------------
-
- //
- // Gui-friendly Design layer
- //
-
- namespace Design
- {
- struct TypeIBase : DesignBase
- {
- enum
- {
- NumParams = 3
- };
-
- static int getNumParams() { return 3; }
- static ParamInfo getParamInfo_1() { return ParamInfo::defaultCutoffFrequencyParam(); }
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultQParam(); }
- };
-
- template <class FilterClass>
- struct TypeI : TypeIBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2]); }
- };
-
- struct TypeIIBase : DesignBase
- {
- enum
- {
- NumParams = 3
- };
-
- static int getNumParams() { return 3; }
- static ParamInfo getParamInfo_1() { return ParamInfo::defaultCenterFrequencyParam(); }
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultBandwidthParam(); }
- };
-
- template <class FilterClass>
- struct TypeII : TypeIIBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2]); }
- };
-
- struct TypeIIIBase : DesignBase
- {
- enum
- {
- NumParams = 4
- };
-
- static int getNumParams() { return 4; }
- static ParamInfo getParamInfo_1() { return ParamInfo::defaultCutoffFrequencyParam(); }
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultGainParam(); }
- static ParamInfo getParamInfo_3() { return ParamInfo::defaultSlopeParam(); }
- };
-
- template <class FilterClass>
- struct TypeIII : TypeIIIBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2], params[3]); }
- };
-
- struct TypeIVBase : DesignBase
- {
- enum
- {
- NumParams = 4
- };
-
- static int getNumParams() { return 4; }
- static ParamInfo getParamInfo_1() { return ParamInfo::defaultCenterFrequencyParam(); }
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultGainParam(); }
- static ParamInfo getParamInfo_3() { return ParamInfo::defaultBandwidthParam(); }
- };
-
- template <class FilterClass>
- struct TypeIV : TypeIVBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(params[0], params[1], params[2], params[3]); }
- };
-
- //------------------------------------------------------------------------------
-
- struct LowPass : TypeI<RBJ::LowPass>
- {
- static Kind getKind() { return kindLowPass; }
- static const char* getName() { return "RBJ Low Pass"; }
- };
-
- struct HighPass : TypeI<RBJ::HighPass>
- {
- static Kind getKind() { return kindHighPass; }
- static const char* getName() { return "RBJ High Pass"; }
- };
-
- struct BandPass1 : TypeII<RBJ::BandPass1>
- {
- static Kind getKind() { return kindBandPass; }
- static const char* getName() { return "RBJ Band Pass 1"; }
- };
-
- struct BandPass2 : TypeII<RBJ::BandPass2>
- {
- static Kind getKind() { return kindBandPass; }
- static const char* getName() { return "RBJ Band Pass 2"; }
- };
-
- struct BandStop : TypeII<RBJ::BandStop>
- {
- static Kind getKind() { return kindBandStop; }
- static const char* getName() { return "RBJ Band Stop"; }
- };
-
- struct LowShelf : TypeIII<RBJ::LowShelf>
- {
- static Kind getKind() { return kindLowShelf; }
- static const char* getName() { return "RBJ Low Shelf"; }
- };
-
- struct HighShelf : TypeIII<RBJ::HighShelf>
- {
- static Kind getKind() { return kindHighShelf; }
- static const char* getName() { return "RBJ High Shelf"; }
- };
-
- struct BandShelf : TypeIV<RBJ::BandShelf>
- {
- static Kind getKind() { return kindBandShelf; }
- static const char* getName() { return "RBJ Band Shelf"; }
- };
-
- struct AllPass : TypeI<RBJ::AllPass>
- {
- static Kind getKind() { return kindOther; }
- static const char* getName() { return "RBJ All Pass"; }
- };
- } // namespace Design
- } // namespace RBJ
- }
-
- #endif
|