shithub: opus

Download patch

ref: ee44ff86c6ae55eb5c4b568b3822c9b280514c53
parent: 76596ad93a7869e6b877dc44cefda45cde1b3e8b
author: Jean-Marc Valin <[email protected]>
date: Mon Jul 25 06:23:07 EDT 2016

Move PLC LPC bandwidth expansion before the FIR to avoid overflows in celt_fir()

--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -567,7 +567,24 @@
 #endif
             }
             _celt_lpc(lpc+c*LPC_ORDER, ac, LPC_ORDER);
+#ifdef FIXED_POINT
+         /* For fixed-point, apply bandwidth expansion until we can guarantee that
+            no overflow can happen in the IIR filter. This means:
+            32768*sum(abs(filter)) < 2^31 */
+         while (1) {
+            opus_val16 tmp=Q15ONE;
+            opus_val32 sum=QCONST16(1., SIG_SHIFT);
+            for (i=0;i<LPC_ORDER;i++)
+               sum += ABS16(lpc[c*LPC_ORDER+i]);
+            if (sum < 65535) break;
+            for (i=0;i<LPC_ORDER;i++)
+            {
+               tmp = MULT16_16_Q15(QCONST16(.99f,15), tmp);
+               lpc[c*LPC_ORDER+i] = MULT16_16_Q15(lpc[c*LPC_ORDER+i], tmp);
+            }
          }
+#endif
+         }
          /* We want the excitation for 2 pitch periods in order to look for a
             decaying signal, but we can't get more than MAX_PERIOD. */
          exc_length = IMIN(2*pitch_index, MAX_PERIOD);
@@ -638,23 +655,6 @@
                   SIG_SHIFT);
             S1 += SHR32(MULT16_16(tmp, tmp), 10);
          }
-#ifdef FIXED_POINT
-         /* For fixed-point, apply bandwidth expansion until we can guarantee that
-            no overflow can happen in the IIR filter. This means:
-            32768*sum(abs(filter)) < 2^31 */
-         while (1) {
-            opus_val16 tmp=Q15ONE;
-            opus_val32 sum=QCONST16(1., SIG_SHIFT);
-            for (i=0;i<LPC_ORDER;i++)
-               sum += ABS16(lpc[c*LPC_ORDER+i]);
-            if (sum < 65535) break;
-            for (i=0;i<LPC_ORDER;i++)
-            {
-               tmp = MULT16_16_Q15(QCONST16(.99f,15), tmp);
-               lpc[c*LPC_ORDER+i] = MULT16_16_Q15(lpc[c*LPC_ORDER+i], tmp);
-            }
-         }
-#endif
          {
             opus_val16 lpc_mem[LPC_ORDER];
             /* Copy the last decoded samples (prior to the overlap region) to