Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pcm - detect silence

1,231 views
Skip to first unread message

Eduardo

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
I want to understand the theory behind a raw uncompressed pcm file. For
example, I want to read the bytes and detect silence. Any good url for it?

Thanks,


Eduardo

Richard S. Vidil

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
Uncompressed PCM is pretty simple. Samples are stored either as unsigned
chars (8-bit PCM) or signed short integers (16-bit PCM). In the 8-bit case,
sample values range from 0 to 255 with an implied offset of 128 (i.e., 0 is
the most negative value, 128 is the "zero" value, and 255 is the most
positive). In the 16-bit case, sample values range from -32768 (most
negative) to 32767 (most positive) with 0 as the "zero" value.

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...

Eduardo

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
Just one more question. Absolute silence (no energy) would be 128?

> Hope this helps!
Yes, it helps a lot, thanks!

Richard S. Vidil

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to

"Eduardo" <ale...@bestway.com.br> wrote in message
news:#SgHMzM8$GA.281@cppssbbsa04...

> Just one more question. Absolute silence (no energy) would be 128?
>

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];

Eduardo

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to

The bytes are coming from the modem and actually 99% of them are of a value
of 128 (0x80) when in silence. It is working very well now. Thank you very
much!

Regards,

Eduardo


Richard S. Vidil <rvi...@home.com> escreveu nas notícias de
mensagem:OmlTZVO8$GA....@cppssbbsa02.microsoft.com...

0 new messages