ref: 68d21fb5b0c1f38ef9fc82344094cf02103282c3
parent: 78fe48adfb5b849f263629d391878c7d34596f11
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Sat Jul 2 23:07:00 EDT 2022
Fix fixed-point overflow in pitch downsampling Reviewed by Mark Harris
--- a/celt/pitch.c
+++ b/celt/pitch.c
@@ -161,17 +161,26 @@
shift=0;
if (C==2)
shift++;
-#endif
for (i=1;i<len>>1;i++)
- x_lp[i] = SHR32(HALF32(HALF32(x[0][(2*i-1)]+x[0][(2*i+1)])+x[0][2*i]), shift);
- x_lp[0] = SHR32(HALF32(HALF32(x[0][1])+x[0][0]), shift);
+ x_lp[i] = SHR32(x[0][(2*i-1)], shift+2) + SHR32(x[0][(2*i+1)], shift+2) + SHR32(x[0][2*i], shift+1);
+ x_lp[0] = SHR32(x[0][1], shift+2) + SHR32(x[0][0], shift+1);
if (C==2)
{
for (i=1;i<len>>1;i++)
- x_lp[i] += SHR32(HALF32(HALF32(x[1][(2*i-1)]+x[1][(2*i+1)])+x[1][2*i]), shift);
- x_lp[0] += SHR32(HALF32(HALF32(x[1][1])+x[1][0]), shift);
+ x_lp[i] += SHR32(x[1][(2*i-1)], shift+2) + SHR32(x[1][(2*i+1)], shift+2) + SHR32(x[1][2*i], shift+1);
+ x_lp[0] += SHR32(x[1][1], shift+2) + SHR32(x[1][0], shift+1);
}
-
+#else
+ for (i=1;i<len>>1;i++)
+ x_lp[i] = .25f*x[0][(2*i-1)] + .25f*x[0][(2*i+1)] + .5f*x[0][2*i];
+ x_lp[0] = .25f*x[0][1] + .5f*x[0][0];
+ if (C==2)
+ {
+ for (i=1;i<len>>1;i++)
+ x_lp[i] += .25f*x[1][(2*i-1)] + .25f*x[1][(2*i+1)] + .5f*x[1][2*i];
+ x_lp[0] += .25f*x[1][1] + .5f*x[1][0];
+ }
+#endif
_celt_autocorr(x_lp, ac, NULL, 0,
4, len>>1, arch);