shithub: opus

Download patch

ref: 70c8ffdd5500a07a890762fdcd7b11df5d7b2ab2
parent: fc08d0a6d63a5453a8928bd5f77e30cf73f13073
author: Jean-Marc Valin <[email protected]>
date: Fri Dec 7 09:20:01 EST 2007

More decoding work

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -177,39 +177,29 @@
       X[i] = 0;
 }
 
-
-/* Scales the pulse-codebook entry in each band such that unit-energy is conserved when 
-   adding the pitch */
-void pitch_renormalise_bands(const CELTMode *m, float *X, float *P)
+void unquant_bands(const CELTMode *m, float *X, float *P, ec_dec *dec)
 {
-   int i, B;
+   int i, j, B;
    const int *eBands = m->eBands;
    B = m->nbMdctBlocks;
+   float norm[B*eBands[m->nbEBands+1]];
+   
    for (i=0;i<m->nbEBands;i++)
    {
-      int j;
-      float Rpp=0;
-      float Rxp=0;
-      float Rxx=0;
-      float gain1;
-      for (j=B*eBands[i];j<B*eBands[i+1];j++)
-      {
-         Rxp += X[j]*P[j];
-         Rpp += P[j]*P[j];
-         Rxx += X[j]*X[j];
+      int q, id;
+      q = m->nbPulses[i];
+      if (q>0) {
+         float n = sqrt(B*(eBands[i+1]-eBands[i]));
+         alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], dec);
+         for (j=B*eBands[i];j<B*eBands[i+1];j++)
+            norm[j] = X[j] * n;
+      } else {
+         float n = sqrt(B*(eBands[i+1]-eBands[i]));
+         //copy_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i], dec);
+         for (j=B*eBands[i];j<B*eBands[i+1];j++)
+            norm[j] = X[j] * n;
       }
-      float arg = Rxp*Rxp + 1 - Rpp;
-      if (arg < 0)
-         arg = 0;
-      gain1 = sqrt(arg)-Rxp;
-      Rxx = 0;
-      for (j=B*eBands[i];j<B*eBands[i+1];j++)
-      {
-         X[j] = P[j]+gain1*X[j];
-         Rxx += X[j]*X[j];
-      }
    }
    for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
       X[i] = 0;
 }
-
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -35,6 +35,7 @@
 
 #include "modes.h"
 #include "entenc.h"
+#include "entdec.h"
 
 void compute_band_energies(const CELTMode *m, float *X, float *bands);
 
@@ -48,6 +49,6 @@
 
 void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc);
 
-void pitch_renormalise_bands(const CELTMode *m, float *X, float *P);
+void unquant_bands(const CELTMode *m, float *X, float *P, ec_dec *dec);
 
 #endif /* BANDS_H */
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -243,6 +243,16 @@
    /* Residual quantisation */
    quant_bands(st->mode, X, P, &st->enc);
    
+   if (0) {//This is just for debugging
+      ec_enc_done(&st->enc);
+      ec_dec dec;
+      ec_byte_readinit(&st->buf,ec_byte_get_buffer(&st->buf),ec_byte_bytes(&st->buf));
+      ec_dec_init(&dec,&st->buf);
+
+      unquant_bands(st->mode, X, P, &dec);
+      //printf ("\n");
+   }
+   
    /* Synthesis */
    denormalise_bands(st->mode, X, bandE);
 
@@ -362,7 +372,17 @@
    float bandE[st->mode->nbEBands];
    float gains[st->mode->nbPBands];
    int pitch_index;
-
+   ec_dec dec;
+   ec_byte_buffer buf;
+   
+   ec_byte_readinit(&buf,data,len);
+   ec_dec_init(&dec,&buf);
+   
+   /* Get band energies */
+   
+   /* Get the pitch index */
+   
+   /* Pitch MDCT */
    compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index, P, N, B);
 
    //haar1(P, B*N);
@@ -373,12 +393,14 @@
       normalise_bands(st->mode, P, bandEp);
    }
 
-   /* Apply pitch gains */
+   /* Get the pitch gains */
    
-   /* Decode fixed codebook */
-   
-   /* Merge pitch and fixed codebook */
-   
+   /* Apply pitch gains */
+   pitch_quant_bands(st->mode, X, P, gains);
+
+   /* Decode fixed codebook and merge with pitch */
+   unquant_bands(st->mode, X, P, &dec);
+
    /* Synthesis */
    denormalise_bands(st->mode, X, bandE);
 
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -184,6 +184,8 @@
    }
    int comb[K];
    int signs[K];
+   //for (i=0;i<N;i++)
+   //   printf ("%d ", iy[0][i]);
    pulse2comb(N, K, comb, signs, iy[0]); 
    ec_enc_uint(enc,icwrs(N, K, comb, signs),ncwrs(N, K));
 }
@@ -267,7 +269,8 @@
    id = ec_dec_uint(dec, ncwrs(N, K));
    cwrsi(N, K, id, comb, signs);
    comb2pulse(N, K, iy, comb, signs);
-   
+   //for (i=0;i<N;i++)
+   //   printf ("%d ", iy[i]);
    for (i=0;i<N;i++)
       Rpp += p[i]*p[i];
 
@@ -275,7 +278,7 @@
       Ryp += iy[i]*p[i];
 
    for (i=0;i<N;i++)
-      y[i] = iy[i] - Ryp*p[i];
+      y[i] = iy[i] - alpha*Ryp*p[i];
    
    /* Recompute after the projection (I think it's right) */
    Ryp = 0;