Am probably as much of a beginner as one can be but I managed yesterday to code a very simple and primitive silence trimmer. It just searches for the first point that a sound reaches a certain level and then trims away the audio before that. So, basically, it trims the beginnings. The problem was that when I ran this plugin in a chain on a lot of files, the memory usage rose a lot (from about 30 megs to 70, processing 36 files).
This is the code:
Code: Select all
;control treshold "Treshold" real "" 0.5 0 1
;control maxlen "Max" real "seconds" 1 0 2
(setq dur (truncate (* maxlen *sound-srate*)))
(setq samples (snd-samples s dur) )
(setq y 0) ;init y
(setq i
(do ((i 0 (setq i (1+ i))))
((or (> i dur) (>= y treshold)) (1- i))
(setq y (abs (aref samples i)))))
(setq start (/ i *sound-srate*))
(setq end (/ len *sound-srate*))
(mult (env 0.003 0 0 1 1 1) (extract-abs start end s))
I read in a post here that it is preferable to work with sounds instead of samples so I started to look for a way to do that. After looking through the Nyquist reference I came up with this code:
Code: Select all
;control treshold "Treshold" real "" 0.5 0 1
(mult (env 0.003 0 0 1 1 1)
(extract-abs
(sref-inverse (s-abs s) treshold)
(get-duration 1) s))