IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, const double frequency) noexcept { const double n = tan (double_Pi * frequency / sampleRate); const double nSquared = n * n; const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); return IIRCoefficients (c1, c1 * -2.0f, c1, 1.0, c1 * 2.0 * (nSquared - 1.0), c1 * (1.0 - std::sqrt (2.0) * n + nSquared)); }
IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, const double frequency) noexcept { jassert (sampleRate > 0); const double n = 1.0 / tan (double_Pi * frequency / sampleRate); const double nSquared = n * n; const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); return IIRCoefficients (c1, c1 * 2.0f, c1, 1.0, c1 * 2.0 * (1.0 - nSquared), c1 * (1.0 - std::sqrt (2.0) * n + nSquared)); }
IIRCoefficients BiquadFilter::makeHighPass (const double sampleRate, const double frequency, const double Q) noexcept { const double oneOverCurrentSampleRate = 1.0 / sampleRate; float w0 = (float) (2.0f * float_Pi * frequency * oneOverCurrentSampleRate); float cos_w0 = cos (w0); float sin_w0 = sin (w0); float alpha = sin_w0 / (2.0f * (float) Q); return IIRCoefficients ((1.0f + cos_w0) * 0.5f, -(1.0f + cos_w0), (1.0f + cos_w0) * 0.5f, (1.0f + alpha), -2.0f * cos_w0, (1.0f - alpha)); }
IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, const double frequency, const double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); const double n = std::tan (double_Pi * frequency / sampleRate); const double nSquared = n * n; const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); return IIRCoefficients (c1, c1 * -2.0, c1, 1.0, c1 * 2.0 * (nSquared - 1.0), c1 * (1.0 - 1.0 / Q * n + nSquared)); }
IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, const double frequency, const double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); const double nSquared = n * n; const double c1 = 1.0 / (1.0 + n / Q + nSquared); return IIRCoefficients (c1 * (1.0 + nSquared), 2.0 * c1 * (1.0 - nSquared), c1 * (1.0 + nSquared), 1.0, c1 * 2.0 * (1.0 - nSquared), c1 * (1.0 - n / Q + nSquared)); }
IIRCoefficients BiquadFilter::makeAllpass (const double sampleRate, const double frequency, const double Q) noexcept { const double qFactor = jlimit(0.00001, 1000.0, Q); const double oneOverCurrentSampleRate = 1.0 / sampleRate; float w0 = (float) (2.0f * float_Pi * frequency * oneOverCurrentSampleRate); float cos_w0 = cos(w0); float sin_w0 = sin(w0); float alpha = (float) (sin_w0 / (2 * qFactor)); return IIRCoefficients (1.0f - alpha, -2 * cos_w0, 1.0f + alpha, 1.0f + alpha, -2.0f * cos_w0, 1.0f - alpha); }
IIRCoefficients BiquadFilter::makeBandPass (const double sampleRate, const double frequency, const double Q) noexcept { const double qFactor = jlimit (0.00001, 1000.0, Q); const double oneOverCurrentSampleRate = 1.0 / sampleRate; float w0 = (float) (2.0f * float_Pi * frequency * oneOverCurrentSampleRate); float cos_w0 = cos (w0); float sin_w0 = sin (w0); float alpha = sin_w0 / (2.0f * (float) qFactor); // float alpha = sin_w0 * sinh( (log(2.0)/2.0) * bandwidth * w0/sin_w0 ); return IIRCoefficients (alpha, 0.0f, -alpha, 1.0f + alpha, -2.0f * cos_w0, 1.0f - alpha); }
IIRCoefficients IIRCoefficients::makePeakFilter (const double sampleRate, const double centreFrequency, const double Q, const float gainFactor) noexcept { jassert (sampleRate > 0); jassert (Q > 0); const double A = jmax (0.0f, std::sqrt (gainFactor)); const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate; const double alpha = 0.5 * std::sin (omega) / Q; const double c2 = -2.0 * std::cos (omega); const double alphaTimesA = alpha * A; const double alphaOverA = alpha / A; return IIRCoefficients (1.0 + alphaTimesA, c2, 1.0 - alphaTimesA, 1.0 + alphaOverA, c2, 1.0 - alphaOverA); }
IIRCoefficients IIRCoefficients::makeLowShelf (const double sampleRate, const double cutOffFrequency, const double Q, const float gainFactor) noexcept { jassert (sampleRate > 0); jassert (Q > 0); const double A = jmax (0.0f, std::sqrt (gainFactor)); const double aminus1 = A - 1.0; const double aplus1 = A + 1.0; const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; const double coso = std::cos (omega); const double beta = std::sin (omega) * std::sqrt (A) / Q; const double aminus1TimesCoso = aminus1 * coso; return IIRCoefficients (A * (aplus1 - aminus1TimesCoso + beta), A * 2.0 * (aminus1 - aplus1 * coso), A * (aplus1 - aminus1TimesCoso - beta), aplus1 + aminus1TimesCoso + beta, -2.0 * (aminus1 + aplus1 * coso), aplus1 + aminus1TimesCoso - beta); }