How to detect a sound in just a few lines of code

The basic detection method is just one short line of code:

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:

To make it a little more useful, let’s create a label at the detected audio position:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.