How to detect silience with IMediaSample in PCM audio
===

I need to detect silience in PCM audio stream with IMediaSample. Signal is provided by TV and is connected with PC by optic cable to Prodigy 7.1 HiFi soundcard. So far I have this:

    bool detectSound(IMediaSample *pSamples)
    {
        BYTE *pData;
        pSamples->GetPointer(&pData);
        long size = pSamples->GetActualDataLength();

        long nulls = 0;
        for(long i = 0; i < size; ++i) {
            if(pData[i] == 0)
                ++nulls;
        }

        /* 0.9 to eliminate interference */
        long max_nulls = (long) (0.9 * size);
        if(nulls > max_nulls) {                 /* STOP */
            /* no audio */
            return false;
        }
        else {
            /* audio available */
            return true;
        }
    }

The problem is that if I put breakpoint at line marked "STOP", nulls has nearly always the same value and is smaller than max_nulls no matter if I mute TV or not. I noticed that pData[i] values are always 0 or 255. (strange, or not?)

Probably I don't understand what exactly this "data" is and how to interpret it. All I'm sure of is that  if there is no audio than all sampled values from waveform should be almost 0.

Could you verify my way of thinking? Thanks in advance.

eclipse
