├── .gitignore ├── DSPFilters ├── include │ └── DspFilters │ │ ├── Bessel.h │ │ ├── Biquad.h │ │ ├── Butterworth.h │ │ ├── Cascade.h │ │ ├── ChebyshevI.h │ │ ├── ChebyshevII.h │ │ ├── Common.h │ │ ├── Custom.h │ │ ├── Design.h │ │ ├── Dsp.h │ │ ├── Elliptic.h │ │ ├── Filter.h │ │ ├── Layout.h │ │ ├── Legendre.h │ │ ├── MathSupplement.h │ │ ├── Params.h │ │ ├── PoleFilter.h │ │ ├── RBJ.h │ │ ├── RootFinder.h │ │ ├── SmoothedFilter.h │ │ ├── State.h │ │ ├── Types.h │ │ └── Utilities.h └── source │ ├── Bessel.cpp │ ├── Biquad.cpp │ ├── Butterworth.cpp │ ├── Cascade.cpp │ ├── ChebyshevI.cpp │ ├── ChebyshevII.cpp │ ├── Custom.cpp │ ├── Design.cpp │ ├── Documentation.cpp │ ├── Elliptic.cpp │ ├── Filter.cpp │ ├── Legendre.cpp │ ├── Param.cpp │ ├── PoleFilter.cpp │ ├── RBJ.cpp │ ├── RootFinder.cpp │ └── State.cpp ├── DSPFiltersDemo ├── DSPFilters.jucer └── source │ ├── AudioOutput.cpp │ ├── AudioOutput.h │ ├── BrickWallChart.cpp │ ├── BrickWallChart.h │ ├── Common.h │ ├── ContentComponentConstrainer.h │ ├── CpuMeter.cpp │ ├── CpuMeter.h │ ├── CustomSlider.h │ ├── FilterChart.cpp │ ├── FilterChart.h │ ├── FilterControls.cpp │ ├── FilterControls.h │ ├── FilterListener.h │ ├── FilteringAudioSource.cpp │ ├── FilteringAudioSource.h │ ├── GainChart.cpp │ ├── GainChart.h │ ├── GroupDelayChart.cpp │ ├── GroupDelayChart.h │ ├── MainApp.cpp │ ├── MainApp.h │ ├── MainPanel.cpp │ ├── MainPanel.h │ ├── MainWindow.cpp │ ├── MainWindow.h │ ├── NoiseAudioSource.cpp │ ├── NoiseAudioSource.h │ ├── PhaseChart.cpp │ ├── PhaseChart.h │ ├── PoleZeroChart.cpp │ ├── PoleZeroChart.h │ ├── Precompile.cpp │ ├── ResamplingReader.cpp │ ├── ResamplingReader.h │ ├── ResizableLayout.cpp │ ├── ResizableLayout.h │ ├── SettingsPanel.cpp │ ├── SettingsPanel.h │ ├── SettingsWindow.cpp │ ├── SettingsWindow.h │ ├── SliderGroup.cpp │ ├── SliderGroup.h │ ├── StepResponseChart.cpp │ ├── StepResponseChart.h │ ├── ThreadQueue.cpp │ ├── ThreadQueue.h │ ├── binaries.cpp │ ├── binaries.h │ └── bond.h ├── README.md ├── doc ├── EllipticFilterDesign.pdf ├── LegendreFilterDesign.pdf └── ParametricEqDesign.pdf ├── include └── src /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .waf* 3 | .lock* 4 | .*.sw* 5 | shared/DSPFiltersProjucer/JuceLibraryCode 6 | shared/DSPFiltersProjucer/Builds 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Cascade.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_CASCADE_H 37 | #define DSPFILTERS_CASCADE_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/Biquad.h" 41 | #include "DspFilters/Filter.h" 42 | #include "DspFilters/Layout.h" 43 | #include "DspFilters/MathSupplement.h" 44 | 45 | namespace Dsp { 46 | 47 | /* 48 | * Holds coefficients for a cascade of second order sections. 49 | * 50 | */ 51 | 52 | // Factored implementation to reduce template instantiations 53 | class Cascade 54 | { 55 | public: 56 | template 57 | class StateBase : private DenormalPrevention 58 | { 59 | public: 60 | template 61 | inline Sample process (const Sample in, const Cascade& c) 62 | { 63 | double out = in; 64 | StateType* state = m_stateArray; 65 | Biquad const* stage = c.m_stageArray; 66 | const double vsa = ac(); 67 | int i = c.m_numStages - 1; 68 | out = (state++)->process1 (out, *stage++, vsa); 69 | for (; --i >= 0;) 70 | out = (state++)->process1 (out, *stage++, 0); 71 | //for (int i = c.m_numStages; --i >= 0; ++state, ++stage) 72 | // out = state->process1 (out, *stage, vsa); 73 | return static_cast (out); 74 | } 75 | 76 | protected: 77 | StateBase (StateType* stateArray) 78 | : m_stateArray (stateArray) 79 | { 80 | } 81 | 82 | protected: 83 | StateType* m_stateArray; 84 | }; 85 | 86 | struct Stage : Biquad 87 | { 88 | }; 89 | 90 | struct Storage 91 | { 92 | Storage (int maxStages_, Stage* stageArray_) 93 | : maxStages (maxStages_) 94 | , stageArray (stageArray_) 95 | { 96 | } 97 | 98 | int maxStages; 99 | Stage* stageArray; 100 | }; 101 | 102 | int getNumStages () const 103 | { 104 | return m_numStages; 105 | } 106 | 107 | const Stage& operator[] (int index) 108 | { 109 | assert (index >= 0 && index <= m_numStages); 110 | return m_stageArray[index]; 111 | } 112 | 113 | public: 114 | // Calculate filter response at the given normalized frequency. 115 | complex_t response (double normalizedFrequency) const; 116 | 117 | std::vector getPoleZeros () const; 118 | 119 | // Process a block of samples in the given form 120 | template 121 | void process (int numSamples, Sample* dest, StateType& state) const 122 | { 123 | while (--numSamples >= 0) { 124 | *dest = state.process (*dest, *this); 125 | dest++; 126 | } 127 | } 128 | 129 | protected: 130 | Cascade (); 131 | 132 | void setCascadeStorage (const Storage& storage); 133 | 134 | void applyScale (double scale); 135 | void setLayout (const LayoutBase& proto); 136 | 137 | private: 138 | int m_numStages; 139 | int m_maxStages; 140 | Stage* m_stageArray; 141 | }; 142 | 143 | //------------------------------------------------------------------------------ 144 | 145 | // Storage for Cascade 146 | template 147 | class CascadeStages 148 | { 149 | public: 150 | template 151 | class State : public Cascade::StateBase 152 | { 153 | public: 154 | State() : Cascade::StateBase (m_states) 155 | { 156 | Cascade::StateBase ::m_stateArray = m_states; 157 | reset (); 158 | } 159 | 160 | void reset () 161 | { 162 | StateType* state = m_states; 163 | for (int i = MaxStages; --i >= 0; ++state) 164 | state->reset(); 165 | } 166 | 167 | private: 168 | StateType m_states[MaxStages]; 169 | }; 170 | 171 | /*@Internal*/ 172 | Cascade::Storage getCascadeStorage() 173 | { 174 | return Cascade::Storage (MaxStages, m_stages); 175 | } 176 | 177 | private: 178 | Cascade::Stage m_stages[MaxStages]; 179 | }; 180 | 181 | } 182 | 183 | #endif 184 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Common.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_COMMON_H 37 | #define DSPFILTERS_COMMON_H 38 | 39 | // 40 | // This must be the first file included in every DspFilters header and source 41 | // 42 | 43 | #ifdef _MSC_VER 44 | # pragma warning (disable: 4100) 45 | #endif 46 | 47 | //#include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | 60 | #ifdef _MSC_VER 61 | namespace tr1 = std; 62 | #else 63 | namespace tr1 = std; 64 | #endif 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Custom.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_CUSTOM_H 37 | #define DSPFILTERS_CUSTOM_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/Biquad.h" 41 | #include "DspFilters/Design.h" 42 | #include "DspFilters/Filter.h" 43 | 44 | namespace Dsp { 45 | 46 | /* 47 | * Single pole and Biquad with parameters allowing 48 | * for directly setting the poles and zeros 49 | * 50 | */ 51 | 52 | namespace Custom { 53 | 54 | // 55 | // Raw filters 56 | // 57 | 58 | struct OnePole : Biquad 59 | { 60 | void setup (double scale, 61 | double pole, 62 | double zero); 63 | }; 64 | 65 | struct TwoPole : Biquad 66 | { 67 | void setup (double scale, 68 | double poleRho, 69 | double poleTheta, 70 | double zeroRho, 71 | double zeroTheta); 72 | }; 73 | 74 | //------------------------------------------------------------------------------ 75 | 76 | // 77 | // Gui-friendly Design layer 78 | // 79 | 80 | namespace Design { 81 | 82 | struct OnePole : DesignBase, Custom::OnePole 83 | { 84 | enum 85 | { 86 | NumParams = 4 87 | }; 88 | 89 | static int getNumParams () 90 | { 91 | return 4; 92 | } 93 | 94 | static const ParamInfo getParamInfo_1 () 95 | { 96 | return ParamInfo::defaultGainParam (); 97 | } 98 | 99 | static const ParamInfo getParamInfo_2 () 100 | { 101 | return ParamInfo::defaultPoleRealParam (); 102 | } 103 | 104 | static const ParamInfo getParamInfo_3 () 105 | { 106 | return ParamInfo::defaultZeroRealParam (); 107 | } 108 | 109 | static Kind getKind () { return kindOther; } 110 | static const char* getName() { return "Custom One-Pole"; } 111 | 112 | void setParams (const Params& params) 113 | { 114 | setup (pow (10., params[1]/20), 115 | params[2], 116 | params[3]); 117 | } 118 | }; 119 | 120 | struct TwoPole : DesignBase, Custom::TwoPole 121 | { 122 | enum 123 | { 124 | NumParams = 6 125 | }; 126 | 127 | static int getNumParams () 128 | { 129 | return 6; 130 | } 131 | 132 | static const ParamInfo getParamInfo_1 () 133 | { 134 | return ParamInfo::defaultGainParam (); 135 | } 136 | 137 | static const ParamInfo getParamInfo_2 () 138 | { 139 | return ParamInfo::defaultPoleRhoParam (); 140 | } 141 | 142 | static const ParamInfo getParamInfo_3 () 143 | { 144 | return ParamInfo::defaultPoleThetaParam (); 145 | } 146 | 147 | static const ParamInfo getParamInfo_4 () 148 | { 149 | return ParamInfo::defaultZeroRhoParam (); 150 | } 151 | 152 | static const ParamInfo getParamInfo_5 () 153 | { 154 | return ParamInfo::defaultZeroThetaParam (); 155 | } 156 | 157 | 158 | static Kind getKind () { return kindOther; } 159 | static const char* getName() { return "Custom Two-Pole"; } 160 | 161 | void setParams (const Params& params) 162 | { 163 | setup (pow (10., params[1]/20), 164 | params[2], 165 | params[3], 166 | params[4], 167 | params[5]); 168 | } 169 | }; 170 | 171 | } 172 | 173 | } 174 | 175 | } 176 | 177 | #endif 178 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Design.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_DESIGN_H 37 | #define DSPFILTERS_DESIGN_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/Params.h" 41 | 42 | namespace Dsp { 43 | 44 | struct DesignBase 45 | { 46 | // Sampling rate is the first param for every Design filter 47 | static const ParamInfo getParamInfo_0 () 48 | { 49 | return ParamInfo::defaultSampleRateParam (); 50 | } 51 | 52 | // These should never get called 53 | static const ParamInfo getParamInfo_1 () { return ParamInfo(); } 54 | static const ParamInfo getParamInfo_2 () { return ParamInfo(); } 55 | static const ParamInfo getParamInfo_3 () { return ParamInfo(); } 56 | static const ParamInfo getParamInfo_4 () { return ParamInfo(); } 57 | static const ParamInfo getParamInfo_5 () { return ParamInfo(); } 58 | static const ParamInfo getParamInfo_6 () { return ParamInfo(); } 59 | static const ParamInfo getParamInfo_7 () { return ParamInfo(); } 60 | }; 61 | 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Dsp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_DSP_H 37 | #define DSPFILTERS_DSP_H 38 | 39 | // 40 | // Include this file in your application to get everything 41 | // 42 | 43 | #include "DspFilters/Common.h" 44 | 45 | #include "DspFilters/Biquad.h" 46 | #include "DspFilters/Cascade.h" 47 | #include "DspFilters/Filter.h" 48 | #include "DspFilters/PoleFilter.h" 49 | #include "DspFilters/SmoothedFilter.h" 50 | #include "DspFilters/State.h" 51 | #include "DspFilters/Utilities.h" 52 | 53 | #include "DspFilters/Bessel.h" 54 | #include "DspFilters/Butterworth.h" 55 | #include "DspFilters/ChebyshevI.h" 56 | #include "DspFilters/ChebyshevII.h" 57 | #include "DspFilters/Custom.h" 58 | #include "DspFilters/Elliptic.h" 59 | #include "DspFilters/Legendre.h" 60 | #include "DspFilters/RBJ.h" 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Layout.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_LAYOUT_H 37 | #define DSPFILTERS_LAYOUT_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/MathSupplement.h" 41 | 42 | namespace Dsp { 43 | 44 | // 45 | // Describes a filter as a collection of poles and zeros along with 46 | // normalization information to achieve a specified gain at a specified 47 | // frequency. The poles and zeros may lie either in the s or the z plane. 48 | // 49 | 50 | // Base uses pointers to reduce template instantiations 51 | class LayoutBase 52 | { 53 | public: 54 | LayoutBase () 55 | : m_numPoles (0) 56 | , m_maxPoles (0) 57 | { 58 | } 59 | 60 | LayoutBase (int maxPoles, PoleZeroPair* pairs) 61 | : m_numPoles (0) 62 | , m_maxPoles (maxPoles) 63 | , m_pair (pairs) 64 | { 65 | } 66 | 67 | void setStorage (const LayoutBase& other) 68 | { 69 | m_numPoles = 0; 70 | m_maxPoles = other.m_maxPoles; 71 | m_pair = other.m_pair; 72 | } 73 | 74 | void reset () 75 | { 76 | m_numPoles = 0; 77 | } 78 | 79 | int getNumPoles () const 80 | { 81 | return m_numPoles; 82 | } 83 | 84 | int getMaxPoles () const 85 | { 86 | return m_maxPoles; 87 | } 88 | 89 | void add (const complex_t& pole, const complex_t& zero) 90 | { 91 | assert (!(m_numPoles&1)); // single comes last 92 | assert (!Dsp::is_nan (pole)); 93 | m_pair[m_numPoles/2] = PoleZeroPair (pole, zero); 94 | ++m_numPoles; 95 | } 96 | 97 | void addPoleZeroConjugatePairs (const complex_t pole, 98 | const complex_t zero) 99 | { 100 | assert (!(m_numPoles&1)); // single comes last 101 | assert (!Dsp::is_nan (pole)); 102 | m_pair[m_numPoles/2] = PoleZeroPair ( 103 | pole, zero, std::conj (pole), std::conj (zero)); 104 | m_numPoles += 2; 105 | } 106 | 107 | void add (const ComplexPair& poles, const ComplexPair& zeros) 108 | { 109 | assert (!(m_numPoles&1)); // single comes last 110 | assert (poles.isMatchedPair ()); 111 | assert (zeros.isMatchedPair ()); 112 | m_pair[m_numPoles/2] = PoleZeroPair (poles.first, zeros.first, 113 | poles.second, zeros.second); 114 | m_numPoles += 2; 115 | } 116 | 117 | const PoleZeroPair& getPair (int pairIndex) const 118 | { 119 | assert (pairIndex >= 0 && pairIndex < (m_numPoles+1)/2); 120 | return m_pair[pairIndex]; 121 | } 122 | 123 | const PoleZeroPair& operator[] (int pairIndex) const 124 | { 125 | return getPair (pairIndex); 126 | } 127 | 128 | double getNormalW () const 129 | { 130 | return m_normalW; 131 | } 132 | 133 | double getNormalGain () const 134 | { 135 | return m_normalGain; 136 | } 137 | 138 | void setNormal (double w, double g) 139 | { 140 | m_normalW = w; 141 | m_normalGain = g; 142 | } 143 | 144 | private: 145 | int m_numPoles; 146 | int m_maxPoles; 147 | PoleZeroPair* m_pair; 148 | double m_normalW; 149 | double m_normalGain; 150 | }; 151 | 152 | //------------------------------------------------------------------------------ 153 | 154 | // Storage for Layout 155 | template 156 | class Layout 157 | { 158 | public: 159 | operator LayoutBase () 160 | { 161 | return LayoutBase (MaxPoles, m_pairs); 162 | } 163 | 164 | private: 165 | PoleZeroPair m_pairs[(MaxPoles+1)/2]; 166 | }; 167 | 168 | } 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/MathSupplement.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_MATHSUPPLEMENT_H 37 | #define DSPFILTERS_MATHSUPPLEMENT_H 38 | 39 | #include "DspFilters/Common.h" 40 | 41 | namespace Dsp { 42 | 43 | const double doublePi =3.1415926535897932384626433832795028841971; 44 | const double doublePi_2 =1.5707963267948966192313216916397514420986; 45 | const double doubleLn2 =0.69314718055994530941723212145818;//????? 46 | const double doubleLn10 =2.3025850929940456840179914546844;//?????? 47 | 48 | typedef std::complex complex_t; 49 | typedef std::pair complex_pair_t; 50 | 51 | template 52 | inline std::complex solve_quadratic_1 (Real a, Real b, Real c) 53 | { 54 | return (-b + sqrt (std::complex (b*b - 4*a*c, 0))) / (2. * a); 55 | } 56 | 57 | template 58 | inline std::complex solve_quadratic_2 (Real a, Real b, Real c) 59 | { 60 | return (-b - sqrt (std::complex (b*b - 4*a*c, 0))) / (2. * a); 61 | } 62 | 63 | inline const complex_t infinity() 64 | { 65 | return complex_t (std::numeric_limits::infinity()); 66 | } 67 | 68 | inline const complex_t adjust_imag (const complex_t& c) 69 | { 70 | if (fabs (c.imag()) < 1e-30) 71 | return complex_t (c.real(), 0); 72 | else 73 | return c; 74 | } 75 | 76 | template 77 | inline std::complex addmul (const std::complex& c, 78 | Ty v, 79 | const std::complex& c1) 80 | { 81 | return std::complex ( 82 | c.real() + v * c1.real(), c.imag() + v * c1.imag()); 83 | } 84 | 85 | template 86 | inline std::complex recip (const std::complex& c) 87 | { 88 | Ty n = 1.0 / std::norm (c); 89 | 90 | return std::complex (n * c.real(), n * c.imag()); 91 | } 92 | 93 | template 94 | inline Ty asinh (Ty x) 95 | { 96 | return log (x + std::sqrt (x * x + 1 )); 97 | } 98 | 99 | template 100 | inline Ty acosh (Ty x) 101 | { 102 | return log (x + std::sqrt (x * x - 1)); 103 | } 104 | 105 | template 106 | inline bool is_nan (Ty v) 107 | { 108 | return !(v == v); 109 | } 110 | 111 | template <> 112 | inline bool is_nan (complex_t v) 113 | { 114 | return Dsp::is_nan (v.real()) || Dsp::is_nan (v.imag()); 115 | } 116 | 117 | //------------------------------------------------------------------------------ 118 | 119 | /* 120 | * Hack to prevent denormals 121 | * 122 | */ 123 | 124 | //const double anti_denormal_vsa = 1e-16; // doesn't prevent denormals 125 | //const double anti_denormal_vsa = 0; 126 | const double anti_denormal_vsa = 1e-8; 127 | 128 | class DenormalPrevention 129 | { 130 | public: 131 | DenormalPrevention () 132 | : m_v (anti_denormal_vsa) 133 | { 134 | } 135 | 136 | // small alternating current 137 | inline double ac () 138 | { 139 | return m_v = -m_v; 140 | } 141 | 142 | // small direct current 143 | static inline double dc () 144 | { 145 | return anti_denormal_vsa; 146 | } 147 | 148 | private: 149 | double m_v; 150 | }; 151 | 152 | } 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/RootFinder.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_ROOTFINDER_H 37 | #define DSPFILTERS_ROOTFINDER_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/Types.h" 41 | 42 | namespace Dsp { 43 | 44 | // 45 | // Finds the complex roots of the given polynomial with 46 | // complex-valued coefficients using a numerical method. 47 | // 48 | 49 | class RootFinderBase 50 | { 51 | public: 52 | struct Array 53 | { 54 | Array (int max, complex_t* values) 55 | // : m_max (max) 56 | // , m_values (values) 57 | { 58 | } 59 | 60 | //complex_t& operator[] (int index) 61 | //{ 62 | //}; 63 | }; 64 | 65 | // 66 | // Find roots of polynomial f(x)=a[0]+a[1]*x+a[2]*x^2...+a[degree]*x^degree 67 | // The input coefficients are set using coef()[]. 68 | // The solutions are placed in roots. 69 | // 70 | void solve (int degree, 71 | bool polish = true, 72 | bool doSort = true); 73 | 74 | // Evaluates the polynomial at x 75 | complex_t eval (int degree, 76 | const complex_t& x); 77 | 78 | // Direct access to the input coefficient array of size degree+1. 79 | complex_t* coef() 80 | { 81 | return m_a; 82 | } 83 | 84 | // Direct access to the resulting roots array of size degree 85 | complex_t* root() 86 | { 87 | return m_root; 88 | } 89 | 90 | // sort the roots by descending imaginary part 91 | void sort (int degree); 92 | 93 | private: 94 | // Improves x as a root using Laguerre's method. 95 | // The input coefficient array has degree+1 elements. 96 | void laguerre (int degree, 97 | complex_t a[], 98 | complex_t& x, 99 | int& its); 100 | 101 | protected: 102 | int m_maxdegree; 103 | complex_t* m_a; // input coefficients (m_maxdegree+1 elements) 104 | complex_t* m_ad; // copy of deflating coefficients 105 | complex_t* m_root; // array of roots (maxdegree elements) 106 | }; 107 | 108 | //------------------------------------------------------------------------------ 109 | 110 | template 111 | struct RootFinder : RootFinderBase 112 | { 113 | RootFinder() 114 | { 115 | m_maxdegree = maxdegree; 116 | m_a = m_a0; 117 | m_ad = m_ad0; 118 | m_root = m_r; 119 | } 120 | 121 | private: 122 | complex_t m_a0 [maxdegree+1]; 123 | complex_t m_ad0[maxdegree+1]; 124 | complex_t m_r [maxdegree]; 125 | }; 126 | 127 | } 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/SmoothedFilter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_SMOOTHEDFILTER_H 37 | #define DSPFILTERS_SMOOTHEDFILTER_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/Filter.h" 41 | 42 | namespace Dsp { 43 | 44 | /* 45 | * Implements smooth modulation of time-varying filter parameters 46 | * 47 | */ 48 | template 51 | class SmoothedFilterDesign 52 | : public FilterDesign 55 | { 56 | public: 57 | typedef FilterDesign filter_type_t; 58 | 59 | SmoothedFilterDesign (int transitionSamples) 60 | : m_transitionSamples (transitionSamples) 61 | , m_remainingSamples (-1) // first time flag 62 | { 63 | } 64 | 65 | // Process a block of samples. 66 | template 67 | void processBlock (int numSamples, 68 | Sample* const* destChannelArray) 69 | { 70 | const int numChannels = this->getNumChannels(); 71 | 72 | // If this goes off it means setup() was never called 73 | assert (m_remainingSamples >= 0); 74 | 75 | // first handle any transition samples 76 | int remainingSamples = std::min (m_remainingSamples, numSamples); 77 | 78 | if (remainingSamples > 0) 79 | { 80 | // interpolate parameters for each sample 81 | const double t = 1. / m_remainingSamples; 82 | double dp[maxParameters]; 83 | for (int i = 0; i < DesignClass::NumParams; ++i) 84 | dp[i] = (this->getParams()[i] - m_transitionParams[i]) * t; 85 | 86 | for (int n = 0; n < remainingSamples; ++n) 87 | { 88 | for (int i = DesignClass::NumParams; --i >=0;) 89 | m_transitionParams[i] += dp[i]; 90 | 91 | m_transitionFilter.setParams (m_transitionParams); 92 | 93 | for (int i = numChannels; --i >= 0;) 94 | { 95 | Sample* dest = destChannelArray[i]+n; 96 | *dest = this->m_state[i].process (*dest, m_transitionFilter); 97 | } 98 | } 99 | 100 | m_remainingSamples -= remainingSamples; 101 | 102 | if (m_remainingSamples == 0) 103 | m_transitionParams = this->getParams(); 104 | } 105 | 106 | // do what's left 107 | if (numSamples - remainingSamples > 0) 108 | { 109 | // no transition 110 | for (int i = 0; i < numChannels; ++i) 111 | this->m_design.process (numSamples - remainingSamples, 112 | destChannelArray[i] + remainingSamples, 113 | this->m_state[i]); 114 | } 115 | } 116 | 117 | void reset () 118 | { 119 | m_remainingSamples = -1; 120 | FilterDesign::reset(); 121 | } 122 | 123 | void process (int numSamples, float* const* arrayOfChannels) 124 | { 125 | processBlock (numSamples, arrayOfChannels); 126 | } 127 | 128 | void process (int numSamples, double* const* arrayOfChannels) 129 | { 130 | processBlock (numSamples, arrayOfChannels); 131 | } 132 | 133 | protected: 134 | void doSetParams (const Params& parameters) 135 | { 136 | if (m_remainingSamples >= 0) 137 | { 138 | m_remainingSamples = m_transitionSamples; 139 | } 140 | else 141 | { 142 | // first time 143 | m_remainingSamples = 0; 144 | m_transitionParams = parameters; 145 | } 146 | 147 | filter_type_t::doSetParams (parameters); 148 | } 149 | 150 | protected: 151 | Params m_transitionParams; 152 | DesignClass m_transitionFilter; 153 | int m_transitionSamples; 154 | 155 | int m_remainingSamples; // remaining transition samples 156 | }; 157 | 158 | } 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /DSPFilters/include/DspFilters/Types.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPFILTERS_TYPES_H 37 | #define DSPFILTERS_TYPES_H 38 | 39 | #include "DspFilters/Common.h" 40 | #include "DspFilters/MathSupplement.h" 41 | 42 | namespace Dsp { 43 | 44 | // A conjugate or real pair 45 | struct ComplexPair : complex_pair_t 46 | { 47 | ComplexPair () 48 | { 49 | } 50 | 51 | explicit ComplexPair (const complex_t& c1) 52 | : complex_pair_t (c1, 0.) 53 | { 54 | assert (isReal()); 55 | } 56 | 57 | ComplexPair (const complex_t& c1, 58 | const complex_t& c2) 59 | : complex_pair_t (c1, c2) 60 | { 61 | } 62 | 63 | bool isConjugate () const 64 | { 65 | return second == std::conj (first); 66 | } 67 | 68 | bool isReal () const 69 | { 70 | return first.imag() == 0 && second.imag() == 0; 71 | } 72 | 73 | // Returns true if this is either a conjugate pair, 74 | // or a pair of reals where neither is zero. 75 | bool isMatchedPair () const 76 | { 77 | if (first.imag() != 0) 78 | return second == std::conj (first); 79 | else 80 | return second.imag () == 0 && 81 | second.real () != 0 && 82 | first.real () != 0; 83 | } 84 | 85 | bool is_nan () const 86 | { 87 | return Dsp::is_nan (first) || Dsp::is_nan (second); 88 | } 89 | }; 90 | 91 | // A pair of pole/zeros. This fits in a biquad (but is missing the gain) 92 | struct PoleZeroPair 93 | { 94 | ComplexPair poles; 95 | ComplexPair zeros; 96 | 97 | PoleZeroPair () { } 98 | 99 | // single pole/zero 100 | PoleZeroPair (const complex_t& p, const complex_t& z) 101 | : poles (p), zeros (z) 102 | { 103 | } 104 | 105 | // pole/zero pair 106 | PoleZeroPair (const complex_t& p1, const complex_t& z1, 107 | const complex_t& p2, const complex_t& z2) 108 | : poles (p1, p2) 109 | , zeros (z1, z2) 110 | { 111 | } 112 | 113 | bool isSinglePole () const 114 | { 115 | return poles.second == 0. && zeros.second == 0.; 116 | } 117 | 118 | bool is_nan () const 119 | { 120 | return poles.is_nan() || zeros.is_nan(); 121 | } 122 | }; 123 | 124 | // Identifies the general class of filter 125 | enum Kind 126 | { 127 | kindLowPass, 128 | kindHighPass, 129 | kindBandPass, 130 | kindBandStop, 131 | kindLowShelf, 132 | kindHighShelf, 133 | kindBandShelf, 134 | kindOther 135 | }; 136 | 137 | } 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /DSPFilters/source/Cascade.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "DspFilters/Common.h" 37 | #include "DspFilters/Cascade.h" 38 | 39 | namespace Dsp { 40 | 41 | Cascade::Cascade () 42 | : m_numStages (0) 43 | , m_maxStages (0) 44 | , m_stageArray (0) 45 | { 46 | } 47 | 48 | void Cascade::setCascadeStorage (const Storage& storage) 49 | { 50 | m_numStages = 0; 51 | m_maxStages = storage.maxStages; 52 | m_stageArray = storage.stageArray; 53 | } 54 | 55 | complex_t Cascade::response (double normalizedFrequency) const 56 | { 57 | double w = 2 * doublePi * normalizedFrequency; 58 | const complex_t czn1 = std::polar (1., -w); 59 | const complex_t czn2 = std::polar (1., -2 * w); 60 | complex_t ch (1); 61 | complex_t cbot (1); 62 | 63 | const Biquad* stage = m_stageArray; 64 | for (int i = m_numStages; --i >=0; ++stage) 65 | { 66 | complex_t cb (1); 67 | complex_t ct (stage->getB0()/stage->getA0()); 68 | ct = addmul (ct, stage->getB1()/stage->getA0(), czn1); 69 | ct = addmul (ct, stage->getB2()/stage->getA0(), czn2); 70 | cb = addmul (cb, stage->getA1()/stage->getA0(), czn1); 71 | cb = addmul (cb, stage->getA2()/stage->getA0(), czn2); 72 | ch *= ct; 73 | cbot *= cb; 74 | } 75 | 76 | return ch / cbot; 77 | } 78 | 79 | std::vector Cascade::getPoleZeros () const 80 | { 81 | std::vector vpz; 82 | vpz.reserve (m_numStages); 83 | 84 | const Stage* stage = m_stageArray; 85 | for (int i = m_numStages; --i >=0;) 86 | { 87 | BiquadPoleState bps (*stage++); 88 | assert (!bps.isSinglePole() || i == 0); 89 | vpz.push_back (bps); 90 | } 91 | 92 | return vpz; 93 | } 94 | 95 | void Cascade::applyScale (double scale) 96 | { 97 | // For higher order filters it might be helpful 98 | // to spread this factor between all the stages. 99 | assert (m_numStages > 0); 100 | m_stageArray->applyScale (scale); 101 | } 102 | 103 | void Cascade::setLayout (const LayoutBase& proto) 104 | { 105 | const int numPoles = proto.getNumPoles(); 106 | m_numStages = (numPoles + 1)/ 2; 107 | assert (m_numStages <= m_maxStages); 108 | 109 | Biquad* stage = m_stageArray; 110 | for (int i = 0; i < m_numStages; ++i, ++stage) 111 | stage->setPoleZeroPair (proto[i]); 112 | 113 | applyScale (proto.getNormalGain() / 114 | std::abs (response (proto.getNormalW() / (2 * doublePi)))); 115 | } 116 | 117 | } 118 | 119 | -------------------------------------------------------------------------------- /DSPFilters/source/Custom.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "DspFilters/Common.h" 37 | #include "DspFilters/Custom.h" 38 | 39 | namespace Dsp { 40 | 41 | namespace Custom { 42 | 43 | void OnePole::setup (double scale, 44 | double pole, 45 | double zero) 46 | { 47 | setOnePole (pole, zero); 48 | applyScale (scale); 49 | } 50 | 51 | void TwoPole::setup (double scale, 52 | double poleRho, 53 | double poleTheta, 54 | double zeroRho, 55 | double zeroTheta) 56 | { 57 | complex_t pole = std::polar (poleRho, poleTheta); 58 | complex_t zero = std::polar (zeroRho, zeroTheta); 59 | 60 | setTwoPole (pole, zero, std::conj(pole), std::conj(zero)); 61 | applyScale (scale); 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /DSPFilters/source/Design.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "DspFilters/Common.h" 37 | #include "DspFilters/Design.h" 38 | 39 | namespace Dsp { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /DSPFilters/source/Filter.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "DspFilters/Common.h" 37 | #include "DspFilters/Filter.h" 38 | 39 | namespace Dsp { 40 | 41 | Params Filter::getDefaultParams() const 42 | { 43 | Params params; 44 | 45 | params.clear(); 46 | 47 | for (int i = 0; i < getNumParams(); ++i) 48 | params[i] = getParamInfo(i).getDefaultValue(); 49 | 50 | return params; 51 | } 52 | 53 | Filter::~Filter() 54 | { 55 | } 56 | 57 | int Filter::findParamId (int paramId) 58 | { 59 | int index = -1; 60 | 61 | for (int i = getNumParams(); --i >= 0;) 62 | { 63 | if (getParamInfo (i).getId () == paramId) 64 | { 65 | index = i; 66 | break; 67 | } 68 | } 69 | 70 | return index; 71 | } 72 | 73 | void Filter::setParamById (int paramId, double nativeValue) 74 | { 75 | for (int i = getNumParams(); --i >= 0;) 76 | { 77 | if (getParamInfo (i).getId () == paramId) 78 | { 79 | setParam (i, nativeValue); 80 | return; 81 | } 82 | } 83 | 84 | assert (0); 85 | } 86 | 87 | void Filter::copyParamsFrom (Dsp::Filter const* other) 88 | { 89 | // first, set reasonable defaults 90 | m_params = getDefaultParams (); 91 | 92 | if (other) 93 | { 94 | // now loop 95 | for (int i = 0; i < getNumParams (); ++i) 96 | { 97 | const ParamInfo& paramInfo = getParamInfo (i); 98 | 99 | // find a match 100 | for (int j = 0; j < other->getNumParams(); ++j) 101 | { 102 | const ParamInfo& otherParamInfo = other->getParamInfo (j); 103 | 104 | if (paramInfo.getId() == otherParamInfo.getId()) 105 | { 106 | // match! 107 | m_params [i] = paramInfo.clamp (other->getParam (j)); 108 | break; 109 | } 110 | } 111 | } 112 | } 113 | 114 | doSetParams (m_params); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /DSPFilters/source/RootFinder.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "DspFilters/Common.h" 37 | #include "DspFilters/RootFinder.h" 38 | #include 39 | 40 | namespace Dsp { 41 | 42 | void RootFinderBase::solve (int degree, 43 | bool polish, 44 | bool doSort) 45 | { 46 | assert (degree <= m_maxdegree); 47 | 48 | const double EPS = 1.0e-30; 49 | 50 | int its; 51 | complex_t x, b, c; 52 | 53 | int m = degree; 54 | 55 | // copy coefficients 56 | for (int j = 0; j <= m; ++j) 57 | m_ad[j] = m_a[j]; 58 | 59 | // for each root 60 | for (int j = m - 1; j >= 0; --j) 61 | { 62 | // initial guess at 0 63 | x = 0.0; 64 | laguerre (j + 1, m_ad, x, its); 65 | 66 | if (fabs (std::imag(x)) <= 2.0 * EPS * fabs (std::real(x))) 67 | x = complex_t (std::real(x), 0.0); 68 | 69 | m_root[j] = x; 70 | 71 | // deflate 72 | b = m_ad[j+1]; 73 | for (int jj = j; jj >= 0; --jj) 74 | { 75 | c = m_ad[jj]; 76 | m_ad[jj] = b; 77 | b = x * b + c; 78 | } 79 | } 80 | 81 | if (polish) 82 | for (int j = 0; j < m; ++j) 83 | laguerre (degree, m_a, m_root[j], its); 84 | 85 | if (doSort) 86 | sort (degree); 87 | } 88 | 89 | void RootFinderBase::sort (int degree) 90 | { 91 | for (int j = 1; j < degree; ++j) 92 | { 93 | complex_t x = m_root[j]; 94 | 95 | int i; 96 | for (i = j - 1; i >= 0; --i ) 97 | { 98 | if (m_root[i].imag() >= x.imag()) 99 | break; 100 | 101 | m_root[i+1] = m_root[i]; 102 | } 103 | 104 | m_root[i+1] = x; 105 | } 106 | } 107 | 108 | //------------------------------------------------------------------------------ 109 | 110 | void RootFinderBase::laguerre (int degree, 111 | complex_t a[], 112 | complex_t& x, 113 | int& its) 114 | { 115 | const int MR = 8, MT = 10, MAXIT = MT * MR; 116 | const double EPS = std::numeric_limits::epsilon(); 117 | 118 | static const double frac[MR + 1] = 119 | {0.0, 0.5, 0.25, 0.75, 0.13, 0.38, 0.62, 0.88, 1.0}; 120 | 121 | complex_t dx, x1, b, d, f, g, h, sq, gp, gm, g2; 122 | 123 | int m = degree; 124 | for (int iter = 1; iter <= MAXIT; ++iter) 125 | { 126 | its = iter; 127 | b = a[m]; 128 | double err = std::abs(b); 129 | d = f = 0.0; 130 | double abx = std::abs(x); 131 | for (int j = m - 1; j >= 0; --j) 132 | { 133 | f = x * f + d; 134 | d = x * d + b; 135 | b = x * b + a[j]; 136 | err = std::abs(b) + abx * err; 137 | } 138 | err *= EPS; 139 | if (std::abs(b) <= err) 140 | return; 141 | g = d / b; 142 | g2 = g * g; 143 | h = g2 - 2.0 * f / b; 144 | 145 | sq = sqrt (double(m - 1) * (double(m) * h - g2)); 146 | gp = g + sq; 147 | gm = g - sq; 148 | 149 | double abp = std::abs (gp); 150 | double abm = std::abs (gm); 151 | if (abp < abm) 152 | gp = gm; 153 | dx = std::max(abp, abm) > 0.0 ? double(m) / gp : std::polar (1 + abx, double(iter)); 154 | x1 = x - dx; 155 | if (x == x1) 156 | return; 157 | if (iter % MT != 0) 158 | x = x1; 159 | else 160 | x -= frac[iter / MT] * dx; 161 | } 162 | 163 | throw std::logic_error ("laguerre failed"); 164 | } 165 | 166 | //------------------------------------------------------------------------------ 167 | 168 | complex_t RootFinderBase::eval (int degree, 169 | const complex_t& x ) 170 | { 171 | complex_t y; 172 | 173 | if (x != 0.) 174 | { 175 | for (int i = 0; i <= degree; ++i) 176 | y += m_a[i] * pow (x, double(i)); 177 | } 178 | else 179 | { 180 | y = m_a[0]; 181 | } 182 | 183 | return y; 184 | } 185 | 186 | 187 | } 188 | -------------------------------------------------------------------------------- /DSPFilters/source/State.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "DspFilters/Common.h" 37 | #include "DspFilters/State.h" 38 | 39 | namespace Dsp { 40 | 41 | //------------------------------------------------------------------------------ 42 | 43 | } 44 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/AudioOutput.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPDEMO_AUDIOOUTPUT_H 37 | #define DSPDEMO_AUDIOOUTPUT_H 38 | 39 | #include "Common.h" 40 | #include "ThreadQueue.h" 41 | #include "FilteringAudioSource.h" 42 | 43 | /* 44 | * Handles Audio Output. Allows insertion of one Dsp::Filter 45 | * in the output chain, selectable audio source material, and 46 | * a resampler with dynamically adjustable tempo control. 47 | * 48 | */ 49 | class AudioOutput 50 | : private AudioIODeviceCallback 51 | { 52 | public: 53 | AudioOutput (); 54 | ~AudioOutput (); 55 | 56 | AudioDeviceManager& getAudioDeviceManager(); 57 | 58 | void setGain (float gainDb); 59 | void setTempo (float tempo); 60 | void setSource (AudioSource* source); 61 | void setFilter (Dsp::Filter* filter); 62 | void setFilterParameters (Dsp::Params parameters); 63 | void resetFilter (); 64 | 65 | protected: 66 | void doSetGain (float gain); 67 | void doSetTempo (float tempo); 68 | void doSetSource (ResamplingAudioSource* source); 69 | void doSetFilter (Dsp::Filter* filter); 70 | void doSetFilterParameters (Dsp::Params parameters); 71 | void doResetFilter (); 72 | 73 | void audioDeviceAboutToStart (AudioIODevice* device); 74 | 75 | void audioDeviceIOCallback (const float** inputChannelData, 76 | int numInputChannels, 77 | float** outputChannelData, 78 | int numOutputChannels, 79 | int numSamples); 80 | 81 | void audioDeviceStopped (); 82 | 83 | private: 84 | ScopedPointer m_audioDeviceManager; 85 | ThreadQueue m_queue; 86 | AudioIODevice* m_device; 87 | ScopedPointer m_filteringAudioSource; 88 | ResamplingAudioSource* m_resampler; 89 | float m_gain; 90 | float m_gainNext; 91 | float m_tempo; 92 | float m_tempoNext; 93 | int m_tempoSamplesFade; 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/BrickWallChart.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "Common.h" 37 | #include "BrickWallChart.h" 38 | 39 | #define MARGIN 1.1f 40 | 41 | //------------------------------------------------------------------------------ 42 | 43 | BrickWallChart::BrickWallChart (FilterListeners& listeners) 44 | : FrequencyChart (listeners) 45 | , m_scale_y (1) 46 | { 47 | } 48 | 49 | const String BrickWallChart::getName () const 50 | { 51 | return "Magnitude"; 52 | } 53 | 54 | int BrickWallChart::yToScreen (float y) 55 | { 56 | AffineTransform t = calcTransform(); 57 | Point p (0, y); 58 | return int(p.transformedBy (t).getY()); 59 | } 60 | 61 | void BrickWallChart::paintContents (Graphics& g) 62 | { 63 | AffineTransform t = calcTransform(); 64 | 65 | { 66 | int y = yToScreen (0); 67 | 68 | g.setColour (m_cAxis); 69 | g.fillRect (getLocalBounds().getX() + 1, y, 70 | getLocalBounds().getWidth() - 2, 1); 71 | 72 | g.setColour (m_cText); 73 | drawText (g, Point (6, y-2), "0"); 74 | } 75 | 76 | { 77 | int y = yToScreen (1); 78 | 79 | g.setColour (m_cAxis); 80 | g.fillRect (getLocalBounds().getX() + 1, y, 81 | getLocalBounds().getWidth() - 2, 1); 82 | 83 | g.setColour (m_cText); 84 | drawText (g, Point (6, y+2), "1", Justification::topLeft); 85 | } 86 | 87 | // path 88 | g.setColour (Colours::blue); 89 | g.strokePath (m_path, PathStrokeType (1.0f), t); 90 | } 91 | 92 | void BrickWallChart::update () 93 | { 94 | m_isDefined = false; 95 | m_path.clear(); 96 | 97 | if (m_filter) 98 | { 99 | m_isDefined = true; 100 | 101 | const Rectangle bounds = getLocalBounds (); 102 | const Rectangle r = bounds.reduced (4, 4); 103 | 104 | for (int xi = 0; xi < r.getWidth(); ++xi ) 105 | { 106 | float x = xi / float(r.getWidth()); // [0..1) 107 | float f = xToF (x); 108 | 109 | Dsp::complex_t c = m_filter->response (f/2.f); 110 | float y = float (std::abs(c)); 111 | 112 | if (!Dsp::is_nan (y)) 113 | { 114 | if (xi == 0) 115 | m_path.startNewSubPath (x, y); 116 | else 117 | m_path.lineTo (x, y); 118 | } 119 | else 120 | { 121 | m_path.clear (); 122 | m_isDefined = false; 123 | break; 124 | } 125 | } 126 | 127 | if (m_isDefined) 128 | m_path.startNewSubPath (0, 0); 129 | } 130 | 131 | float yh = m_path.getBounds().getHeight(); 132 | m_scale_y = (yh > MARGIN) ? (1/yh) : (1/MARGIN); 133 | 134 | repaint(); 135 | } 136 | 137 | AffineTransform BrickWallChart::calcTransform () 138 | { 139 | const Rectangle bounds = getLocalBounds (); 140 | const Rectangle r = bounds.reduced (4, 4); 141 | 142 | AffineTransform t; 143 | 144 | // scale x from 0..1 to 0..getWidth(), and flip vertical 145 | t = AffineTransform::scale (float(r.getWidth()), -1.f); 146 | 147 | // scale y from gain to 0..1 bounds in r 148 | t = t.scaled (1.f, m_scale_y); 149 | 150 | // scale y from 0..1 to getHeight() 151 | t = t.scaled (1.f, float(r.getHeight())); 152 | 153 | // translate 154 | t = t.translated (float(r.getX()), float(r.getBottom())); 155 | 156 | return t; 157 | } 158 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/BrickWallChart.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPDEMO_BRICKWALLCHART_H 37 | #define DSPDEMO_BRICKWALLCHART_H 38 | 39 | #include "FilterChart.h" 40 | 41 | /* 42 | * Displays the magnitude response of a Dsp::Filter. 43 | * This is sometimes referred to as a "brick wall diagram" 44 | * 45 | */ 46 | class BrickWallChart : public FrequencyChart 47 | { 48 | public: 49 | BrickWallChart (FilterListeners& listeners); 50 | 51 | const String getName () const; 52 | 53 | int yToScreen (float y); 54 | 55 | void paintContents (Graphics& g); 56 | 57 | private: 58 | void update (); 59 | AffineTransform calcTransform (); 60 | 61 | private: 62 | float m_scale_y; 63 | Path m_path; 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/Common.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPDEMO_COMMON_H 37 | #define DSPDEMO_COMMON_H 38 | 39 | #include "JuceHeader.h" 40 | 41 | #include "DspFilters/Dsp.h" 42 | 43 | #ifdef _MSC_VER 44 | # pragma warning (disable: 4100) 45 | # pragma warning (disable: 4355) 46 | #endif 47 | 48 | inline Rectangle tlbr (int top, int left, int bottom, int right) 49 | { 50 | return Rectangle (left, top, right-left, bottom-top); 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/ContentComponentConstrainer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef CONTENTCOMPONENTCONSTRAINER_H 37 | #define CONTENTCOMPONENTCONSTRAINER_H 38 | 39 | #include "Common.h" 40 | 41 | // "shim" which goes between your constrainer and a ResizableWindow 42 | // or derived class. This will adjust the parameters of the associated 43 | // constrainer so that all constraints are based on the content component 44 | // and do not include the title bar, native window frame, menu bar, or 45 | // window border. 46 | // 47 | // If you set a minimum size with your constrainer, the content component will 48 | // be constrained to EXACTLY your desired dimensions. 49 | // 50 | // This class is SUPER easy to use. First put a constrainer on your window 51 | // or use the function ResizableWindow::setResizeLimits(), and then 52 | // just call ContentComponentConstrainer::attachTo (yourResizableWindow). 53 | // It will take care of deleting itself and handle everything for you. 54 | class ContentComponentConstrainer 55 | : private ComponentBoundsConstrainer 56 | , private ComponentListener 57 | { 58 | public: 59 | // we can attach to anything with ResizableWindow as a base 60 | static void attachTo (ResizableWindow* resizableWindow) 61 | { 62 | ContentComponentConstrainer* contentConstrainer = 63 | new ContentComponentConstrainer (resizableWindow); 64 | resizableWindow->addComponentListener (contentConstrainer); 65 | } 66 | 67 | private: 68 | ContentComponentConstrainer (ResizableWindow* resizableWindow) 69 | : m_resizableWindow (resizableWindow) 70 | , m_originalConstrainer (0) 71 | { 72 | // if you aren't using a custom constrainer, then at least put a 73 | // constraint on your ResizableWindow using ResizableWindow::setResizeLimits 74 | // so that it gets the defaultConstrainer. 75 | m_originalConstrainer = m_resizableWindow->getConstrainer(); 76 | jassert (m_originalConstrainer); // must exist 77 | 78 | m_resizableWindow->setConstrainer (this); 79 | m_resizableWindow->addComponentListener (this); 80 | } 81 | 82 | void resizeStart() 83 | { 84 | m_originalConstrainer->resizeStart(); 85 | copyConstraints (*m_originalConstrainer); 86 | adjustConstraints(); 87 | } 88 | 89 | void resizeEnd() 90 | { 91 | m_originalConstrainer->resizeEnd(); 92 | } 93 | 94 | void applyBoundsToComponent (Component* component, 95 | const Rectangle& bounds) 96 | { 97 | m_originalConstrainer->applyBoundsToComponent (*component, bounds); 98 | } 99 | 100 | void copyConstraints (ComponentBoundsConstrainer& from) 101 | { 102 | setMinimumWidth (from.getMinimumWidth()); 103 | setMaximumWidth (from.getMaximumWidth()); 104 | setMinimumHeight (from.getMinimumHeight()); 105 | setMaximumHeight (from.getMaximumHeight()); 106 | setFixedAspectRatio (from.getFixedAspectRatio()); 107 | 108 | int minimumWhenOffTheTop; 109 | int minimumWhenOffTheLeft; 110 | int minimumWhenOffTheBottom; 111 | int minimumWhenOffTheRight; 112 | 113 | minimumWhenOffTheTop = from.getMinimumWhenOffTheTop(); 114 | minimumWhenOffTheLeft = from.getMinimumWhenOffTheLeft(); 115 | minimumWhenOffTheBottom = from.getMinimumWhenOffTheBottom(); 116 | minimumWhenOffTheRight = from.getMinimumWhenOffTheRight(); 117 | 118 | setMinimumOnscreenAmounts (minimumWhenOffTheTop, 119 | minimumWhenOffTheLeft, 120 | minimumWhenOffTheBottom, 121 | minimumWhenOffTheRight); 122 | } 123 | 124 | static int addWithoutOverflow (int a, int b) 125 | { 126 | if (a < (0x7ffffff-b)) 127 | return a+b; 128 | else 129 | return 0x7fffffff; 130 | } 131 | 132 | // adjusts the current constraints to take into account decorations 133 | void adjustConstraints() 134 | { 135 | BorderSize peerFrameBorder = m_resizableWindow->getPeer()->getFrameSize(); 136 | BorderSize contentCompBorder = m_resizableWindow->getContentComponentBorder(); 137 | 138 | int extraWidth = peerFrameBorder.getLeftAndRight() + contentCompBorder.getLeftAndRight(); 139 | int extraHeight = peerFrameBorder.getTopAndBottom() + contentCompBorder.getTopAndBottom(); 140 | 141 | setMinimumHeight (m_originalConstrainer->getMinimumHeight() + extraHeight); 142 | setMaximumHeight (addWithoutOverflow (m_originalConstrainer->getMaximumHeight(), extraHeight)); 143 | setMinimumWidth (m_originalConstrainer->getMinimumWidth() + extraWidth); 144 | setMaximumWidth (addWithoutOverflow (m_originalConstrainer->getMaximumWidth(), extraWidth)); 145 | } 146 | 147 | void componentBeingDeleted (Component& component) 148 | { 149 | delete this; 150 | } 151 | 152 | private: 153 | ResizableWindow* m_resizableWindow; 154 | ComponentBoundsConstrainer* m_originalConstrainer; 155 | }; 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/CpuMeter.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #include "Common.h" 37 | #include "CpuMeter.h" 38 | 39 | CpuMeter::CpuMeter (AudioDeviceManager& audioDeviceManager) 40 | : ResizableLayout (this) 41 | , m_audioDeviceManager (audioDeviceManager) 42 | , m_value (0) 43 | { 44 | setSize (80, 18); 45 | 46 | m_label = new Label; 47 | m_label->setText ("CPU", dontSendNotification); 48 | m_label->setBorderSize (BorderSize (2)); 49 | m_label->setSize (m_label->getFont().getStringWidth (m_label->getText()), 18); 50 | m_label->setTopLeftPosition (0, 0); 51 | addToLayout (m_label, anchorTopLeft, anchorBottomLeft); 52 | addAndMakeVisible (m_label); 53 | 54 | activateLayout (); 55 | 56 | startTimer (100); 57 | } 58 | 59 | CpuMeter::~CpuMeter() 60 | { 61 | } 62 | 63 | void CpuMeter::paint (Graphics& g) 64 | { 65 | const Rectangle bounds = getLocalBounds(); 66 | Rectangle r = bounds; 67 | r.setLeft (m_label->getRight() + 4); 68 | 69 | // fill 70 | g.setColour (Colours::white); 71 | g.fillRect (r.reduced (1, 1)); 72 | 73 | // frame 74 | g.setColour (Colours::black); 75 | g.drawRect (r, 1); 76 | 77 | // value 78 | r = r.reduced (1, 1); 79 | Colour c; 80 | if (m_value > 0.95) 81 | c = Colours::red; 82 | else if (m_value > 0.85) 83 | c = Colours::olivedrab.interpolatedWith (Colours::red, float(m_value - 0.85f)); 84 | else 85 | c = Colours::olivedrab; 86 | 87 | float w = float(r.getWidth() * m_value); 88 | g.setColour (c); 89 | g.fillRect (r.getX(), r.getY(), int(w), r.getHeight()); 90 | if (w != floor (w)) 91 | { 92 | // anti-alias 93 | g.setColour (c.withAlpha (float(w-floor(w)))); 94 | g.fillRect (r.getX() + int(w), r.getY(), 1, r.getHeight()); 95 | } 96 | } 97 | 98 | void CpuMeter::timerCallback () 99 | { 100 | m_value = m_audioDeviceManager.getCpuUsage(); 101 | repaint (); 102 | } 103 | -------------------------------------------------------------------------------- /DSPFiltersDemo/source/CpuMeter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | "A Collection of Useful C++ Classes for Digital Signal Processing" 4 | By Vinnie Falco 5 | 6 | Official project location: 7 | https://github.com/vinniefalco/DSPFilters 8 | 9 | See Documentation.cpp for contact information, notes, and bibliography. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | License: MIT License (http://www.opensource.org/licenses/mit-license.php) 14 | Copyright (c) 2009 by Vinnie Falco 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy 17 | of this software and associated documentation files (the "Software"), to deal 18 | in the Software without restriction, including without limitation the rights 19 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in 24 | all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 | THE SOFTWARE. 33 | 34 | *******************************************************************************/ 35 | 36 | #ifndef DSPDEMO_CPUMETER_H 37 | #define DSPDEMO_CPUMETER_H 38 | 39 | #include "Common.h" 40 | #include "ResizableLayout.h" 41 | 42 | /* 43 | * Simple CPU meter. Note this measures overall consumption in 44 | * the Audio callback (via Juce), not the overall system CPU usage. 45 | * 46 | */ 47 | class CpuMeter 48 | : public Component 49 | , public Timer 50 | , public ResizableLayout 51 | { 52 | public: 53 | CpuMeter (AudioDeviceManager& audioDeviceManager); 54 | ~CpuMeter (); 55 | 56 | void paint (Graphics& g); 57 | 58 | private: 59 | void timerCallback (); 60 | 61 | private: 62 | ScopedPointer