|
-
February 20th, 2010, 06:06 AM
#1
[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_
-
February 21st, 2010, 03:13 PM
#2
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!
-
February 22nd, 2010, 01:06 AM
#3
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
-
February 22nd, 2010, 11:09 AM
#4
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
-
February 23rd, 2010, 12:51 AM
#5
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.
-
February 23rd, 2010, 08:01 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|