Live audio peak detection from a microphone

Hi,

I'm a new programmer and I'm looking for some help.

Here is my problem. I need to detect peaks in a live audio from a pickup microphone and output the exact time to milliseconds or preferably nanoseconds of the peak in a .txt file.

I have been looking at two possible solutions. The first one was to set up a shell script in linux to record audio increments of 5 seconds via the nohup function and then analyze them in matlab, but the problem here is that the endings and the beginnings of the recorded files are not exactly 5 seconds apart. There is a delay of 50-150 milliseconds when a new file starts recording.

The second option was to do something similar to what they use for clap light switches, but I have no idea how I would extract the exact time from that. And I also don't know if that would work with a pickup microphone or does it just work with a sound sensor (for Arduino...) like it is shown here.http://en.code-bude.net/2014/12/08/how-to-build-a-clap-switch-using-arduino/

I want to know if there is a better solution out there. Can I do this in C++ or java, perhaps? Remember, I need to output the exact time in milli- or nanoseconds.

Thank you guys, much help is appreciated.
I assume you mean MICROseconds, not NANOseconds, but neither is possible with a standard PC/sound card. Keep in mind that at a standard 44.1KHz audio sampling rate the time resolution is about 22 uSec (microsec). The problem is that neither your sound card or OS is likely designed to care at all about real-time measurements so you can probably only hope for tens of milliseconds at best. I suppose if you have some sort of fast pulse in the file to use as a time reference you could calculate a better result based on that but if you're counting on a C++ program to align the file with real time that's tricky. What you really need is a data acquisition card that has it's own internal time-base and can collect data points fast (1MHz is common these days).

If you have no options but PC and sound card I suggest you look into some of the projects that are leveraging that hardware in ways you might find useful like this: http://homediyelectronics.com/projects/howtomakeafreesoundcardpcoscilloscope/
Topic archived. No new replies allowed.