In Progress Improvements on Track Detector Script

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

In Progress Improvements on Track Detector Script

Alex S. Brown, PMP
I have a work-in-progress upgrade to share with everyone, for the silence
detecting script I did a while back. I am making changes to take advantage of
some of the new features coming out in Audacity v1.3. This script will work
with either Audacity 1.2.x or 1.3, but the next version will be especially for
1.3.

Version 1.3 allows each label to have both a start and an end date. I changed
the silence detector so that it marks both the start and end of each track (as
best it can figure, based on periods of silence). When v1.3 can handle it, I
will send out each label with both a start and an end date on it, so that the
whole track is effectively marked. This will allow people to export just the
tracks, and not the periods of silence in between. A few people asked for that
feature a few months ago, but I could not figure a good way to do it in
Nyquist. The new feature of Audacity should make it pretty easy.

While I was in the code, I also cleaned up the detection method, based on music
that has caused incorrect markers for me in the past. I added a pop detector,
so that brief pops of sound are treated like silence. That let me set the
threshold for silence a lot lower, which lead to more accurate results for many
passages. I would also like to put the whole silence-finding routine inside a
function, to make it easier to reuse.

After going through a lot of music passages, I have decided that I am never
going to get the track detection perfect just by measuring silence. Some music
and some voice recordings have so many long pauses that it is impossible to
tell the difference between a track break and a quiet part in the middle of a
track. Pink Floyd's "High Hopes" with the long, fading bell toll is probably
the worst for a computer to try to understand. I am working out a way so that
the computer can pick the best silence markers, if you can provide it with a
list of tracks and their expected durations. With this extra information, it
looks like I can get nearly 100% accuracy. I figure if you know what you are
recording, you can probably give a good guess about how long each passage is
supposed to be, and that improves the computer's ability to split tracks well
tremendously. I also found ways you can add MP3 or OGG tags to the files, based
on the same text file that contains the track durations. I will provide that
upgrade once I am done with it.

If you want to play around with the latest version, just paste the code below my
signature into a "track-splitter.ny" file and put it in your plug-in folder.

Thanks in advance for your feedback and thoughts.

----------------------
Alex S. Brown, PMP
[hidden email]
http://www.alexsbrown.com/

