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?
help for sound noise suppression ...
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:
Sound is a waveform, fluctuating both above and below the baseline. Therefore, the average of any sound, loud or quiet, will usually be about zero - or in the case of an 8 bit PCM wave-form, about 127, as the mid point between 0 and 255. So you'll pretty much miss all sound with your algorithm.
What you want instead is the loudness - the offset from the average - so try this instead:
This might be good enough for you. To do this properly you'd normally use an expander algorithm but that is a bit more complex.
What you want instead is the loudness - the offset from the average - so try this instead:
for( cT = 0; cT < nSizeToWrite; cT++ ){ offset = 127 - *((BYTE*)pbSrcData+cT); avg = avg + abs(offset);}...if(avg > 30 ){//record in wave file.
This might be good enough for you. To do this properly you'd normally use an expander algorithm but that is a bit more complex.
thank you Kylotan
i test it but avg in your code is 90 - 100 in silent !
i cant underestand ... sample is amplitude of sound in wave file . then how silence amplitude is not zero or near it. how speaker not play anything but amplitude is so more than zero !!
please tell me expander algorithm if you can !
tanx
i test it but avg in your code is 90 - 100 in silent !
i cant underestand ... sample is amplitude of sound in wave file . then how silence amplitude is not zero or near it. how speaker not play anything but amplitude is so more than zero !!
please tell me expander algorithm if you can !
tanx
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 read that 16bit wave file store sample in 2's complement ...
now every thing change ...
now how can i check silence ? what changes in my code needs?
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 read that 16bit wave file store sample in 2's complement ...
now every thing change ...
now how can i check silence ? what changes in my code needs?
The sample is not the amplitude, it's the current displacement of the audio wave. The amplitude is proportional to the size of the wave, measured from the 2 extremes of the displacement. More about digital audio at Wikipedia.
You must find out what format the samples are stored in to be able to process them properly. If they are signed 16-bit samples, then your 'quiet' range will be around the 0 point (maybe something like -200 to +200). If they are unsigned, then that point will be around 32768 instead of 0.
Your code must read enough bytes to get an entire sample each time, anyway. Often this is just a case of casting the byte pointer to a uint16 pointer (or an int16) and reading the result, then stepping forward 2 bytes to the next sample instead of 1.
You must find out what format the samples are stored in to be able to process them properly. If they are signed 16-bit samples, then your 'quiet' range will be around the 0 point (maybe something like -200 to +200). If they are unsigned, then that point will be around 32768 instead of 0.
Your code must read enough bytes to get an entire sample each time, anyway. Often this is just a case of casting the byte pointer to a uint16 pointer (or an int16) and reading the result, then stepping forward 2 bytes to the next sample instead of 1.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement