;; root mean squared (mono passthrough)
;; grab current rms value from val:
;;
;; updates db every FRAMES
;; passes mono signal straight through
;;
;; DB is (RMS is +3db - i.e. dBFS with sine 1.0 at 0.0db)
;;
(bind-func static rms_c
  (lambda ()
    (let ((d:SAMPLE* (alloc FRAMES))
          (t 0)
          (db:SAMPLE 0.0))
      (lambda (x:SAMPLE)
        (pset! d (% t FRAMES) (* x x))
        (set! t (+ t 1))
        (if (= 0 (% t FRAMES))
            (set! db (+ 3.0 (amp2db (sqrt (calc_vmean d FRAMES))))))
        x))))