Dereverb

This can calculate the RMS for very long (mono) audio.

I’ve separated out the calculation for choosing an appropriate block (“step”) size into it’s own function. If you are working with very long audio selections (hours), then you may want to try and optimise the BEST-STEP-SIZE function, but as written it should work for any size up to many hours of audio with good precision.

(defun get-rms (sig ln)
  ;; Return RMS of mono sound.
  (let ((sigsq (mult sig sig)))
    (setf step (best-step-size ln))
    (setf ms (snd-avg sigsq step step op-average))
    (setf sigsq nil) ;memory optimisation.
    ;; Use SND-AVG rather than S-AVG for compatibility with
    ;; Audacity versions < 3.0.
    (when (> (snd-length ms 2) 1)
      (setf step (snd-length ms ny:all))
      (setf ms (snd-avg ms step step op-average)))
    (linear-to-db (sqrt (snd-fetch ms)))))


(defun best-step-size (ln)
  ;; Return a step size less than maxblock.
  ;; Optimisation Hints:
  ;; Large step requires less loops in LISP, so may be faster,
  ;; but greater difference between step size and final block length
  ;; decreases precision.
  (let ((maxblocklen 1000000))
    (if (> ln maxblocklen)
        (round (sqrt (float ln)))
        ln)))


(get-rms *track* (truncate len))