;; mod is phase between 0.0-1.0
;; pw for pulse width 0.0-1.0 = 0.5 is square
(bind-func static pulse_c
(lambda (mod:float)
(let ((out 0.0) (inc 0.0))
(lambda (amp:float frq:float pw: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 (if (> mod pw) -1.0 1.0))
(set! mod (+ mod inc))
(* amp out)))))