shithub: opus

Download patch

ref: 2805a14ecac4a42fbae742b95f87047c7500032e
parent: 5f09ea5659cfed80efc1ea22ced84c0b278a6f35
author: Jean-Marc Valin <[email protected]>
date: Tue Feb 26 12:02:08 EST 2008

fixed-point: celt_pgain_t now a 16-bit value (Q15)

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -54,19 +54,19 @@
 typedef celt_word32_t celt_sig_t;
 typedef celt_word16_t celt_norm_t;
 typedef celt_word32_t celt_ener_t;
-typedef float celt_pgain_t;
+typedef celt_word16_t celt_pgain_t;
 typedef float celt_mask_t;
 
 #define Q15ONE 32767
 
 #define SIG_SCALING 16384.f
-#define SIG_SCALING_1 0.000061035
+#define SIG_SCALING_1 (1.f/16384.f)
 #define NORM_SCALING 16384.f
-#define NORM_SCALING_1 0.000061035
+#define NORM_SCALING_1 (1.f/16384.f)
 #define ENER_SCALING 16384.f
-#define ENER_SCALING_1 0.000061035
-#define PGAIN_SCALING 1.f
-#define PGAIN_SCALING_1 1.f
+#define ENER_SCALING_1 (1.f/16384.f)
+#define PGAIN_SCALING 32768.f
+#define PGAIN_SCALING_1 (1.f/32768.f)
 
 #define VERY_SMALL 0
 #define VERY_LARGE32 ((celt_word32_t)2147483647)
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -178,7 +178,7 @@
          gain = 0.0f;
       /* We need to be a bit conservative, otherwise residual doesn't quantise well */
       gain *= .9f;
-      gains[i] = gain;
+      gains[i] = PGAIN_SCALING*gain;
       /*printf ("%f ", 1-sqrt(1-gain*gain));*/
    }
    /*if(rand()%10==0)
@@ -201,7 +201,7 @@
    {
       int j;
       for (j=B*pBands[i];j<B*pBands[i+1];j++)
-         P[j] *= gains[i];
+         P[j] *= PGAIN_SCALING_1*gains[i];
       /*printf ("%f ", gain);*/
    }
    for (i=B*pBands[m->nbPBands];i<B*pBands[m->nbPBands+1];i++)
--- a/libcelt/quant_pitch.c
+++ b/libcelt/quant_pitch.c
@@ -69,12 +69,12 @@
    ALLOC(g2, len, float);
    /*for (i=0;i<len;i++) printf ("%f ", gains[i]);printf ("\n");*/
    for (i=0;i<len;i++)
-      g2[i] = 1-sqrt(1-gains[i]*gains[i]);
+      g2[i] = 1-sqrt(1-PGAIN_SCALING_1*PGAIN_SCALING_1*gains[i]*gains[i]);
    id = vq_index(g2, pgain_table, len, 128);
    ec_enc_uint(enc, id, 128);
    /*for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");*/
    for (i=0;i<len;i++)
-      gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
+      gains[i] = PGAIN_SCALING*(sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
    return id!=0;
 }
 
@@ -83,6 +83,6 @@
    int i, id;
    id = ec_dec_uint(dec, 128);
    for (i=0;i<len;i++)
-      gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
+      gains[i] = PGAIN_SCALING*(sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
    return id!=0;
 }