(bind-func static va_onepole
(lambda (type) ;; either LPF1 or HPF1
(if (and (<> type HPF1) (<> type LPF1)) (println "BAD TYPE FOR FILTER: should be LPF1 or HPF1"))
(let ((m_dAlpha:SAMPLE* (alloc 1)) ;; feed forward coeff
(m_dBeta:SAMPLE* (alloc 1)) ;; for korg and moog
(m_dGamma 1.0) ;; pre gain
(m_dDelta 0.0) ;; FB in
(m_dEpsilon 0.0) ;; FB out
(m_da0 1.0) ;; input gain
(m_dZ1 0.0) ;; z-1 register
(vn 0.0) ;; fn
(xn:SAMPLE 0.0)
(feedbackOutput:SAMPLE* (alloc 1)) ;; (lambda () (* (pref m_dBeta 0) (+ m_dZ1 (* m_dFeedback m_dDelta)))))
(lpf 0.0)
(hpf 0.0))
(lambda (x:SAMPLE fb)
;; (set! m_dFeedback fb)
(pset! feedbackOutput 0 (* (pref m_dBeta 0) (+ m_dZ1 (* fb m_dDelta))))
;; for diode filter support
(set! xn (+ (* x m_dGamma) fb (* m_dEpsilon (pref feedbackOutput 0))))
(set! vn (* (- (* m_da0 xn) m_dZ1) (pref m_dAlpha 0)))
(set! lpf (+ vn m_dZ1))
(set! m_dZ1 (+ vn lpf))
(set! hpf (- xn lpf))
(if (= type HPF1) hpf lpf)))))