MCPcopy Create free account
hub / github.com/LabSound/LabSound / setNotchParams

Method setNotchParams

src/internal/src/Biquad.cpp:338–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336}
337
338void Biquad::setNotchParams(double frequency, double Q)
339{
340 // Clip frequencies to between 0 and 1, inclusive.
341 frequency = std::max(0.0, std::min(frequency, 1.0));
342
343 // Don't let Q go negative, which causes an unstable filter.
344 Q = std::max(0.0, Q);
345
346 if (frequency > 0 && frequency < 1)
347 {
348 if (Q > 0)
349 {
350 double w0 = static_cast<double>(LAB_PI) * frequency;
351 double alpha = sin(w0) / (2 * Q);
352 double k = cos(w0);
353
354 double b0 = 1;
355 double b1 = -2 * k;
356 double b2 = 1;
357 double a0 = 1 + alpha;
358 double a1 = -2 * k;
359 double a2 = 1 - alpha;
360
361 setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
362 }
363 else
364 {
365 // When Q = 0, the above formulas have problems. If we look at
366 // the z-transform, we can see that the limit as Q->0 is 0, so
367 // set the filter that way.
368 setNormalizedCoefficients(0, 0, 0,
369 1, 0, 0);
370 }
371 }
372 else
373 {
374 // When frequency is 0 or 1, the z-transform is 1.
375 setNormalizedCoefficients(1, 0, 0,
376 1, 0, 0);
377 }
378}
379
380void Biquad::setBandpassParams(double frequency, double Q)
381{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected