diff --git a/libcelt/bands.c b/libcelt/bands.c index 7b1fe300..9c7142dd 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -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; diff --git a/libcelt/fixed_debug.h b/libcelt/fixed_debug.h index 656dad00..4b90bde7 100644 --- a/libcelt/fixed_debug.h +++ b/libcelt/fixed_debug.h @@ -427,18 +427,20 @@ static inline short MULT16_16_Q14(int a, int b) celt_mips+=3; 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; if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) { - 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); } celt_mips+=1; 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) #undef PRINT_MIPS -#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); #endif diff --git a/libcelt/vq.c b/libcelt/vq.c index 7071c226..488fbcd1 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -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); */ +#ifdef FIXED_POINT + if (rE <= 128) + g = Q15ONE; + else +#endif + g = MULT16_16_Q15(value,celt_rcp(SHL32(rE,9))); xptr = X; for (i=0;i