;; simple triangle
;;
;; mod is phase 0.0-1.0
;;
(bind-func static tri_c
(lambda (mod:float)
(let ((out 0.0) (inc 0.0))
(lambda (amp:float frq:float)
(set! inc (/ frq SRs))
;; positive frequencies
(if (and (> inc 0.0) (>= mod 1.0))
(set! mod (- mod 1.0)))
;; negative frequencies
(if (and (< inc 0.0) (<= mod 0.0))
(set! mod (+ mod 1.0)))
(set! out (- (* 2.0 (fabs (- (* 2.0 mod) 1.0))) 1.0))
(set! mod (+ mod inc))
(* amp -1.0 out)))))