The basic detection method is just one short line of code:
1 2 |
(while (= (snd-fetch *track*) 0)) |
What this does is to fetch consecutive samples from the sound *track* until a sample is returned with a non-zero value.
A word of caution, SND-FETCH is destructive to the audio data. If *track* will be required later in the code, use SND-COPY to copy the audio data or it will be corrupted.
Clearly we can set a non-zero detection threshold if required with something like:
1 2 |
(while (< (abs (snd-fetch *track*)) 0.1)) |
To make it a little more useful, let’s create a label at the detected audio position:
1 2 3 4 5 6 |
(let (num) (setf num (do ((j 0 (1+ j))) ((/= 0 (snd-fetch *track*)) j))) (list (list (/ (- num 0.5) *sound-srate*) "Start"))) |