;; pan around 'n' channels
;; with a bleed to surrounding channels.
;;
;; the 1st speaker (channel) is pan 0.0
;; the 2nd speaker is pan 1.0
;; etc..
;; the last speaker is pan (- n 1.0)
;; it is legal to pan past (- n 1.0) to n
;; this makes it possible to pan between the
;; last speaker and the first speaker
;;
;; for example: assuming 4 channels
;; (pan chan in 1.0 (% pos 4.0))
;; would pan around a circle of 4 speakers
;;
;; the amount of 'bleed' is the amount of bleed
;; between speakers. A bleed of 4.0 with 4.0 channels
;; would mean all speakers would always be sounding.
;; A bleed of less than 0.5 would ensure that only one
;; speaker at a time will ever be sounding.
;;
(bind-func static pan_c
(lambda (chans)
(let ((fchans (i64tof (+ chans 0)))
(fchan 0.0)
(chk 0)
(p1 0.0) (p2 0.0) (p3 0.0)
(b1 0.0) (b2 0.0))
(lambda (chan in bleed pan)
(set! fchan (i64tof chan))
(set! p1 pan)
(set! p2 (- pan fchans))
(set! p3 (+ pan fchans))
(set! b1 (- fchan bleed))
(set! b2 (+ fchan bleed))
(cond ((and (> p1 b1) (< p1 b2)) (* in (/ 1.0 bleed) (- bleed (fabs (- fchan p1)))))
((and (> p2 b1) (< p2 b2)) (* in (/ 1.0 bleed) (- bleed (fabs (- fchan p2)))))
((and (> p3 b1) (< p3 b2)) (* in (/ 1.0 bleed) (- bleed (fabs (- fchan p3)))))
(else 0.0))))))