45 double c4,
double c5,
double c6) noexcept
57 double frequency) noexcept
66 jassert (sampleRate > 0.0);
67 jassert (frequency > 0.0 && frequency <= sampleRate * 0.5);
71 auto nSquared = n * n;
72 auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared);
78 c1 * 2.0 * (1.0 - nSquared),
79 c1 * (1.0 - 1.0 / Q * n + nSquared));
83 double frequency) noexcept
85 return makeHighPass (sampleRate, frequency, 1.0 / std::sqrt(2.0));
92 jassert (sampleRate > 0.0);
93 jassert (frequency > 0.0 && frequency <= sampleRate * 0.5);
97 auto nSquared = n * n;
98 auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared);
104 c1 * 2.0 * (nSquared - 1.0),
105 c1 * (1.0 - 1.0 / Q * n + nSquared));
109 double frequency) noexcept
118 jassert (sampleRate > 0.0);
119 jassert (frequency > 0.0 && frequency <= sampleRate * 0.5);
123 auto nSquared = n * n;
124 auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared);
130 c1 * 2.0 * (1.0 - nSquared),
131 c1 * (1.0 - 1.0 / Q * n + nSquared));
135 double frequency) noexcept
144 jassert (sampleRate > 0.0);
145 jassert (frequency > 0.0 && frequency <= sampleRate * 0.5);
149 auto nSquared = n * n;
150 auto c1 = 1.0 / (1.0 + n / Q + nSquared);
153 2.0 * c1 * (1.0 - nSquared),
154 c1 * (1.0 + nSquared),
156 c1 * 2.0 * (1.0 - nSquared),
157 c1 * (1.0 - n / Q + nSquared));
161 double frequency) noexcept
170 jassert (sampleRate > 0.0);
171 jassert (frequency > 0.0 && frequency <= sampleRate * 0.5);
175 auto nSquared = n * n;
176 auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared);
179 c1 * 2.0 * (1.0 - nSquared),
182 c1 * 2.0 * (1.0 - nSquared),
183 c1 * (1.0 - n / Q + nSquared));
187 double cutOffFrequency,
189 float gainFactor) noexcept
191 jassert (sampleRate > 0.0);
192 jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5);
195 auto A = jmax (0.0f, std::sqrt (gainFactor));
196 auto aminus1 = A - 1.0;
197 auto aplus1 = A + 1.0;
199 auto coso = std::cos (omega);
200 auto beta = std::sin (omega) * std::sqrt (A) / Q;
201 auto aminus1TimesCoso = aminus1 * coso;
204 A * 2.0 * (aminus1 - aplus1 * coso),
205 A * (aplus1 - aminus1TimesCoso - beta),
206 aplus1 + aminus1TimesCoso + beta,
207 -2.0 * (aminus1 + aplus1 * coso),
208 aplus1 + aminus1TimesCoso - beta);
212 double cutOffFrequency,
214 float gainFactor) noexcept
216 jassert (sampleRate > 0.0);
217 jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5);
220 auto A = jmax (0.0f, std::sqrt (gainFactor));
221 auto aminus1 = A - 1.0;
222 auto aplus1 = A + 1.0;
224 auto coso = std::cos (omega);
225 auto beta = std::sin (omega) * std::sqrt (A) / Q;
226 auto aminus1TimesCoso = aminus1 * coso;
229 A * -2.0 * (aminus1 + aplus1 * coso),
230 A * (aplus1 + aminus1TimesCoso - beta),
231 aplus1 - aminus1TimesCoso + beta,
232 2.0 * (aminus1 - aplus1 * coso),
233 aplus1 - aminus1TimesCoso - beta);
239 float gainFactor) noexcept
241 jassert (sampleRate > 0.0);
242 jassert (frequency > 0.0 && frequency <= sampleRate * 0.5);
245 auto A = jmax (0.0f, std::sqrt (gainFactor));
247 auto alpha = 0.5 * std::sin (omega) / Q;
248 auto c2 = -2.0 * std::cos (omega);
249 auto alphaTimesA = alpha * A;
250 auto alphaOverA = alpha / A;
300 JUCE_SNAP_TO_ZERO (out);
319 auto lv1 = v1, lv2 = v2;
321 for (
int i = 0; i < numSamples; ++i)
323 auto in = samples[i];
324 auto out = c0 * in + lv1;
327 lv1 = c1 * in - c3 * out + lv2;
328 lv2 = c2 * in - c4 * out;
331 JUCE_SNAP_TO_ZERO (lv1); v1 = lv1;
332 JUCE_SNAP_TO_ZERO (lv2); v2 = lv2;
static IIRCoefficients makeLowShelf(double sampleRate, double cutOffFrequency, double Q, float gainFactor) noexcept
Returns the coefficients for a low-pass shelf filter with variable Q and gain.
void makeInactive() noexcept
Clears the filter so that any incoming data passes through unchanged.
static IIRCoefficients makeHighShelf(double sampleRate, double cutOffFrequency, double Q, float gainFactor) noexcept
Returns the coefficients for a high-pass shelf filter with variable Q and gain.
static IIRCoefficients makeLowPass(double sampleRate, double frequency) noexcept
Returns the coefficients for a low-pass filter.
IIRCoefficients() noexcept
Creates a null set of coefficients (which will produce silence).
static IIRCoefficients makePeakFilter(double sampleRate, double centreFrequency, double Q, float gainFactor) noexcept
Returns the coefficients for a peak filter centred around a given frequency, with a variable Q and ga...
void setCoefficients(const IIRCoefficients &newCoefficients) noexcept
Applies a set of coefficients to this filter.
static IIRCoefficients makeNotchFilter(double sampleRate, double frequency) noexcept
Returns the coefficients for a notch filter.
static IIRCoefficients makeAllPass(double sampleRate, double frequency) noexcept
Returns the coefficients for an all-pass filter.
void processSamples(float *samples, int numSamples) noexcept
Performs the filter operation on the given set of samples.
~IIRFilter() noexcept
Destructor.
An IIR filter that can perform low, high, or band-pass filtering on an audio signal.
IIRFilter() noexcept
Creates a filter.
float coefficients[5]
The raw coefficients.
A set of coefficients for use in an IIRFilter object.
static IIRCoefficients makeBandPass(double sampleRate, double frequency) noexcept
Returns the coefficients for a band-pass filter.
Commonly used mathematical constants.
static IIRCoefficients makeHighPass(double sampleRate, double frequency) noexcept
Returns the coefficients for a high-pass filter.
Automatically locks and unlocks a mutex object.
~IIRCoefficients() noexcept
Destructor.
IIRCoefficients & operator=(const IIRCoefficients &) noexcept
Creates a copy of another filter.
float processSingleSampleRaw(float sample) noexcept
Processes a single sample, without any locking or checking.
void reset() noexcept
Resets the filter's processing pipeline, ready to start a new stream of data.