/******************************************************************************* "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. *******************************************************************************/ #pragma once #include "Common.h" #include "Cascade.h" #include "Design.h" #include "Filter.h" #include "PoleFilter.h" namespace Dsp { /* * Filters with Inverse Chebyshev response characteristics * */ namespace ChebyshevII { // Half-band analog prototypes (s-plane) class AnalogLowPass : public LayoutBase { public: AnalogLowPass(); void design(int numPoles, double stopBandDb); private: int m_numPoles = 0; double m_stopBandDb = 0; }; //------------------------------------------------------------------------------ class AnalogLowShelf : public LayoutBase { public: AnalogLowShelf(); void design(int numPoles, double gainDb, double stopBandDb); private: int m_numPoles = 0; double m_stopBandDb = 0; double m_gainDb = 0; }; //------------------------------------------------------------------------------ // Factored implementations to reduce template instantiations struct LowPassBase : PoleFilterBase { void setup(int order, double sampleRate, double cutoffFrequency, double stopBandDb); }; struct HighPassBase : PoleFilterBase { void setup(int order, double sampleRate, double cutoffFrequency, double stopBandDb); }; struct BandPassBase : PoleFilterBase { void setup(int order, double sampleRate, double centerFrequency, double widthFrequency, double stopBandDb); }; struct BandStopBase : PoleFilterBase { void setup(int order, double sampleRate, double centerFrequency, double widthFrequency, double stopBandDb); }; struct LowShelfBase : PoleFilterBase { void setup(int order, double sampleRate, double cutoffFrequency, double gainDb, double stopBandDb); }; struct HighShelfBase : PoleFilterBase { void setup(int order, double sampleRate, double cutoffFrequency, double gainDb, double stopBandDb); }; struct BandShelfBase : PoleFilterBase { void setup(int order, double sampleRate, double centerFrequency, double widthFrequency, double gainDb, double stopBandDb); }; //------------------------------------------------------------------------------ // // Raw filters // template struct LowPass : PoleFilter {}; template struct HighPass : PoleFilter {}; template struct BandPass : PoleFilter {}; template struct BandStop : PoleFilter {}; template struct LowShelf : PoleFilter {}; template struct HighShelf : PoleFilter {}; template struct BandShelf : PoleFilter {}; //------------------------------------------------------------------------------ // // Gui-friendly Design layer // namespace Design { struct TypeIBase : DesignBase { enum { NumParams = 4 }; static int getNumParams() { return 4; } static ParamInfo getParamInfo_2() { return ParamInfo::defaultCutoffFrequencyParam(); } static ParamInfo getParamInfo_3() { return ParamInfo::defaultStopDbParam(); } }; template struct TypeI : TypeIBase, FilterClass { void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3]); } }; struct TypeIIBase : 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::defaultStopDbParam(); } }; template struct TypeII : TypeIIBase, FilterClass { void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3], params[4]); } }; struct TypeIIIBase : DesignBase { enum { NumParams = 5 }; static int getNumParams() { return 5; } static ParamInfo getParamInfo_2() { return ParamInfo::defaultCutoffFrequencyParam(); } static ParamInfo getParamInfo_3() { return ParamInfo::defaultGainParam(); } static ParamInfo getParamInfo_4() { return ParamInfo::defaultStopDbParam(); } }; template struct TypeIII : TypeIIIBase, FilterClass { void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3], params[4]); } }; struct TypeIVBase : DesignBase { enum { NumParams = 6 }; static int getNumParams() { return 6; } static ParamInfo getParamInfo_2() { return ParamInfo::defaultCenterFrequencyParam(); } static ParamInfo getParamInfo_3() { return ParamInfo::defaultBandwidthHzParam(); } static ParamInfo getParamInfo_4() { return ParamInfo::defaultGainParam(); } static ParamInfo getParamInfo_5() { return ParamInfo::defaultStopDbParam(); } }; template struct TypeIV : TypeIVBase, FilterClass { void setParams(const Params& params) { FilterClass::setup(int(params[1]), params[0], params[2], params[3], params[4], params[5]); } }; // Factored kind and name struct LowPassDescription { static Kind getKind() { return kindLowPass; } static const char* getName() { return "Chebyshev II Low Pass"; } }; struct HighPassDescription { static Kind getKind() { return kindHighPass; } static const char* getName() { return "Chebyshev II High Pass"; } }; struct BandPassDescription { static Kind getKind() { return kindHighPass; } static const char* getName() { return "Chebyshev II Band Pass"; } }; struct BandStopDescription { static Kind getKind() { return kindHighPass; } static const char* getName() { return "Chebyshev II Band Stop"; } }; struct LowShelfDescription { static Kind getKind() { return kindLowShelf; } static const char* getName() { return "Chebyshev II Low Shelf"; } }; struct HighShelfDescription { static Kind getKind() { return kindHighShelf; } static const char* getName() { return "Chebyshev II High Shelf"; } }; struct BandShelfDescription { static Kind getKind() { return kindBandShelf; } static const char* getName() { return "Chebyshev II Band Shelf"; } }; // This glues on the Order parameter template class TypeClass, template class FilterClass> struct OrderBase : TypeClass> { ParamInfo getParamInfo_1() const { return ParamInfo(idOrder, "Order", "Order", 1, MaxOrder, 2, &ParamInfo::Int_toControlValue, &ParamInfo::Int_toNativeValue, &ParamInfo::Int_toString); } }; //------------------------------------------------------------------------------ // // Design Filters // template struct LowPass : OrderBase, LowPassDescription {}; template struct HighPass : OrderBase, HighPassDescription {}; template struct BandPass : OrderBase, BandPassDescription {}; template struct BandStop : OrderBase, BandStopDescription {}; template struct LowShelf : OrderBase, LowShelfDescription {}; template struct HighShelf : OrderBase, HighShelfDescription {}; template struct BandShelf : OrderBase, BandShelfDescription {}; } // namespace Design } // namespace ChebyshevII } // namespace Dsp