(bind-func vu_meter_c
"frame_size must be a multiple of 4 (since the RMS sum is SIMD-optimised)"
(lambda (ninst frame_size)
(let ((data:SAMPLE* (zalloc (* ninst frame_size)))
(counters:i64* (zalloc ninst)))
(lambda (chan inst_idx in)
(if (or (< inst_idx 0)
(> inst_idx ninst)
(<> chan 0))
in
(let ((counter (pref counters inst_idx)))
(pset! data (+ (* inst_idx frame_size) counter) in)
(pset! counters inst_idx (% (+ counter 1) frame_size))
(if (= (% counter frame_size) 0)
(aset! VU_LEVELS_RMS inst_idx
(rms_power (pref-ptr data (* inst_idx frame_size))
frame_size)))
in))))))