;;
;; moog VCF variation 3
;;
;; from Stilson/Smith CCRMA
;;
;; type is:
;; lp 1 (or anything)
;; hp 2
;; bp 3
(bind-func static vcf3_c
(lambda (type)
(let ((b0 0.0) (b1 0.0) (b2 0.0) (b3 0.0) (b4 0.0)
(t1 0.0) (t2 0.0))
(lambda (in:SAMPLE cutoff res)
(let ((frq (* 1.75 (/ cutoff SAMPLERATE)))
(q (- 1.0 frq))
(p (+ frq (* 0.8 frq q)))
(f (+ p (- p 1.0))))
(set! q (* res (+ 1.0 (* 0.5 q (+ (- 1.0 q) (* 5.6 q q))))))
(set! in (- in (* q b4))) ;; feedback
(set! t1 b1) (set! b1 (- (* (+ in b0) p) (* b1 f)))
(set! t2 b2) (set! b2 (- (* (+ b1 t1) p) (* b2 f)))
(set! t1 b3) (set! b3 (- (* (+ b2 t2) p) (* b3 f)))
(set! b4 (- (* (+ b3 t1) p) (* b4 f)))
(set! b4 (- b4 (* b4 b4 b4 0.166667)))
;;(set! b4 (- b4 (* b4 b4 0.25))) ;; clipping
(set! b0 in)
(if (= type 2) (- b0 b4) ;; high pass
(if (= type 3) (* 3.0 (- b3 b4))
b4)))))))