123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- /*******************************************************************************
-
- "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_BESSEL_H
- #define DSPFILTERS_BESSEL_H
-
- #include "Common.h"
- #include "Cascade.h"
- #include "Design.h"
- #include "Filter.h"
- #include "PoleFilter.h"
- #include "RootFinder.h"
-
- namespace Dsp
- {
-
- /*
- * Filters with Bessel response characteristics
- *
- */
-
- namespace Bessel
- {
-
- // A Workspace is necessary to find roots
-
- struct WorkspaceBase
- {
- WorkspaceBase(RootFinderBase* rootsBase)
- : roots(*rootsBase) { }
-
- RootFinderBase& roots;
-
- private:
- WorkspaceBase(WorkspaceBase&);
- WorkspaceBase& operator=(WorkspaceBase&);
- };
-
- template <int MaxOrder>
- struct Workspace : WorkspaceBase
- {
- Workspace() : WorkspaceBase(&m_roots) { }
-
- private:
- RootFinder<MaxOrder> m_roots;
- };
-
- //------------------------------------------------------------------------------
-
- // Half-band analog prototypes (s-plane)
-
- class AnalogLowPass : public LayoutBase
- {
- public:
- AnalogLowPass() : m_numPoles(-1) { setNormal(0, 1); }
-
- void design(int numPoles, WorkspaceBase* w);
-
- private:
- int m_numPoles = 0;
- };
-
- //------------------------------------------------------------------------------
-
- class AnalogLowShelf : public LayoutBase
- {
- public:
- AnalogLowShelf();
-
- void design(int numPoles, double gainDb, WorkspaceBase* w);
-
- private:
- int m_numPoles = 0;
- double m_gainDb = 0;
- };
-
- //------------------------------------------------------------------------------
-
- // Factored implementations to reduce template instantiations
-
- struct LowPassBase : PoleFilterBase<AnalogLowPass>
- {
- void setup(int order, double sampleRate, double cutoffFrequency, WorkspaceBase* w);
- };
-
- struct HighPassBase : PoleFilterBase<AnalogLowPass>
- {
- void setup(int order, double sampleRate, double cutoffFrequency, WorkspaceBase* w);
- };
-
- struct BandPassBase : PoleFilterBase<AnalogLowPass>
- {
- void setup(int order, double sampleRate, double centerFrequency, double widthFrequency, WorkspaceBase* w);
- };
-
- struct BandStopBase : PoleFilterBase<AnalogLowPass>
- {
- void setup(int order, double sampleRate, double centerFrequency, double widthFrequency, WorkspaceBase* w);
- };
-
- struct LowShelfBase : PoleFilterBase<AnalogLowShelf>
- {
- void setup(int order, double sampleRate, double cutoffFrequency, double gainDb, WorkspaceBase* w);
- };
-
- //------------------------------------------------------------------------------
-
- //
- // Raw filters
- //
-
- template <int MaxOrder>
- struct LowPass : PoleFilter<LowPassBase, MaxOrder>
- {
- void setup(int order, double sampleRate, double cutoffFrequency)
- {
- Workspace<MaxOrder> w;
- LowPassBase::setup(order, sampleRate, cutoffFrequency, &w);
- }
- };
-
- template <int MaxOrder>
- struct HighPass : PoleFilter<HighPassBase, MaxOrder>
- {
- void setup(int order, double sampleRate, double cutoffFrequency)
- {
- Workspace<MaxOrder> w;
- HighPassBase::setup(order, sampleRate, cutoffFrequency, &w);
- }
- };
-
- template <int MaxOrder>
- struct BandPass : PoleFilter<BandPassBase, MaxOrder, MaxOrder * 2>
- {
- void setup(int order, double sampleRate, double centerFrequency, double widthFrequency)
- {
- Workspace<MaxOrder> w;
- BandPassBase::setup(order, sampleRate, centerFrequency, widthFrequency, &w);
- }
- };
-
- template <int MaxOrder>
- struct BandStop : PoleFilter<BandStopBase, MaxOrder, MaxOrder * 2>
- {
- void setup(int order, double sampleRate, double centerFrequency, double widthFrequency)
- {
- Workspace<MaxOrder> w;
- BandStopBase::setup(order, sampleRate, centerFrequency, widthFrequency, &w);
- }
- };
-
- template <int MaxOrder>
- struct LowShelf : PoleFilter<LowShelfBase, MaxOrder, MaxOrder * 2>
- {
- void setup(int order, double sampleRate, double cutoffFrequency, double gainDb)
- {
- Workspace<MaxOrder> w;
- LowShelfBase::setup(order, sampleRate, cutoffFrequency, gainDb, &w);
- }
- };
-
- //------------------------------------------------------------------------------
-
- //
- // Gui-friendly Design layer
- //
-
- namespace Design
- {
- struct TypeIBase : DesignBase
- {
- enum
- {
- NumParams = 3
- };
-
- static int getNumParams() { return 3; }
-
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultCutoffFrequencyParam(); }
- };
-
- template <class FilterClass>
- struct TypeI : TypeIBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2]); }
- };
-
- struct TypeIIBase : DesignBase
- {
- enum
- {
- NumParams = 4
- };
-
- static int getNumParams() { return 4; }
-
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultCenterFrequencyParam(); }
-
- static ParamInfo getParamInfo_3() { return ParamInfo::defaultBandwidthHzParam(); }
- };
-
- template <class FilterClass>
- struct TypeII : TypeIIBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3]); }
- };
-
- struct TypeIIIBase : DesignBase
- {
- enum
- {
- NumParams = 4
- };
-
- static int getNumParams() { return 4; }
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultCutoffFrequencyParam(); }
- static ParamInfo getParamInfo_3() { return ParamInfo::defaultGainParam(); }
- };
-
- template <class FilterClass>
- struct TypeIII : TypeIIIBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3]); }
- };
-
- struct TypeIVBase : DesignBase
- {
- enum
- {
- NumParams = 5
- };
-
- static int getNumParams() { return 5; }
- static ParamInfo getParamInfo_2() { return ParamInfo::defaultCenterFrequencyParam(); }
- static ParamInfo getParamInfo_3() { return ParamInfo::defaultBandwidthHzParam(); }
- static ParamInfo getParamInfo_4() { return ParamInfo::defaultGainParam(); }
- };
-
- template <class FilterClass>
- struct TypeIV : TypeIVBase, FilterClass
- {
- void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3], params[4]); }
- };
-
- // Factored kind and name
-
- struct LowPassDescription
- {
- static Kind getKind() { return kindLowPass; }
- static const char* getName() { return "Bessel Low Pass"; }
- };
-
- struct HighPassDescription
- {
- static Kind getKind() { return kindHighPass; }
- static const char* getName() { return "Bessel High Pass"; }
- };
-
- struct BandPassDescription
- {
- static Kind getKind() { return kindHighPass; }
- static const char* getName() { return "Bessel Band Pass"; }
- };
-
- struct BandStopDescription
- {
- static Kind getKind() { return kindHighPass; }
- static const char* getName() { return "Bessel Band Stop"; }
- };
-
- struct LowShelfDescription
- {
- static Kind getKind() { return kindLowShelf; }
- static const char* getName() { return "Bessel Low Shelf"; }
- };
-
- // This glues on the Order parameter
- template <int MaxOrder, template <class> class TypeClass, template <int> class FilterClass>
- struct OrderBase : TypeClass<FilterClass<MaxOrder>>
- {
- const ParamInfo getParamInfo_1() const
- {
- return ParamInfo(idOrder, "Order", "Order", 1, MaxOrder, 2, &ParamInfo::Int_toControlValue, &ParamInfo::Int_toNativeValue,
- &ParamInfo::Int_toString);
- }
- };
-
- //------------------------------------------------------------------------------
-
- //
- // Gui-friendly Design layer
- //
-
- template <int MaxOrder>
- struct LowPass : OrderBase<MaxOrder, TypeI, Bessel::LowPass>, LowPassDescription {};
-
- template <int MaxOrder>
- struct HighPass : OrderBase<MaxOrder, TypeI, Bessel::HighPass>, HighPassDescription {};
-
- template <int MaxOrder>
- struct BandPass : OrderBase<MaxOrder, TypeII, Bessel::BandPass>, BandPassDescription {};
-
- template <int MaxOrder>
- struct BandStop : OrderBase<MaxOrder, TypeII, Bessel::BandStop>, BandStopDescription {};
-
- /*
- * NOT IMPLEMENTED
- *
- */
- template <int MaxOrder>
- struct LowShelf : OrderBase<MaxOrder, TypeIII, Bessel::LowShelf>, LowShelfDescription {};
- } // namespace Design
- } // namespace Bessel
- } // namespace Dsp
-
- #endif
-
- /* This is a test of svn:external */
|