Code: Select all
// update coeffs when parameters change
f = tan(M_PI*cutoff / samplerate)
r = f + 1 / Q
g = 1 / (f * r + 1)
// rest is per sample
// calculate outputs
hp = (in - r*z1 - z2) * g
bp = z1 + f*hp
lp = z2 + f*bp
// and update state
z1 += 2*f*hp
z2 += 2*f*bp