MCPcopy Create free account
hub / github.com/VCVRack/Rack / setParameters

Method setParameters

include/dsp/filter.hpp:316–433  ·  view source on GitHub ↗

Calculates and sets the biquad transfer function coefficients. f: normalized frequency (cutoff frequency / sample rate), must be less than 0.5 Q: quality factor V: gain */

Source from the content-addressed store, hash-verified

314 V: gain
315 */
316 void setParameters(Type type, float f, float Q, float V) {
317 float K = std::tan(M_PI * f);
318 switch (type) {
319 case LOWPASS_1POLE: {
320 this->a[0] = -std::exp(-2.f * M_PI * f);
321 this->a[1] = 0.f;
322 this->b[0] = 1.f + this->a[0];
323 this->b[1] = 0.f;
324 this->b[2] = 0.f;
325 } break;
326
327 case HIGHPASS_1POLE: {
328 this->a[0] = std::exp(-2.f * M_PI * (0.5f - f));
329 this->a[1] = 0.f;
330 this->b[0] = 1.f - this->a[0];
331 this->b[1] = 0.f;
332 this->b[2] = 0.f;
333 } break;
334
335 case LOWPASS: {
336 float norm = 1.f / (1.f + K / Q + K * K);
337 this->b[0] = K * K * norm;
338 this->b[1] = 2.f * this->b[0];
339 this->b[2] = this->b[0];
340 this->a[0] = 2.f * (K * K - 1.f) * norm;
341 this->a[1] = (1.f - K / Q + K * K) * norm;
342 } break;
343
344 case HIGHPASS: {
345 float norm = 1.f / (1.f + K / Q + K * K);
346 this->b[0] = norm;
347 this->b[1] = -2.f * this->b[0];
348 this->b[2] = this->b[0];
349 this->a[0] = 2.f * (K * K - 1.f) * norm;
350 this->a[1] = (1.f - K / Q + K * K) * norm;
351
352 } break;
353
354 case LOWSHELF: {
355 float sqrtV = std::sqrt(V);
356 if (V >= 1.f) {
357 float norm = 1.f / (1.f + M_SQRT2 * K + K * K);
358 this->b[0] = (1.f + M_SQRT2 * sqrtV * K + V * K * K) * norm;
359 this->b[1] = 2.f * (V * K * K - 1.f) * norm;
360 this->b[2] = (1.f - M_SQRT2 * sqrtV * K + V * K * K) * norm;
361 this->a[0] = 2.f * (K * K - 1.f) * norm;
362 this->a[1] = (1.f - M_SQRT2 * K + K * K) * norm;
363 }
364 else {
365 float norm = 1.f / (1.f + M_SQRT2 / sqrtV * K + K * K / V);
366 this->b[0] = (1.f + M_SQRT2 * K + K * K) * norm;
367 this->b[1] = 2.f * (K * K - 1) * norm;
368 this->b[2] = (1.f - M_SQRT2 * K + K * K) * norm;
369 this->a[0] = 2.f * (K * K / V - 1.f) * norm;
370 this->a[1] = (1.f - M_SQRT2 / sqrtV * K + K * K / V) * norm;
371 }
372 } break;
373

Callers

nothing calls this directly

Calls 3

tanFunction · 0.85
expFunction · 0.85
sqrtFunction · 0.85

Tested by

no test coverage detected