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

Method setPeakingParams

src/internal/src/Biquad.cpp:252–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250}
251
252void Biquad::setPeakingParams(double frequency, double Q, double dbGain)
253{
254 // Clip frequencies to between 0 and 1, inclusive.
255 frequency = std::max(0.0, std::min(frequency, 1.0));
256
257 // Don't let Q go negative, which causes an unstable filter.
258 Q = std::max(0.0, Q);
259
260 double A = pow(10.0, dbGain / 40);
261
262 if (frequency > 0 && frequency < 1)
263 {
264 if (Q > 0)
265 {
266 double w0 = static_cast<double>(LAB_PI) * frequency;
267 double alpha = sin(w0) / (2 * Q);
268 double k = cos(w0);
269
270 double b0 = 1 + alpha * A;
271 double b1 = -2 * k;
272 double b2 = 1 - alpha * A;
273 double a0 = 1 + alpha / A;
274 double a1 = -2 * k;
275 double a2 = 1 - alpha / A;
276
277 setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
278 }
279 else
280 {
281 // When Q = 0, the above formulas have problems. If we look at
282 // the z-transform, we can see that the limit as Q->0 is A^2, so
283 // set the filter that way.
284 setNormalizedCoefficients(A * A, 0, 0,
285 1, 0, 0);
286 }
287 }
288 else
289 {
290 // When frequency is 0 or 1, the z-transform is 1.
291 setNormalizedCoefficients(1, 0, 0,
292 1, 0, 0);
293 }
294}
295
296void Biquad::setAllpassParams(double frequency, double Q)
297{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected