Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created May 14, 2021 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpcima/383a75231da650659bbed32971a3908f to your computer and use it in GitHub Desktop.
Save jpcima/383a75231da650659bbed32971a3908f to your computer and use it in GitHub Desktop.
Resonant filter 6dB/oct
import("stdfaust.lib");
// modified W. Pirkle half-ladder filter
// extracts LPF1 and LPF2 output to produce resonant 6dB/oct and 12dB/oct
declare modifiedHalfLadder author "Jean Pierre Cimalando, Eric Tarr";
declare modifiedHalfLadder license "MIT-style STK-4.3 license";
modifiedHalfLadder(freq/*normFreq*/,Q) = _ <: (s1,s2,s3,/*y*/lpf1, lpf2) : !,!,!,_,_
letrec{
's1 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha*2):+(s1);
's2 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha*2):+(s2);
's3 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha):+(s2):-(s3):*(alpha*2):+(s3);
//'y = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha):+(s2) <:_*-1,((-(s3):*(alpha):+(s3))*2):>_;
'lpf1 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1);
'lpf2 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha):+(s2);
}
with{
//freq = 2*(10^(3*normFreq+1));
k = 2.0*(Q - 0.707)/(25.0 - 0.707);
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
alpha = G;
GA = 2*G-1; // All-pass gain
B1 = GA*G/(1+g);
B2 = GA/(1+g);
B3 = 2/(1+g);
alpha0 = 1/(1 + k*GA*G*G);
};
process = par(i, 2, modifiedHalfLadder(f, q) : (_,!)) with {
f = hslider("[1] freq", 1000, 0, 5000, 1) : si.smoo;
q = hslider("[2] q", 0, 0, 24, 0.001) : si.smoo;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment