| Index: third_party/WebKit/Source/platform/audio/Biquad.cpp
|
| diff --git a/third_party/WebKit/Source/platform/audio/Biquad.cpp b/third_party/WebKit/Source/platform/audio/Biquad.cpp
|
| index 913c07a4052d3accbd5485c9f58a7c8c842f070e..f29e77aa3d5091f16176b7036447c38c9bbd7920 100644
|
| --- a/third_party/WebKit/Source/platform/audio/Biquad.cpp
|
| +++ b/third_party/WebKit/Source/platform/audio/Biquad.cpp
|
| @@ -255,23 +255,22 @@ void Biquad::setLowpassParams(int index, double cutoff, double resonance)
|
| 1, 0, 0);
|
| } else if (cutoff > 0) {
|
| // Compute biquad coefficients for lowpass filter
|
| - resonance = std::max(0.0, resonance); // can't go negative
|
| - double g = pow(10.0, 0.05 * resonance);
|
| - double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
|
|
|
| + resonance = pow(10, resonance / 20);
|
| double theta = piDouble * cutoff;
|
| - double sn = 0.5 * d * sin(theta);
|
| - double beta = 0.5 * (1 - sn) / (1 + sn);
|
| - double gamma = (0.5 + beta) * cos(theta);
|
| - double alpha = 0.25 * (0.5 + beta - gamma);
|
| -
|
| - double b0 = 2 * alpha;
|
| - double b1 = 2 * 2 * alpha;
|
| - double b2 = 2 * alpha;
|
| - double a1 = 2 * -gamma;
|
| - double a2 = 2 * beta;
|
| -
|
| - setNormalizedCoefficients(index, b0, b1, b2, 1, a1, a2);
|
| + double alpha = sin(theta) / (2 * resonance);
|
| + double cosw = cos(theta);
|
| + double beta = (1 - cosw) / 2;
|
| +
|
| + double b0 = beta;
|
| + double b1 = 2 * beta;
|
| + double b2 = beta;
|
| +
|
| + double a0 = 1 + alpha;
|
| + double a1 = -2 * cosw;
|
| + double a2 = 1 - alpha;
|
| +
|
| + setNormalizedCoefficients(index, b0, b1, b2, a0, a1, a2);
|
| } else {
|
| // When cutoff is zero, nothing gets through the filter, so set
|
| // coefficients up correctly.
|
| @@ -293,23 +292,22 @@ void Biquad::setHighpassParams(int index, double cutoff, double resonance)
|
| 1, 0, 0);
|
| } else if (cutoff > 0) {
|
| // Compute biquad coefficients for highpass filter
|
| - resonance = std::max(0.0, resonance); // can't go negative
|
| - double g = pow(10.0, 0.05 * resonance);
|
| - double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
|
|
|
| + resonance = pow(10, resonance / 20);
|
| double theta = piDouble * cutoff;
|
| - double sn = 0.5 * d * sin(theta);
|
| - double beta = 0.5 * (1 - sn) / (1 + sn);
|
| - double gamma = (0.5 + beta) * cos(theta);
|
| - double alpha = 0.25 * (0.5 + beta + gamma);
|
| -
|
| - double b0 = 2 * alpha;
|
| - double b1 = 2 * -2 * alpha;
|
| - double b2 = 2 * alpha;
|
| - double a1 = 2 * -gamma;
|
| - double a2 = 2 * beta;
|
| -
|
| - setNormalizedCoefficients(index, b0, b1, b2, 1, a1, a2);
|
| + double alpha = sin(theta) / (2 * resonance);
|
| + double cosw = cos(theta);
|
| + double beta = (1 + cosw) / 2;
|
| +
|
| + double b0 = beta;
|
| + double b1 = -2 * beta;
|
| + double b2 = beta;
|
| +
|
| + double a0 = 1 + alpha;
|
| + double a1 = -2 * cosw;
|
| + double a2 = 1 - alpha;
|
| +
|
| + setNormalizedCoefficients(index, b0, b1, b2, a0, a1, a2);
|
| } else {
|
| // When cutoff is zero, we need to be careful because the above
|
| // gives a quadratic divided by the same quadratic, with poles
|
|
|