diff --git a/celt/arch.h b/celt/arch.h index 3845c3a08..c14b775eb 100644 --- a/celt/arch.h +++ b/celt/arch.h @@ -132,9 +132,14 @@ typedef opus_val32 celt_ener; #define Q15ONE 32767 #define SIG_SHIFT 12 -/* Safe saturation value for 32-bit signals. Should be less than - 2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/ -#define SIG_SAT (300000000) +/* Safe saturation value for 32-bit signals. We need to make sure that we can + add two sig values and that the first stages of the MDCT don't cause an overflow. + The most constraining is the ARM_ASM comb filter where we shift left by one + and then add two values. Because of that, we use 2^29-1. SIG_SAT must be large + enough to fit a full-scale high-freq tone through the prefilter and comb filter, + meaning 1.85*1.75*2^(15+SIG_SHIFT) = 434529895. + so the limit should be about 2^31*sqrt(.5). */ +#define SIG_SAT (536870911) #define NORM_SCALING 16384 diff --git a/celt/celt_decoder.c b/celt/celt_decoder.c index ef92c3435..87b190fd2 100644 --- a/celt/celt_decoder.c +++ b/celt/celt_decoder.c @@ -261,8 +261,8 @@ static void deemphasis_stereo_simple(celt_sig *in[], opus_val16 *pcm, int N, con { celt_sig tmp0, tmp1; /* Add VERY_SMALL to x[] first to reduce dependency chain. */ - tmp0 = x0[j] + VERY_SMALL + m0; - tmp1 = x1[j] + VERY_SMALL + m1; + tmp0 = SATURATE(x0[j] + VERY_SMALL + m0, SIG_SAT); + tmp1 = SATURATE(x1[j] + VERY_SMALL + m1, SIG_SAT); m0 = MULT16_32_Q15(coef0, tmp0); m1 = MULT16_32_Q15(coef0, tmp1); pcm[2*j ] = SCALEOUT(SIG2WORD16(tmp0)); @@ -314,7 +314,7 @@ void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, c opus_val16 coef3 = coef[3]; for (j=0;j