From 1ad93cf485b344abc9f8c67e4120fdb29536ea03 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sat, 6 Nov 2010 22:02:32 -0400 Subject: [PATCH] Fixes several fixed-point overflows in the PLC code --- libcelt/celt.c | 11 ++++++++--- libcelt/mathops.c | 7 +++---- libcelt/plc.c | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index fe92075c..450bde5a 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -1458,13 +1458,15 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p /* Copy excitation, taking decay into account */ for (i=0;imode->overlap;i++) { + celt_word16 tmp; if (offset+i >= MAX_PERIOD) { offset -= pitch_index; decay = MULT16_16_Q15(decay, decay); } e[i] = SHL32(EXTEND32(MULT16_16_Q15(decay, exc[offset+i])), SIG_SHIFT); - S1 += SHR32(MULT16_16(out_mem[c][offset+i],out_mem[c][offset+i]),8); + tmp = ROUND16(out_mem[c][offset+i],SIG_SHIFT); + S1 += SHR32(MULT16_16(tmp,tmp),8); } for (i=0;i SHR32(S2,2))) @@ -1490,7 +1495,7 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p { celt_word16 ratio = celt_sqrt(frac_div32(SHR32(S1,1)+1,S2+1)); for (i=0;i