Fixes fixed-point PLC issue reported in trac ticket #1954
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Sat, 18 May 2013 06:14:24 +0000 (02:14 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Sat, 18 May 2013 06:18:42 +0000 (02:18 -0400)
A fixed shift factor was insufficient to properly estimate the decay
factor, resulting in extreme attenuation of the PLC excitation.

celt/celt_decoder.c

index 7df94b5..d5d2c57 100644 (file)
@@ -506,14 +506,17 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
          {
             opus_val32 E1=1, E2=1;
             int decay_length;
+#ifdef FIXED_POINT
+            int shift = IMAX(0,2*celt_zlog2(celt_maxabs16(&exc[MAX_PERIOD-exc_length], exc_length))-20);
+#endif
             decay_length = exc_length>>1;
             for (i=0;i<decay_length;i++)
             {
                opus_val16 e;
                e = exc[MAX_PERIOD-decay_length+i];
-               E1 += SHR32(MULT16_16(e, e), 8);
+               E1 += SHR32(MULT16_16(e, e), shift);
                e = exc[MAX_PERIOD-2*decay_length+i];
-               E2 += SHR32(MULT16_16(e, e), 8);
+               E2 += SHR32(MULT16_16(e, e), shift);
             }
             E1 = MIN32(E1, E2);
             decay = celt_sqrt(frac_div32(SHR32(E1, 1), E2));