(bind-func static skf_c
"lowpass filter: returns filtering closure using a Sallen Key lpf"
(lambda ()
(let ((ic1eq 0.0) (ic2eq 0.0)
(g 0.0)
(k 0.0)
(a0 0.0) (a1 0.0) (a2 0.0) (a3 0.0) (a4 0.0) (a5 0.0)
(v1 0.0) (v2:SAMPLE 0.0))
(lambda (in cutoff res)
;; one option: do the check (= res oldres) trick here
(set! g (tan (* SPI (/ cutoff SRs))))
(set! k (* 2.0 res))
(set! a0 (/ 1.0 (- (* (+ 1.0 g)
(+ 1.0 g))
(* g k))))
(set! a1 (* k a0))
(set! a2 (* (+ 1.0 g) a0))
(set! a3 (* g a2))
(set! a4 (/ 1.0 (+ 1.0 g)))
(set! a5 (* g a4))
(set! v1 (+ (* a1 ic2eq)
(* a2 ic1eq)
(* a3 in)))
(set! v2 (+ (* a4 ic2eq)
(* a5 v1)))
(set! ic1eq (- (* 2.0 (- v1 (* k v2))) ic1eq))
(set! ic2eq (- (* 2.0 v2) ic2eq))
v2))))