CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Detecting peaks in realtime from a microphone

    Hi to all.

    I start by apologizing for my newbyosity in this field of c++, that is audio tracks. I understand, however, the principles behind sampling and sound recording issues in a computer.

    I put in open terms. I am developing a software that needs to be able to detect when the microphone input sound reaches a certain level.

    I see the API native functions for the waveforms, like waveIn..., waveOut... and so on, but I don't know what to choice to get sound in input in realtime.
    The problem is not so difficult, if I could access the values of incoming samples, even one each X samples, and compare it with a percentage of the maximum value allowing by input device dynamics. The fact is, I don't know how to do, and if it is possible with the waveform functions I named.

    Sorry for the problem-specific question, I appreciate any help.

    Thanks in advance. Oh, and happy 2010!!!
    - Buzzyous -

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Detecting peaks in realtime from a microphone

    Reading the peaks is the trivial part. Just iterate through your audio buffer and keep the highest value. The tough part is implementing a routine to sample the audio. Check out some of the classes here:

    http://www.codeproject.com/KB/audio-...eo%20-%20Audio

    and here:

    http://www.codeguru.com/cpp/g-m/multimedia/

    I've looked at many and used ideas from several to come up with an implementation right for my own purposes.

  3. #3
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: Detecting peaks in realtime from a microphone

    I viewed some of these, and found some interesting. Still reading, there are many articles. Thank you for the addressing.

    But, you said the difficult part is to sample the audio; there are API functions that record the input audio to save it in a file. Could that data be read or interpreted as sampled audio in RT, block by block, instead of sending them to a file on memory? Do I really need to do the sampling on my own?

    I mean, when I have a HWAVEIN received with WaveIn function, could I navigate the data related to it as an "array of samples", or something like that?
    Last edited by Buzzyous; January 6th, 2010 at 03:15 AM.
    - Buzzyous -

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Detecting peaks in realtime from a microphone

    Windows API adds some simple wrappers for all the necessary handling of simple playback (sndPlaySound() ) but it obscures all the internal stuff from the user. I don't know of any way to get at the actual buffers. Nonetheless, recording is a different beast altogether. I don't know of any other way than to: acutally define a callback, threadproc, or message handler called each time the buffer is filled by the sound hardware; create the buffers; then continuously manage the buffers (save to file, monitor, etc.) each time the callback signals a full buffer. It's an ugly process and I understand that it is a little better using DirectX sound APIs, but I've never gone that route.

  5. #5
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: Detecting peaks in realtime from a microphone

    You've been very clear. Thank you again, I will try something out of your suggestion.
    - Buzzyous -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured