;; rms
;;
;; left and right are db
;; (RMS is +3db - i.e. dBFS with sine 1.0 at 0.0db)
;;
(bind-func static rms_st_c
(lambda ()
(let ((lgth (* 1 FRAMES))
(dl:SAMPLE* (alloc lgth))
(dr:SAMPLE* (alloc lgth))
(t 0)
(left:SAMPLE 0.0)
(right:SAMPLE 0.0))
(lambda (chan:i64 x:SAMPLE)
(if (= chan 0)
(begin (pset! dl (% t lgth) (* x x))
(set! t (+ t 1))
;;(printf "left %f\n" (ftod left))
(if (= 0 (% t lgth))
(begin
(set! left (+ 3.0 (amp2db (sqrt (calc_vmean dl lgth)))))
(set! right (+ 3.0 (amp2db (sqrt (calc_vmean dr lgth)))))))
void)
(begin (pset! dr (% t lgth) (* x x))
void))
x))))