Commit cd29b027 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

fixed-point: fixing two overflows that didn't really affect quality

parent 7c422653
......@@ -233,6 +233,8 @@ int compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_
Sxy = MAC16_16(Sxy, X[j], P[j]);
Sxx = MAC16_16(Sxx, X[j], X[j]);
Sxy = SHR32(Sxy,2);
Sxx = SHR32(Sxx,2);
/* No negative gain allowed */
if (Sxy < 0)
Sxy = 0;
......@@ -427,18 +427,20 @@ static inline short MULT16_16_Q14(int a, int b)
return res;
static inline short MULT16_16_Q15(int a, int b)
#define MULT16_16_Q15(a, b) _MULT16_16_Q15(a, b, __FILE__, __LINE__)
static inline short _MULT16_16_Q15(int a, int b, char *file, int line)
long long res;
fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d\n", a, b);
fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a, b, file, line);
res = ((long long)a)*b;
res >>= 15;
if (!VERIFY_SHORT(res))
fprintf (stderr, "MULT16_16_Q15: output is not short: %d\n", (int)res);
fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res, file, line);
return res;
......@@ -547,6 +549,6 @@ static inline int _DIV32(long long a, long long b, char *file, int line)
#define PDIV32_16(a,b) DIV32_16(ADD32((a),(b)>>1),b)
#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %d MIPS\n", celt_mips);} while (0);
#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", celt_mips);} while (0);
......@@ -335,7 +335,14 @@ celt_word16_t renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int
rE = celt_sqrt(E);
g = MULT16_16_Q15(value,celt_rcp(SHL32(rE,9)));
/*if (celt_rcp(SHL32(rE,9))>32767)
fprintf (stderr, "celt_rcp: %d %d\n",rE, E); */
if (rE <= 128)
g = Q15ONE;
g = MULT16_16_Q15(value,celt_rcp(SHL32(rE,9)));
xptr = X;
for (i=0;i<N;i++)
......@@ -374,7 +381,6 @@ void intra_fold(const CELTMode *m, celt_norm_t * restrict x, int N, int K, celt_
pred_gain = celt_div((celt_word32_t)MULT16_16(Q15_ONE,N),(celt_word32_t)(N+KGAIN*K));
fold(m, N, Y, P, N0, B);
renormalise_vector(P, pred_gain, C*N, 1);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment