Thanks,
Eduardo
I'm not an expert on algorithms for silence detection, but the simple ones I
know of usually involve estimating the energy present in small sections of
the signal. Basically, you section the pcm stream into small chunks, say
100 mS or so in length, and sum the squares (or, alternatively, the absolute
values) of the samples in each interval. If your application only requires
the detection of relatively long intervals of silence, you can use larger
sections. The sums are then compared to a silence threshold value -- if a
given sum is less than the threshold value, that section is considered to
contain silence. In practice, the silence threshold is probably best
determined adaptively since the noise floor can vary across pcm streams or
even within a given pcm stream.
Hope this helps!
"Eduardo" <ale...@bestway.com.br> wrote in message
news:emDVgoL8$GA.275@cppssbbsa05...
> Hope this helps!
Yes, it helps a lot, thanks!
128 represents a sample value of 0 in 8-bit pcm format, so an 8-bit pcm file
of "absolute silence" ought to consist of a series of unsigned characters
with value 0x80. However, keep in mind that the 128 is a bias that you
should remove from 8-bit data before doing any calculations with it. For
example:
// suppose pcm8Buffer[] has 100 mS of 8-bit, 22.05 kHz mono samples in it
float energy = 0.0;
for (int i = 0; i < 2205; i++)
{
float sampleVal;
// remove the bias (8-bit only)
sampleVal = (float) (pcm8Buffer[i] - 128);
// accumulate the energy estimate
energy += (sampleVal * sampleVal);
}
// compare the estimate with the threshold
if (energy < SILENCE_THRESHOLD)
// looks like silence
else
// looks like signal
Once the bias has been removed from each sample, you're free to square and
sum to your heart's content. Note that if all of my pcm unsigned chars are
0x80, then once I remove the bias I'm squaring and summing the number 0.0,
so my energy estimate will end up 0.0 as well. This makes sense, since
there's no signal present at all in that case. Of course, you probably
won't ever see a pcm file like this in practice unless it was artificially
generated -- there's always some modest electrical noise associated with
sound cards in PCs, so you'll probably see data that hovers around 0x80
rather than being dead on.
One last suggestion: if you're planning to work with both 8-bit and 16-bit
pcm data, you probably want to scale up the 8-bit data so you can use the
same threshold for both types:
if ( /* pcm data is in 8-bit format */)
sampleVal = (float) (pcmBuffer[i] - 128) * 256.0;
else ( /* pcm data is in 16-bit format */)
sampleVal = (float) pcmBuffer[i];
Regards,
Eduardo
Richard S. Vidil <rvi...@home.com> escreveu nas notícias de
mensagem:OmlTZVO8$GA....@cppssbbsa02.microsoft.com...