| 75 | } |
| 76 | |
| 77 | void Biquad::setLowpassParams(double cutoff, double resonance) |
| 78 | { |
| 79 | // Limit cutoff to 0 to 1. |
| 80 | cutoff = std::max(0.0, std::min(cutoff, 1.0)); |
| 81 | |
| 82 | if (cutoff == 1) |
| 83 | { |
| 84 | // When cutoff is 1, the z-transform is 1. |
| 85 | setNormalizedCoefficients(1, 0, 0, |
| 86 | 1, 0, 0); |
| 87 | } |
| 88 | else if (cutoff > 0) |
| 89 | { |
| 90 | // Compute biquad coefficients for lowpass filter |
| 91 | resonance = std::max(0.0, resonance); // can't go negative |
| 92 | double g = pow(10.0, 0.05 * resonance); |
| 93 | double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2); |
| 94 | |
| 95 | double theta = static_cast<double>(LAB_PI) * cutoff; |
| 96 | double sn = 0.5 * d * sin(theta); |
| 97 | double beta = 0.5 * (1 - sn) / (1 + sn); |
| 98 | double gamma = (0.5 + beta) * cos(theta); |
| 99 | double alpha = 0.25 * (0.5 + beta - gamma); |
| 100 | |
| 101 | double b0 = 2 * alpha; |
| 102 | double b1 = 2 * 2 * alpha; |
| 103 | double b2 = 2 * alpha; |
| 104 | double a1 = 2 * -gamma; |
| 105 | double a2 = 2 * beta; |
| 106 | |
| 107 | setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | // When cutoff is zero, nothing gets through the filter, so set |
| 112 | // coefficients up correctly. |
| 113 | setNormalizedCoefficients(0, 0, 0, |
| 114 | 1, 0, 0); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void Biquad::setHighpassParams(double cutoff, double resonance) |
| 119 | { |
no outgoing calls
no test coverage detected