Using a PC and a cheap microphone to interpret sounds from the sound card and
execute a command every time a clap is heard.
First thing to do when detecting claps (or other loud sounds) is it filter out relatively quiet sounds so that background noise is not interpreted as a clap. Once the majority of noise has been filtered out, we want to try to distinguish claps from other loud noises in the room. We may also want these noises to trigger an event (burgler alarm?). To filter claps we do some primitive analysis of the waveform the sound card produces. The linux sound card interface produces integer values for every sample period. With an 8 bit resolution, the waveform is represented by a character array in C (each char is one byte). A char value of 128 represents a volume level of 0 in the waveform, 256 is a maximum and 0 is a minimum.
For more information on Linux Audio Programming, try http://www.4front-tech.com/pguide/audio.html.
In order to clip all noises below a certain level, we will simply disregard all values in the stream less than a predetermined value. In the default case, we will ignore anything under 160. This can vary greatly depending on the room and microphone used. Then, use a rudimentary means for trying to determine the frequency of the given peak. Although this information is not entirely accurate, it is enough for our purposes. Filter the results and call the command. The command is run in the background so execution of the program is not disrupted.
Once compiled, run it with something like the following:
./clap /dev/dsp echo clap!
Thats about it! You can change the command called to be just about anything you like. In order to modify the settings, you currently have to compile them in as they are hardcoded. This should probably be changed.
Eric Buehl ebuehl@andrew.cmu.edu
(1/27/05)