CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2010
    Posts
    7

    Lightbulb [Help] how do you trigger an event using sound?

    I have writhen a windows form using C# that counts how long time there is between button presses and then show some statistics.

    BUT now i want to make it work with sound instead.
    the sound that I want it to react to is a gun shot, so it is rather loud :P
    and of course i want it to ignore every other noice.

    the code i have used looks like this:

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyCode==Keys.S)
    {
    ..........
    }
    }

    it would be really helpful if somebody could post some example code for me.

    if you like to know more about my little projekt and see how it end you could follow me on twitter my name there is kimlundgren_

  2. #2
    Join Date
    Feb 2010
    Posts
    7

    Re: [Help] how do you trigger an event using sound?

    plz help me with this!

    Im done with everything else in my program, so I would be really greatful to any help!

  3. #3
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: [Help] how do you trigger an event using sound?

    I am assuming that the sound is generated by the same application.

    So, make the code that generates the "gun shot" sound, fire an event, and you can have an handler for that event process this event.

    If the sound is generated by a different application, then you will need to modify both the applications to use IPC mechanism like named pipe:
    http://bartdesmet.net/blogs/bart/arc...med-pipes.aspx

  4. #4
    Join Date
    Feb 2010
    Posts
    7

    Smile Re: [Help] how do you trigger an event using sound?

    Thanks for your reply.

    But no the sound will be generated by a real gun.

    The idéa is that a laptop running the program will stand next to the a person shoting and time the shoter by reacting when it hear the gunshot.

    //kim

  5. #5
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: [Help] how do you trigger an event using sound?

    In that case, you may need to use audio capture library like DirectSound
    http://msdn.microsoft.com/en-us/libr...70(VS.85).aspx

    I have not done anything like this. So, not sure how you can go about implementing this:
    But basic stuff you need to do is:
    1. Create a thread that constantly captures audio from Microphone using DirectSound
    2. Detect "Gun shot" sound from the audio data capture

    The second step may involve some complex DSP algorithm or just check on the amplitude.

  6. #6
    Join Date
    Feb 2010
    Posts
    7

    Thumbs up Re: [Help] how do you trigger an event using sound?

    Thanks for your reply.

    Yes I think something like that should work.
    And Im guessing that checking the amplitude should work perfect, because the gun shot will probably max the microphone to its upper limit.

    I shall read your link later and see if I can figure out how to wriht it.
    //kim

Tags for this Thread

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