From efdd314305038978062e48bdb98bc9d4832eebbf Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jmvalin@jmvalin.ca>
Date: Sat, 18 May 2013 02:14:24 -0400
Subject: [PATCH] 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.
---
 celt/celt_decoder.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/celt/celt_decoder.c b/celt/celt_decoder.c
index 7df94b567..d5d2c57f9 100644
--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -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));
-- 
GitLab