help for sound noise suppression ... (directSound)

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?

Close doors and windows, turn off the TV, work late at night, use a reasonable quality sound card, use a long microphone lead so that you can move away from the computer fan.


Good idea.


This is only a wild guess, but if you are summing positive and negative numbers, you may wish to add the absolute values or the squares of the samples. Also, to get a better feel for exactly what is happening, consider removing “avg < 123” from your if statement.

I hope this helps.

The first time you do live recording, it’s a shock when you realize how noisy your surroundings are. People sail through their day tuning out the airplanes, buses, cellphones, conversations, etc. I lived on a large farm in upstate NY and it was always funny watching people from New York City trying to deal with missing neighborhood reference noises. When the sun goes down, all the noise stops. Zero. Dead Silence.

That rarely happens in any city and just from personal experience trying to record a “quicky” sound track for a large sound production is a nightmare. The only quiet room in three buildings has echoes and the only room that’s quiet and echo-free is never available when I need it.

Dealing with it in post can be amusing, but rarely workable in real life.

“We’re done with the shoot, where’s the sound file? What do you mean you need to filter and mess with it for two hours?” “Who’s this Nyquist guy?”


thanks every body !
i work for one company that they want from me to do this.

i use below sample and my code do beter but not good ! i miss some low sound and some silence be recorded yet !
(my wave file is 16bit and i didn’t attention)

for( cT = 0; cT < nSizeToWrite; cT=cT+2 )
	offset = 127 - *((BYTE*)pbSrcData+cT);
	avg2 = avg2 + abs(offset);
avg2 = avg2 / nSizeToWrite * 2;

if(avg2 > 64){

i cant underestand that whay silence amplitude is far from zero … and how speaker dont playing silence with these amplitude !? whether wave file sample is not amplitude of sound?

On a scale of 0 to 1
Absolute silence is 0.0000
“Silence” is in the region of 0.000015 (1 bit - is that right?)
Very quiet is in the region of 0.001 (-60dB)
Self noise from a laptop microphone is in the region of 0.01
-20 dB = 0.1
-6dB = 0.5
Full scale = 1.0000

People pay good money to get sound numbers closer and closer to perfect. Quiet Noise is always present, but now much noise you have depends on money. Directly. The built-in sound card in your laptop can have very bad noise even if you plug an expensive microphone in. The intense electrical noise inside the computer is competing with your show.

Field news sound mixers and inexpensive USB sound cards can do OK, but the first time you use a top professional microphone preamplifier is a shock because the only noise in the performance came from the performance, not the electronics in the middle.

You can remove noise in post production, but the result never sounds particularly good because the process also removes the subtle hints that you’re listening to a live performance and not a machine. One of the commercial producers here tried to record in a scientific echo-free room once. It was terrible. They had to put noise back in to keep the show from sounding science fiction.

Good luck. And a note that noise removal changes a lot depending on the performance. So you may find one that works on one song…


tnx everyone
speakers dont play silence… i want to be in place of speaker … speaker get some sound samples (from wav file) , if speaker dont play any thing means those samples were silence. how speaker don’t play some samples? i want to be in place of speaker and detect samples that speaker dont play… why speaker can detect silence for no playing and we cant detect it for dont recording !?

The blue waves on the timeline and the bouncing green lights of the sound meter will work no matter what the sound is. People do not work like that.

If you have very low sounds, like a heavy truck driving by your house or an earthquake, you can record very loud sounds in Audacity, but when you listen to the show, you hear nothing, or only very quiet rumbling. Cheap speakers or headphones are even worse. They will not make very low sounds at all.

Same with high sounds. Microphone amplifiers can make sssss noise that dogs and very young women can hear, but most men can not – but there, again, are the Audacity blue waves and meters.

You can use Analyze > Spectrum to see what kind of noise you have, and maybe why you can’t hear it.


i use below code and it work very well !!! (for 8bit wave file)

for( cT = 0; cT < nSizeToWrite; cT=cT+1 )
	offset2 = 127 - *((BYTE*)pbSrcData+cT);
	offset = abs(offset2);
	avg = avg + offset*offset;
db = (float)sqrt(avg/nSizeToWrite)/256;
db = 20*log10(db);

if(db > -50) {

Glad to hear you’ve got it working!