shithub: opus

Download patch

ref: 9cace64e5f94ac8c31c3638f752c5dd976adf87f
parent: e8376605d5e9157a026fd3c3d8e7b380d4046dda
author: Jean-Marc Valin <[email protected]>
date: Thu Dec 6 12:44:09 EST 2007

Fixed codebook entirely quantised

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -160,17 +160,16 @@
       q = m->nbPulses[i];
       if (q>0) {
          float n = sqrt(B*(eBands[i+1]-eBands[i]));
-         id = alg_quant2(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i]);
-         ec_enc_uint(enc,id,ncwrs(B*(eBands[i+1]-eBands[i]), q));
+         alg_quant2(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], enc);
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
             norm[j] = X[j] * n;
          //bits += log2(ncwrs(B*(eBands[i+1]-eBands[i]), q));
       } else {
          float n = sqrt(B*(eBands[i+1]-eBands[i]));
-         copy_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i]);
+         copy_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i], enc);
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
             norm[j] = X[j] * n;
-         //bits += 1+log2(eBands[i])+log2(ncwrs(B*(eBands[i+1]-eBands[i]), -q));
+         //bits += 1+log2(eBands[i]-(eBands[i+1]-eBands[i]))+log2(ncwrs(B*(eBands[i+1]-eBands[i]), -q));
       }
    }
    //printf ("%f\n", bits);
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -32,6 +32,7 @@
 #include <math.h>
 #include <stdlib.h>
 #include "cwrs.h"
+#include "vq.h"
 
 /* Algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch 
    a combination of pulses such that its norm is still equal to 1 */
@@ -95,7 +96,7 @@
 /* Improved algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch 
    a combination of pulses such that its norm is still equal to 1. The only difference with 
    the quantiser above is that the search is more complete. */
-int alg_quant2(float *x, int N, int K, float *p)
+void alg_quant2(float *x, int N, int K, float *p, ec_enc *enc)
 {
    int L = 5;
    //float tata[200];
@@ -240,7 +241,7 @@
    int comb[K];
    int signs[K];
    pulse2comb(N, K, comb, signs, iy[0]); 
-   return icwrs(N, K, comb, signs);
+   ec_enc_uint(enc,icwrs(N, K, comb, signs),ncwrs(N, K));
 }
 
 /* Just replace the band with noise of unit energy */
@@ -263,7 +264,7 @@
 static const float pg[5] = {1.f, .82f, .75f, 0.7f, 0.6f};
 
 /* Finds the right offset into Y and copy it */
-void copy_quant(float *x, int N, int K, float *Y, int B, int N0)
+void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc)
 {
    int i,j;
    int best=0;
@@ -291,6 +292,7 @@
             s = -1;
       }
    }
+   ec_enc_uint(enc,best/B,N0-N/B);
    //printf ("%d %f\n", best, best_score);
    if (K==0)
    {
@@ -319,6 +321,6 @@
       E = .8/sqrt(E);
       for (j=0;j<N;j++)
          P[j] *= E;
-      alg_quant2(x, N, K, P);
+      alg_quant2(x, N, K, P, enc);
    }
 }
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -32,6 +32,8 @@
 #ifndef VQ_H
 #define VQ_H
 
+#include "entenc.h"
+
 /* Algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch 
    a combination of pulses such that its norm is still equal to 1 */
 void alg_quant(float *x, int N, int K, float *p);
@@ -39,12 +41,12 @@
 /* Improved algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch 
    a combination of pulses such that its norm is still equal to 1. The only difference with 
    the quantiser above is that the search is more complete. */
-int alg_quant2(float *x, int N, int K, float *p);
+void alg_quant2(float *x, int N, int K, float *p, ec_enc *enc);
 
 /* Just replace the band with noise of unit energy */
 void noise_quant(float *x, int N, int K, float *p);
 
 /* Finds the right offset into Y and copy it */
-void copy_quant(float *x, int N, int K, float *Y, int B, int N0);
+void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc);
 
 #endif /* VQ_H */