| 294 | } |
| 295 | |
| 296 | void Biquad::setAllpassParams(double frequency, double Q) |
| 297 | { |
| 298 | // Clip frequencies to between 0 and 1, inclusive. |
| 299 | frequency = std::max(0.0, std::min(frequency, 1.0)); |
| 300 | |
| 301 | // Don't let Q go negative, which causes an unstable filter. |
| 302 | Q = std::max(0.0, Q); |
| 303 | |
| 304 | if (frequency > 0 && frequency < 1) |
| 305 | { |
| 306 | if (Q > 0) |
| 307 | { |
| 308 | double w0 = static_cast<double>(LAB_PI) * frequency; |
| 309 | double alpha = sin(w0) / (2 * Q); |
| 310 | double k = cos(w0); |
| 311 | |
| 312 | double b0 = 1 - alpha; |
| 313 | double b1 = -2 * k; |
| 314 | double b2 = 1 + alpha; |
| 315 | double a0 = 1 + alpha; |
| 316 | double a1 = -2 * k; |
| 317 | double a2 = 1 - alpha; |
| 318 | |
| 319 | setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | // When Q = 0, the above formulas have problems. If we look at |
| 324 | // the z-transform, we can see that the limit as Q->0 is -1, so |
| 325 | // set the filter that way. |
| 326 | setNormalizedCoefficients(-1, 0, 0, |
| 327 | 1, 0, 0); |
| 328 | } |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | // When frequency is 0 or 1, the z-transform is 1. |
| 333 | setNormalizedCoefficients(1, 0, 0, |
| 334 | 1, 0, 0); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void Biquad::setNotchParams(double frequency, double Q) |
| 339 | { |
no outgoing calls
no test coverage detected