shithub: opus

Download patch

ref: 5fa59954a9c9f13ecaa3afeb2bb1102619a9f38e
parent: 31348844081c53b1bab49f751187a2baf7c37333
author: Jean-Marc Valin <[email protected]>
date: Thu Feb 14 08:50:44 EST 2008

moved pulse [en|de]coding to cwrs.c

--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -30,7 +30,7 @@
 #include <stdlib.h>
 #include "cwrs.h"
 
-static celt_uint64_t update_ncwrs64(celt_uint64_t *nc, int len, int nc0)
+static celt_uint64_t next_ncwrs64(celt_uint64_t *nc, int len, int nc0)
 {
    int i;
    celt_uint64_t mem;
@@ -45,7 +45,7 @@
    }
 }
 
-static celt_uint64_t reverse_ncwrs64(celt_uint64_t *nc, int len, int nc0)
+static celt_uint64_t prev_ncwrs64(celt_uint64_t *nc, int len, int nc0)
 {
    int i;
    celt_uint64_t mem;
@@ -209,7 +209,7 @@
   for (j=0;j<_n+1;j++)
     nc[j] = 1;
   for (k=0;k<_m-1;k++)
-    update_ncwrs64(nc, _n+1, 0);
+    next_ncwrs64(nc, _n+1, 0);
   for(k=j=0;k<_m;k++){
     celt_uint64_t pn;
     celt_uint64_t p;
@@ -236,9 +236,9 @@
     _x[k]=j;
     if(_s[k])_i-=t;
     if (k<_m-2)
-      reverse_ncwrs64(nc, _n+1, 0);
+      prev_ncwrs64(nc, _n+1, 0);
     else
-      reverse_ncwrs64(nc, _n+1, 1);
+      prev_ncwrs64(nc, _n+1, 1);
   }
 }
 
@@ -254,7 +254,7 @@
   for (j=0;j<_n+1;j++)
     nc[j] = 1;
   for (k=0;k<_m-1;k++)
-    update_ncwrs64(nc, _n+1, 0);
+    next_ncwrs64(nc, _n+1, 0);
   i=0;
   for(k=j=0;k<_m;k++){
     celt_uint64_t pn;
@@ -275,9 +275,9 @@
     }
     if((k==0||_x[k]!=_x[k-1])&&_s[k])i+=p>>1;
     if (k<_m-2)
-      reverse_ncwrs64(nc, _n+1, 0);
+      prev_ncwrs64(nc, _n+1, 0);
     else
-      reverse_ncwrs64(nc, _n+1, 1);
+      prev_ncwrs64(nc, _n+1, 1);
   }
   return i;
 }
@@ -319,5 +319,21 @@
       }
     }
   }
+}
+
+void encode_pulses(int *_y, int N, int K, ec_enc *enc)
+{
+   int comb[K];
+   int signs[K];
+   pulse2comb(N, K, comb, signs, _y);
+   ec_enc_uint64(enc,icwrs64(N, K, comb, signs),ncwrs64(N, K));
+}
+
+void decode_pulses(int *_y, int N, int K, ec_dec *dec)
+{
+   int comb[K];
+   int signs[K];   
+   cwrsi64(N, K, ec_dec_uint64(dec, ncwrs64(N, K)), comb, signs);
+   comb2pulse(N, K, _y, comb, signs);
 }
 
--- a/libcelt/cwrs.h
+++ b/libcelt/cwrs.h
@@ -33,6 +33,8 @@
 #define CWRS_H
 
 #include "arch.h"
+#include "entenc.h"
+#include "entdec.h"
 
 celt_uint32_t ncwrs(int _n,int _m);
 
@@ -50,5 +52,9 @@
 void cwrsi64(int _n,int _m,celt_uint64_t _i,int *_x,int *_s);
 
 celt_uint64_t icwrs64(int _n,int _m,const int *_x,const int *_s);
+
+void encode_pulses(int *_y, int N, int K, ec_enc *enc);
+
+void decode_pulses(int *_y, int N, int K, ec_dec *dec);
 
 #endif /* CWRS_H */
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -226,12 +226,9 @@
       for (i=0;i<N;i++)
          x[i] *= E;
    }
-   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_uint64(enc,icwrs64(N, K, comb, signs),ncwrs64(N, K));
+   
+   encode_pulses(iy[0], N, K, enc);
+   
    //printf ("%llu ", icwrs64(N, K, comb, signs));
    /* Recompute the gain in one pass to reduce the encoder-decoder mismatch
       due to the recursive computation used in quantisation.
@@ -269,18 +266,13 @@
 void alg_unquant(float *x, int N, int K, float *p, float alpha, ec_dec *dec)
 {
    int i;
-   celt_uint64_t id;
-   int comb[K];
-   int signs[K];
    int iy[N];
    float y[N];
    float Rpp=0, Ryp=0, Ryy=0;
    float g;
 
-   id = ec_dec_uint64(dec, ncwrs64(N, K));
-   //printf ("%llu ", id);
-   cwrsi64(N, K, id, comb, signs);
-   comb2pulse(N, K, iy, comb, signs);
+   decode_pulses(iy, N, K, dec);
+
    //for (i=0;i<N;i++)
    //   printf ("%d ", iy[i]);
    for (i=0;i<N;i++)