# help for sound noise suppression ... (directSound)

3 replies to this topic

New Member

• Members
• 3 posts

Posted 25 September 2009 - 07:41 AM

hi
I used DirectSound for recording sound. I want to record only when someone
speeches not when she's silent. So I checked average of capture buffer. If it
is between 123 and 132, sounds aren't recorded:

for( cT = 0; cT < nSizeToWrite; cT++ )

{

avg = avg + *((BYTE*)pbSrcData+cT);

}

avg = avg / nSizeToWrite;

if(avg > 132 || avg < 123 ){

//record in wave file.

...


Unfortunately it doesn't work properly. Silences are recorded mostly. is
that because of environment noise ? how can i suppression it?

### #2Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 25 September 2009 - 04:30 PM

Where are you getting the numbers 123 and 132 from? Those make no sense.

To properly analyze your sound data, you first need to figure out whether it's 8-bit or 16-bit (most likely 16-bit nowadays) and look at it using the appropriate data type (char for 8-bit, short for 16-bit). Note that the data is signed, not unsigned. You can check if the absolute value of the data is bigger than some threshold (maybe this is what you tried to do with your 123-132 thing)? You'll have to experiment to find the right threshold value. Also note that in any sound you'll get a wave that oscillates between positive and negative values. So just a pure threshold check will not work well, as you'll clip out the part of the wave below the threshold and it will distort the sound. Rather, you should do something like keep track of how long it's been below the threshold and stop recording if it's been below the threshold for half a second. Or, calculate the average power over the last half a second and stop recording if it's below a threshold. Again, you'll have to experiment to find the most effective way to do it.
reedbeta.com - developer blog, OpenGL demos, and other projects

New Member

• Members
• 3 posts

Posted 25 September 2009 - 05:51 PM

i see that i use 16bit wave sample !
but my code give me one byte ...
i think that first byte is high byte and second byte is low byte of 16 bit sample and ...
and i think that 16bit wave file store sample in 2's complement ...
now every thing change ...

now how can i check silence ? can you show me in simple code (like my code) what's your offer algorithm ?

### #4Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 25 September 2009 - 06:19 PM

You should just cast your BYTE * to a short * and look at the data as an array of shorts rather than bytes.
reedbeta.com - developer blog, OpenGL demos, and other projects

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users