;nyquist plug-in
;version 1
;type analyze
;name "Track Splitter..."
;action "Marking tracks..."
;info "Track Splitter written by Alex S. Brown, PMP
(http://www.alexsbrown.com)\nVersion 0.1 released January 3 2006 under the GPL
license\n(http://www.opensource.org/licenses/gpl-license.php)
;control sil-lev "Silence level" real "dB" 32 0 100
;control sil-dur "Minimum silence duration" real "seconds" 1.0 0.1 5.0
;control pop-dur "Ignore pops less than" real "seconds long (enter zero to
disable pop detection)" 0.01 0.0 0.5
;control labelbeforedur "Start track" real "seconds before silence ends" 0.5 0.0
1.0
;control labelafterdur "End track" real "seconds after silence ends" 0.5 0.0
1.0

;Create a function to make the sum the two channels if they are stereo
(defun mono-s (s-in) (if (arrayp s-in) (snd-add (aref s-in 0) (aref s-in 1))
s-in))

;Create a function to reduce the sample rate and prepare the signal for
;analysis. RMS is good to monitor volume the way humans hear it, but is not
;available in Audacity. Used a peak-calculating function instead.
;NOTE: this is the place to add any processing to improve the quality of the
;signal. Noise filters could improve the quality of matches for noisy signals.

;PERFORMANCE vs. ACCURACY
;Reducing the samples per second should improve the performance and decrease
;the accuracy of the labels. Increasing the samples per second will do the
;opposite. The more samples checked, the longer it takes. The more samples
;checked, the more precisely the program can place the silence labels.
;my-srate-ratio determines the number of samples in my-s. Set the number after
(snd-srate s)
;higher to increase the number of samples.

(defun my-s (s-in)
 (setq my-srate-ratio (truncate (/ (snd-srate (mono-s s-in)) 100)))
 (snd-avg (mono-s s-in) my-srate-ratio my-srate-ratio OP-PEAK)
)

;Create a function to round a number up to the nearest integer
(defun roundup (my-num)
        (if (> my-num (truncate my-num))
                (+ 1 (truncate my-num))
                (truncate my-num)
        )
)

;Set the silence threshold level (convert it to a linear form)
(setq thres (db-to-linear (* -1 sil-lev)))
;Store the sample rate of the sound
(setq s1-srate (snd-srate (my-s s)))
;Initialize the variable that will hold the length of the sound.
;Do not calculate it now with snd-length, because it would waste memory.
;We will calculate it later.
(setq s1-length 0)
;Convert the silence and pop duration in seconds to a length in samples,
;always rounding up if it results in a fraction of a sample
(setq sil-length (roundup (* sil-dur s1-srate)))
(setq pop-length (roundup (* pop-dur s1-srate)))
;Initialize the silence counter to the silence duration, because at the
;start of the sound, we want to detect silence right away to mark the start
;if the first track.
(setq sil-c (+ 1 sil-length))
;Initialize the pop counter
(setq pop-c 0)
;Initialize the labels variable
(setq l NIL)

;Define a function to add new items to the list of labels
(defun add-label (l-time l-text)
 (setq l (cons (list l-time l-text) l))
)

;The main working part of the program, it counts
;the number of sequential samples with volume under
;the threshold. It adds to a list of markers ever time
;there is a longer period of silence than the silence
;duration amount.

;It runs through a loop, adding to the list of markers (l)
;each time it finds silence.
(let (s1) ;Define s1 as a local variable to allow efficient memory use
 ; Get the sample into s1, then free s to save memory
 (setq s1 (my-s s))
 (setq s nil)
 ;Capture the result of this "do" loop, because we need the sountd's legnth
 ;in samples.
 (setq s1-length
  ;Keep repeating, incrementing the counter and getting another sample
  ;each time through the loop.
  (do ((n 1 (+ n 1)) (v (snd-fetch s1) (setq v (snd-fetch s1))))
   ;Exit when we run out of samples (v is nil) and return the number of
   ;samples processed (n)
   ((not v) n)
   ;Start the execution part of the do loop
   ;if found silence, increment the silence counter by one.
   ;If the pop counter is non-zero, add it and reset it.
   (if (< v thres)
    (prog1
    (setq sil-c (+ sil-c 1 pop-c))
    (setq pop-c 0)
    )
   )

   ;If this sample is NOT silent, and there has been silence for some time,
   ;check for pops and mark the beginning and end of the tracks if the silence
   ;has been long enough
   (if (and (> v thres) (> sil-c 0))
           (progn
                   ;Increment the pop counter
                   (setq pop-c (+ pop-c 1))
                   
                   ;If the sound is too long to be a pop, then reset the silence counter
                   ;and mark the beginning and end of the tracks if the silence is long
enough
                   (if (> pop-c pop-length)
                            (prog1
                            ;If the silence is long enough, mark the tracks
                            (if (> sil-c sil-length)
                            (progn
                                                    ;If this is not the first mark, then also mark the end of the
                                                    ;previous track
                                                    (if (not (null l))
                                                           ;Mark the user-set number of seconds AFTER the silence started as
the
                                                           ;end of the previous track (but no sooner than the start of where the
sound
                                                           ;was detected)
                                                            (add-label (min (/ n s1-srate) (+ (/ (- n sil-c) s1-srate)
labelafterdur)) "E")
                            )
                                                   ;Mark the user-set number of seconds BEFORE the new sound as the
                                                   ;beginning of the track (but no sooner than the zero-point)
                                                    (add-label (max 0 (- (/ n s1-srate) labelbeforedur)) "B")
                            )
                            ) ; end if on sil-c
                            ;Reset the silence counter
                            (setq sil-c 0)
                            )
                   ) ; end if on pop-c
                 )
    ) ; end if on non-silent
         ) ;end do loop across all samples
 ) ;end setq for s1-length
) ;end let s1

;Mark the end of the last track
;Label time is the time the silence began plus the silence duration target
;amount. We calculate the time the silence began as the end-time minus the
;final value of the silence counter
(add-label (min (/ s1-length s1-srate) (+ (/ (- s1-length sil-c) s1-srate)
labelafterdur)) "E")

;Return the list of markers
l;


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Audacity-nyquist mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/audacity-nyquist
Reply | Threaded
Open this post in threaded view
|

Re: In Progress Improvements on Track Detector Script

edgar-rft

Hi Alex,

could you please send me the Nyquist file as an attachment
to edgar-rft[at]web.de - my mailbox always scrambles up the
code so it takes about half an hour to re-construct the original.

Thanks,

- edgar
______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Audacity-nyquist mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/audacity-nyquist
Reply | Threaded
Open this post in threaded view
|

Re: In Progress Improvements on Track Detector Script

Alex S. Brown, PMP
Sorry, I thought in-line was better for people than attached. From now on, I
will do both.

--Alex

Quoting [hidden email]:

>
> Hi Alex,
>
> could you please send me the Nyquist file as an attachment
> to edgar-rft[at]web.de - my mailbox always scrambles up the
> code so it takes about half an hour to re-construct the original.
>
> Thanks,
>
> - edgar
> ______________________________________________________________
> Verschicken Sie romantische, coole und witzige Bilder per SMS!
> Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Audacity-nyquist mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/audacity-nyquist
>

----------------------
Alex S. Brown, PMP
[hidden email]
http://www.alexsbrown.com/

track-splitter-v0.1.ny (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: In Progress Improvements on Track Detector Script

David R. Sky
Hi Alex,

I prefer Nyquist files in attachments too.

Thanks

David

On Thu, 5 Jan 2006, Alex S. Brown wrote:

> Sorry, I thought in-line was better for people than attached. From now on, I
> will do both.
>
> --Alex


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Audacity-nyquist mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/audacity-nyquist