1

I have a wav file and all what i need is to perform a function when a remarkable intensity of sound plays.

For example : if there is a sound of intensity level 10 (supposed) is playing so i want that when ever the intensity level of sound increases from 10 then an event should be triggered to tell me that there is a remarkable sound.

I tried to google it and found that if we read the bytes of wav file and read the data chunk (after 44th byte) we get the user data (sound data). but when i analyse this data i got confused because there is also same data where there is no sound.

I hope my question is quite clear. so please i need your suggestions/ideas and references.

svick
  • 236,525
  • 50
  • 385
  • 514
azeem
  • 103
  • 2
  • 7

1 Answers1

3

You don't need an FFT for this - you can just compute the short term RMS power and when this exceeds a predetermined threshold then you have a "loud" sound.

power_RMS = sqrt(sum(x^2) / N)

where x is the sample value and N is the number of samples over which you want to compute RMS power - I would suggest using a period of say 10 ms which gives N = 441 samples at a 44.1 kHz sample rate.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • would u please elaborate this line " I would suggest using a period of say 10 ms = 441 samples at a 44.1 kHz sample rate." – azeem May 05 '12 at 11:20
  • Simple - you just compute power_RMS over each block of N samples in your waveform. I suggested using N = 441 if you have a 441 kHz sample rate, but you may want to experiment with the block size, depending on your particular application. – Paul R May 05 '12 at 11:33
  • :: can the sample value be a negative after converting the byte array of wav file into INT16 array ??? – azeem May 07 '12 at 05:54
  • byte[] data = File.ReadAllBytes(File_textBox.Text); var samples=new int[data.Length]; int x = 0; for (int i = 44; i – azeem May 07 '12 at 05:55
  • Samples should be positive and negative, roughly symmetrical with a mean of around zero. Note that 8 bit sample values are usually offset binary whereas 16 bit samples are usually 2s complement. – Paul R May 07 '12 at 07:25
  • :: please check my own answer to this question please. – azeem May 07 '12 at 07:55
  • @azeem: you need to either edit this into your question or ask this as a separate question, since it's not an answer to the original question. – Paul R May 07 '12 at 07:58
  • here is my next question :: http://stackoverflow.com/questions/10477697/how-to-get-sound-data-sample-value-in-c-sharp/10478064#comment13539732_10478064 – azeem May 07 '12 at 08:19