shithub: opus

Download patch

ref: 47bf175f292d83479ada061e3f9529d63b0a3c69
parent: 68b02b10252dec071b6824d262abeb7c635774dc
author: Jean-Marc Valin <[email protected]>
date: Thu Feb 28 19:07:00 EST 2008

fixed-point: a few more bits converted from the energy quantisation. Almost done

--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -53,7 +53,7 @@
 static inline celt_ener_t dB2Amp(celt_ener_t dB)
 {
    celt_ener_t amp;
-   amp = PSHR32(celt_exp2(dB/6.0207*8),2)-QCONST16(.3f, 14);
+   amp = PSHR32(celt_exp2(MULT16_16_Q14(21771,dB)),2)-QCONST16(.3f, 14);
    if (amp < 0)
       amp = 0;
    return amp;
@@ -81,6 +81,7 @@
 }
 #endif
 
+static const celt_word16_t base_resolution = QCONST16(6.f,8);
 
 #ifdef FIXED_POINT
 #define Q8 256.f
@@ -105,13 +106,11 @@
    {
       int qi;
       celt_word16_t q;   /* dB */
-      celt_word16_t res; /* dB */
       celt_word16_t x;   /* dB */
       celt_word16_t f;   /* Q8 */
       celt_word16_t mean = (1-coef)*eMeans[i];
       x = amp2dB(eBands[i]);
-      res = DB_SCALING*6;
-      f = QCONST16(1.f,8)*(x-mean-coef*oldEBands[i]-prev*1.f)/res;
+      f = DIV32_16(SHL32(EXTEND32(x-mean-coef*oldEBands[i]-prev),8),base_resolution);
 #ifdef FIXED_POINT
       /* Rounding to nearest integer here is really important! */
       qi = (f+128)>>8;
@@ -125,7 +124,7 @@
          qi = -1;
       else
          ec_laplace_encode(enc, qi, 6000-i*200);
-      q = qi*res;
+      q = qi*base_resolution;
       error[i] = f - SHL16(qi,8);
       
       /*printf("%d ", qi);*/
@@ -180,15 +179,13 @@
    {
       int qi;
       celt_word16_t q;
-      celt_word16_t res;
       celt_word16_t mean = (1-coef)*eMeans[i];
-      res = DB_SCALING*6.;
       /* If we didn't have enough bits to encode all the energy, just assume something safe. */
       if (ec_dec_tell(dec, 0) - bits > budget)
          qi = -1;
       else
          qi = ec_laplace_decode(dec, 6000-i*200);
-      q = qi*res;
+      q = qi*base_resolution;
       
       /*printf("%d ", qi);*/
       /*printf("%f %f ", pred+prev+q, x);*/