;; a delay all pass filter
(bind-func static delay_apf_c
(lambda (delay:i64)
(let ((line:SAMPLE* (zalloc delay))
(time 0)
(n 0)
(tmp 0.0)
(y 0.0))
(lambda (x:SAMPLE afp_gain)
(set! n (modulo time delay))
(set! y (pref line n))
(set! time (+ time 1))
(set! tmp (+ x (* afp_gain y)))
(pset! line n tmp)
(+ (* -1.0 afp_gain tmp) y)))))