(bind-func static peak_c
"peak filter: returns filtering closure which implements a state variable filter"
(lambda ()
(let ((ic1eq 0.0) (ic2eq 0.0)
(g 0.0)
(k 0.0)
(a1 0.0) (a2 0.0)
(ocutoff -1.0) (ores -1.0)
(v1 0.0) (v2:SAMPLE 0.0))
(lambda (in cutoff res)
(if (or (<> cutoff ocutoff)
(<> res ores))
(begin
;; negative frq & res
(if (< cutoff 0.0) (set! cutoff (fabs cutoff)))
(if (< res 0.0) (set! res (fabs res)))
(set! ocutoff cutoff)
(set! ores res)
(set! g (tan (* SPI (/ cutoff SRs))))
(set! k (- 2.0 (* 2.0 res)))
(set! a1 (/ 1.0 (+ 1.0 (* g (+ g k)))))
(set! a2 (* g a1))))
(set! v1 (+ (* a1 ic1eq) (* a2 (- in ic2eq))))
(set! v2 (+ ic2eq (* g v1)))
(set! ic1eq (- (* 2.0 v1) ic1eq))
(set! ic2eq (- (* 2.0 v2) ic2eq))
(- (- in (* k v1)) (* 2.0 v2))))))