How to avoid sampling 16-bit sound after equalization?

I have samples that come from ffmpeg, very often these are 16-bit samples (short type), I used an iir bandwidth filter with dbGain as described here , after filtering I sometimes got a short-term overflow, and there was some noise as a result when the computed sample value is out of 32767 / -32767. Is there a way to avoid clipping pcm audio samples. Can there be any approaches?

I have googled but no working example found?

UPDATE

When I pass the result of the calculation of the transfer function to an integer and check the 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
source share
1 answer

16-bit PCM samples should be in the range [-32768 .. + 32767]. If you apply math (the biquad filter in your case) to the input signal, the output will not be guaranteed to remain within the range, which is an inevitable result here if you apply a positive gain.

Since hitting the borders of the range is a natural side effect of this processing, you should take care of this using one of the approaches (the list should not be filled):

  • make sure your input signal is quiet enough and / or shifts values ​​by a few bits to provide margin for large output values.
  • use higher bitrate for output, e.g. 24-bit PCM
  • Use a floating-point PLC for the output signal for precision loss beyond the PCM sampling range.
+2
source

All Articles