[CM] audio leveler
Bill Schottstaedt
bil@ccrma.Stanford.EDU
Mon, 14 Aug 2006 03:31:31 -0700
> So, can I use SND for leveling?
Yes, but you might need to hack a bit.
There's a first pass at an automatic gain control in dsp.scm,
but it's commented out. I was going to experiment with
moving-rms to detect portions with just background noise
(to be squelched, rather than amplified); it's on my
"TODO" list...
Anyway, to give it a try, load dsp.scm, paste the agc function
into the listener, load the sound you want to try it on, ideally
set optimization to 6: (set! (optimization) 6), and (agc):
(load "dsp.scm")
(set! (optimization) 6)
(define* (agc :optional (ramp-speed .001) (window-size 512))
(let ((maxer (make-moving-max window-size))
(mult 1.0))
(map-channel
(lambda (y)
(let* ((curmax (moving-max maxer y))
(diff (- 0.5 (* mult curmax)))
(this-incr (* diff ramp-speed)))
(set! mult (+ mult this-incr))
(* y mult))))))
(open-sound "learn-Snd-while-you-drive.snd")
(agc)