ZDF SVF 1

Author: Smashed Transistors
License: LGPL
Github: tiar/filter/ZDF SVF 1.axo

Inlets

frac32 pitch

frac32 filter resonance

frac32buffer filter input

Outlets

frac32buffer filter output

frac32buffer hp12

frac32buffer bp6

Parameters

frac32.s.map.pitch pitch

frac32.u.map Q

Declaration
// updates the coefficients with the "ZDF" step invariant method.
void update(float _Q, float F) {
  D = _Q;
  // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  // pre iterations values (equiv to Chamberlin filter)
  float _a = F * F;
  float tmp = 1 - _a - D * F;
  float _b = F * tmp + F;
  float _c = tmp * tmp - _a;
  // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  // 7 iterations to obtain the new a b and c (equiv x32 oversampling)
  // Two sets of vars (_a _b _c and na nb nc) are used to bounce values
  // between iterations to optimize copies.
  float b2;
  b2 = _b * _b;
  na = b2 + _a * (2 - _a);
  nb = _b * (1 + _c - _a);
  nc = _c * _c - b2;
  b2 = nb * nb;
  _a = b2 + na * (2 - na);
  _b = nb * (1 + nc - na);
  _c = nc * nc - b2;
  b2 = _b * _b;
  na = b2 + _a * (2 - _a);
  nb = _b * (1 + _c - _a);
  nc = _c * _c - b2;
  b2 = nb * nb;
  _a = b2 + na * (2 - na);
  _b = nb * (1 + nc - na);
  _c = nc * nc - b2;
  b2 = _b * _b;
  na = b2 + _a * (2 - _a);
  nb = _b * (1 + _c - _a);
  nc = _c * _c - b2;
  b2 = nb * nb;
  _a = b2 + na * (2 - na);
  _b = nb * (1 + nc - na);
  _c = nc * nc - b2;
  b2 = _b * _b;
  na = b2 + _a * (2 - _a);
  nb = _b * (1 + _c - _a);
  nc = _c * _c - b2;
  // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  // deltas for sample rate interpolation
  da = (na - a) * (1 / 16.0f);
  db = (nb - b) * (1 / 16.0f);
  dc = (nc - c) * (1 / 16.0f);
}

float a, b, c;    // current values (srate interpolated)
float na, nb, nc; // new values
float da, db, dc; // deltas for srate interpolation
float D;          // used for hp
float x;          // input
float lp, bp;     // state variables/outputs
float lp2, bp2;   // state variables/outputs of 24dB output
float TRF_coef;
Init
TRF_coef = (820.0f / (1 << 27)) * 2 * 3.1415926535f / (128 * 48000);
D = x = lp = bp = 0;
update(1.0f, 0.1f / 32);
a = na;
b = nb;
c = nc;
da = db = dc = 0;
Control Rate
float q = __USAT(param_Q + inlet_reso, 27) * (1.0f / (1 << 27));
q = 0.25f + q * (1 + q * q * (18.75f + q * 60)); // 0.25 -> 80

int32_t alpha;
MTOFEXTENDED(param_pitch + inlet_pitch - 7, alpha);
update(1 / (2 * q), alpha *TRF_coef);
const float lim = (float)((0x1FFFFFFF) - (1 << 20));
if (bp >= lim)
  bp = lim;
if (bp <= -lim)
  bp = -lim;
if (lp >= lim)
  lp = lim;
if (lp <= -lim)
  lp = -lim;
Audio Rate
a += da;
b += db;
c += dc;
x = (float)inlet_x;
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

float x_lp = x - lp;
outlet_lp12 = (int32_t)(lp += a * x_lp + b * bp);
outlet_hp12 = (int32_t)(x - D * bp - lp);
outlet_bp6 = (int32_t)(bp = b * x_lp + c * bp);

Privacy

© 2024 Zrna Research