shithub: opus

Download patch

ref: ba8e2f7b2932cd68a6ff3f19c695a0771a0ec7b9
parent: c81330822b5727812a30a43fd33552a2af1e5c0b
author: Jean-Marc Valin <[email protected]>
date: Thu Mar 6 19:21:40 EST 2008

fixed-point: done converting quant_bands() and unquant_bands()

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -39,6 +39,7 @@
 #include "vq.h"
 #include "cwrs.h"
 #include "os_support.h"
+#include "mathops.h"
 
 void exp_rotation(celt_norm_t *X, int len, celt_word16_t theta, int dir, int stride, int iter)
 {
@@ -233,13 +234,11 @@
    for (i=0;i<m->nbEBands;i++)
    {
       int q;
-      celt_word16_t theta;
-      float n;
+      celt_word16_t n;
       q = pulses[i];
       /*Scale factor of .0625f is just there to prevent overflows in fixed-point
        (has no effect on float)*/
-      n = .0625f*sqrt(B*(eBands[i+1]-eBands[i]));
-      theta = Q15ONE*.007*(B*(eBands[i+1]-eBands[i]))/(.1f+q);
+      n = SHL16(celt_sqrt(B*(eBands[i+1]-eBands[i])),11);
 
       /* If pitch isn't available, use intra-frame prediction */
       if (eBands[i] >= m->pitchEnd || q<=0)
@@ -256,6 +255,7 @@
       
       if (q > 0)
       {
+         celt_word16_t theta = DIV32_16(MULT16_16_16(QCONST16(.007f,15),B*(eBands[i+1]-eBands[i])),q);
          exp_rotation(P+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, -1, B, 8);
          exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, -1, B, 8);
          alg_quant(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], alpha, enc);
@@ -262,7 +262,7 @@
          exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, 1, B, 8);
       }
       for (j=B*eBands[i];j<B*eBands[i+1];j++)
-         norm[j] = X[j] * n;
+         norm[j] = MULT16_16_Q15(n,X[j]);
    }
    for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
       X[i] = 0;
@@ -295,13 +295,11 @@
    for (i=0;i<m->nbEBands;i++)
    {
       int q;
-      celt_word16_t theta;
-      float n;
+      celt_word16_t n;
       q = pulses[i];
       /*Scale factor of .0625f is just there to prevent overflows in fixed-point
       (has no effect on float)*/
-      n = .0625f*sqrt(B*(eBands[i+1]-eBands[i]));
-      theta = Q15ONE*.007*(B*(eBands[i+1]-eBands[i]))/(.1f+q);
+      n = SHL16(celt_sqrt(B*(eBands[i+1]-eBands[i])),11);
 
       /* If pitch isn't available, use intra-frame prediction */
       if (eBands[i] >= m->pitchEnd || q<=0)
@@ -318,12 +316,13 @@
       
       if (q > 0)
       {
+         celt_word16_t theta = DIV32_16(MULT16_16_16(QCONST16(.007f,15),B*(eBands[i+1]-eBands[i])),q);
          exp_rotation(P+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, -1, B, 8);
          alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], alpha, dec);
          exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, 1, B, 8);
       }
       for (j=B*eBands[i];j<B*eBands[i+1];j++)
-         norm[j] = X[j] * n;
+         norm[j] = MULT16_16_Q15(n,X[j]);
    }
    for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
       X[i] = 0;