4

I have samples which come from ffmpeg, very often it is 16 bit samples (short type), i have used iir band pass filter with dbGain as described here, after filtering i sometimes got a short type overflow and result of it is some noise when calculated sample value go out from 32767/-32767, Is any way to escape audio pcm sample clipping. May be exists any approaches?

I have googled but not found any worked example?

UPDATE

When i cast transfer function calculation result to integer and check overflow then noise still occurs::

int result = A1 * ((int) Rx) + A2 * ((int) Rxx) + A3 * ((int) Rxxx)
                    - B1 * ((int) Ryy) - B2 * ((int) Ryyy);
if (result > 32767)
    result = 32767;
if (result < -32700)
    result = -32700;
y = (short) result;
4

1 回答 1

2

16-bit PCM samples will have to be in range [-32768..+32767]. If you apply math (biquad filter in your case) onto input signal, the output is not guaranteed to stay within the range, which is the inevitable outcome here in case you are applying positive gain.

Since hitting range boundaries is a natural side effect with this kind of processing, you are supposed to take care of it using one of the approaches (the list is not supposed to be full):

  • make sure your input signal is quiet enough and/or shift values right by a few bits to provide headroom for big values on the output
  • use higher bitness for output signal, such as 24-bit PCM
  • use floating point PCM for output signal to precision loss on going outside of PCM sample range
于 2012-12-19T09:06:33.640 回答