shithub: opus

Download patch

ref: cd29b0277316bcdee6aa970f86a98dcc8523da43
parent: 7c422653f3fd27efd1b6e40e4f6bb438bc9de2ab
author: Jean-Marc Valin <[email protected]>
date: Wed Jul 1 05:59:21 EDT 2009

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

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -233,6 +233,8 @@
          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;
--- a/libcelt/fixed_debug.h
+++ b/libcelt/fixed_debug.h
@@ -427,18 +427,20 @@
    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 @@
 #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
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -335,7 +335,14 @@
    }
 
    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<N;i++)
    {
@@ -374,7 +381,6 @@
       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);
 }