Fixes fixed-point PLC issue reported in trac ticket #1954
A fixed shift factor was insufficient to properly estimate the decay
factor, resulting in extreme attenuation of the PLC excitation.
diff --git a/celt/celt_decoder.c b/celt/celt_decoder.c
index 7df94b5..d5d2c57 100644
--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -506,14 +506,17 @@
{
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));