OpenShot Audio Library | OpenShotAudio 0.4.0
Loading...
Searching...
No Matches
juce_audio_basics/utilities/juce_IIRFilter.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26class IIRFilter;
27
28//==============================================================================
36class JUCE_API IIRCoefficients
37{
38public:
39 //==============================================================================
41 IIRCoefficients() noexcept;
42
48 IIRCoefficients (double c1, double c2, double c3,
49 double c4, double c5, double c6) noexcept;
50
52 IIRCoefficients (const IIRCoefficients&) noexcept;
56 ~IIRCoefficients() noexcept;
57
58 //==============================================================================
60 static IIRCoefficients makeLowPass (double sampleRate,
61 double frequency) noexcept;
62
64 static IIRCoefficients makeLowPass (double sampleRate,
65 double frequency,
66 double Q) noexcept;
67
68 //==============================================================================
70 static IIRCoefficients makeHighPass (double sampleRate,
71 double frequency) noexcept;
72
74 static IIRCoefficients makeHighPass (double sampleRate,
75 double frequency,
76 double Q) noexcept;
77
78 //==============================================================================
80 static IIRCoefficients makeBandPass (double sampleRate, double frequency) noexcept;
81
83 static IIRCoefficients makeBandPass (double sampleRate,
84 double frequency,
85 double Q) noexcept;
86
87 //==============================================================================
89 static IIRCoefficients makeNotchFilter (double sampleRate, double frequency) noexcept;
90
92 static IIRCoefficients makeNotchFilter (double sampleRate,
93 double frequency,
94 double Q) noexcept;
95
96 //==============================================================================
98 static IIRCoefficients makeAllPass (double sampleRate, double frequency) noexcept;
99
101 static IIRCoefficients makeAllPass (double sampleRate,
102 double frequency,
103 double Q) noexcept;
104
105 //==============================================================================
112 static IIRCoefficients makeLowShelf (double sampleRate,
113 double cutOffFrequency,
114 double Q,
115 float gainFactor) noexcept;
116
123 static IIRCoefficients makeHighShelf (double sampleRate,
124 double cutOffFrequency,
125 double Q,
126 float gainFactor) noexcept;
127
135 static IIRCoefficients makePeakFilter (double sampleRate,
136 double centreFrequency,
137 double Q,
138 float gainFactor) noexcept;
139
140 //==============================================================================
144 float coefficients[5];
145};
146
147//==============================================================================
156template <typename Mutex>
157class JUCE_API IIRFilterBase
158{
159public:
160 //==============================================================================
168
171
172 //==============================================================================
174 void makeInactive() noexcept;
175
177 void setCoefficients (const IIRCoefficients& newCoefficients) noexcept;
178
180 IIRCoefficients getCoefficients() const noexcept { return coefficients; }
181
182 //==============================================================================
189 void reset() noexcept;
190
192 void processSamples (float* samples, int numSamples) noexcept;
193
199 float processSingleSampleRaw (float sample) noexcept;
200
202 //==============================================================================
203 Mutex processLock;
204 IIRCoefficients coefficients;
205 float v1 = 0, v2 = 0;
206 bool active = false;
207
208 // The exact meaning of an assignment operator would be ambiguous since the filters are
209 // stateful. If you want to copy the coefficients, then just use setCoefficients().
211
212 JUCE_LEAK_DETECTOR (IIRFilter)
213};
214
232{
233public:
234 using IIRFilterBase::IIRFilterBase;
235};
236
248class SingleThreadedIIRFilter : public IIRFilterBase<DummyCriticalSection>
249{
250public:
251 using IIRFilterBase::IIRFilterBase;
252};
253
254} // namespace juce
IIRFilterBase() noexcept