ref: b781877e80052b317e8856044d87c8e6d8deec41
parent: 453ccd829a742feb84a5d3666d22a0a6c04666b8
author: Jean-Marc Valin <[email protected]>
date: Fri Sep 12 17:27:35 EDT 2008
Converted everything to 32-bit CWRS (using split after that)
--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -49,7 +49,6 @@
#include "mathops.h"
#include "arch.h"
-#if 0
int log2_frac(ec_uint32 val, int frac)
{
int i;
@@ -73,32 +72,7 @@
}
return L;
}
-#endif
-int log2_frac64(ec_uint64 val, int frac)
-{
- int i;
- /* EC_ILOG64() actually returns log2()+1, go figure */
- int L = EC_ILOG64(val)-1;
- /*printf ("in: %d %d ", val, L);*/
- if (L>14)
- val >>= L-14;
- else if (L<14)
- val <<= 14-L;
- L <<= frac;
- /*printf ("%d\n", val);*/
- for (i=0;i<frac;i++)
- {
- val = (val*val) >> 15;
- /*printf ("%d\n", val);*/
- if (val > 16384)
- L |= (1<<(frac-i-1));
- else
- val <<= 1;
- }
- return L;
-}
-
int fits_in32(int _n, int _m)
{
static const celt_int16_t maxN[15] = {
@@ -117,28 +91,6 @@
return _m <= maxM[_n];
}
}
-int fits_in64(int _n, int _m)
-{
- static const celt_int16_t maxN[28] = {
- 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 178, 129, 100, 81, 68, 58,
- 51, 46, 42, 38, 36, 33, 31, 30,
- 28, 27, 26, 25};
- static const celt_int16_t maxM[28] = {
- 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 245, 166, 122, 94, 77, 64,
- 56, 49, 44, 40, 37, 34, 32, 30,
- 29, 27, 26, 25};
- if (_n>=27)
- {
- if (_m>=27)
- return 0;
- else
- return _n <= maxN[_m];
- } else {
- return _m <= maxM[_n];
- }
-}
/*Computes the next row/column of any recurrence that obeys the relation
u[i][j]=u[i-1][j]+u[i][j-1]+u[i-1][j-1].
@@ -155,18 +107,6 @@
_ui[j-1]=_ui0;
}
-static inline void unext64(celt_uint64_t *_ui,int _len,celt_uint64_t _ui0){
- celt_uint64_t ui1;
- int j;
- /* doing a do-while would overrun the array if we had less than 2 samples */
- j=1; do {
- ui1=_ui[j]+_ui[j-1]+_ui0;
- _ui[j-1]=_ui0;
- _ui0=ui1;
- } while (++j<_len);
- _ui[j-1]=_ui0;
-}
-
/*Computes the previous row/column of any recurrence that obeys the relation
u[i-1][j]=u[i][j]-u[i][j-1]-u[i-1][j-1].
_ui0 is the base case for the new row/column.*/
@@ -182,18 +122,6 @@
_ui[j-1]=_ui0;
}
-static inline void uprev64(celt_uint64_t *_ui,int _n,celt_uint64_t _ui0){
- celt_uint64_t ui1;
- int j;
- /* doing a do-while would overrun the array if we had less than 2 samples */
- j=1; do {
- ui1=_ui[j]-_ui[j-1]-_ui0;
- _ui[j-1]=_ui0;
- _ui0=ui1;
- } while (++j<_n);
- _ui[j-1]=_ui0;
-}
-
/*Returns the number of ways of choosing _m elements from a set of size _n with
replacement when a sign bit is needed for each unique element.
On input, _u should be initialized to column (_m-1) of U(n,m).
@@ -215,23 +143,6 @@
return ret;
}
-celt_uint64_t ncwrs_unext64(int _n,celt_uint64_t *_ui){
- celt_uint64_t ret;
- celt_uint64_t ui0;
- celt_uint64_t ui1;
- int j;
- ret=ui0=2;
- celt_assert(_n>=2);
- j=1; do {
- ui1=_ui[j]+_ui[j-1]+ui0;
- _ui[j-1]=ui0;
- ui0=ui1;
- ret+=ui0;
- } while (++j<_n);
- _ui[j-1]=ui0;
- return ret;
-}
-
/*Returns the number of ways of choosing _m elements from a set of size _n with
replacement when a sign bit is needed for each unique element.
On exit, _u will be initialized to column _m of U(n,m).*/
@@ -244,15 +155,6 @@
return ncwrs_unext32(_n,_u);
}
-celt_uint64_t ncwrs_u64(int _n,int _m,celt_uint64_t *_u){
- int k;
- CELT_MEMSET(_u,0,_n);
- if(_m<=0)return 1;
- if(_n<=0)return 0;
- for(k=1;k<_m;k++)unext64(_u,_n,2);
- return ncwrs_unext64(_n,_u);
-}
-
/*Returns the _i'th combination of _m elements chosen from a set of size _n
with associated sign bits.
_x: Returns the combination with elements sorted in ascending order.
@@ -283,30 +185,6 @@
}
}
-void cwrsi64(int _n,int _m,celt_uint64_t _i,int *_x,int *_s,celt_uint64_t *_u){
- int j;
- int k;
- for(k=j=0;k<_m;k++){
- celt_uint64_t p;
- celt_uint64_t t;
- p=_u[_n-j-1];
- if(k>0){
- t=p>>1;
- if(t<=_i||_s[k-1])_i+=t;
- }
- while(p<=_i){
- _i-=p;
- j++;
- p=_u[_n-j-1];
- }
- t=p>>1;
- _s[k]=_i>=t;
- _x[k]=j;
- if(_s[k])_i-=t;
- uprev64(_u,_n-j,2);
- }
-}
-
/*Returns the index of the given combination of _m elements chosen from a set
of size _n with associated sign bits.
_x: The combination with elements sorted in ascending order.
@@ -334,27 +212,6 @@
return i;
}
-celt_uint64_t icwrs64(int _n,int _m,const int *_x,const int *_s,
- celt_uint64_t *_u){
- celt_uint64_t i;
- int j;
- int k;
- i=0;
- for(k=j=0;k<_m;k++){
- celt_uint64_t p;
- p=_u[_n-j-1];
- if(k>0)p>>=1;
- while(j<_x[k]){
- i+=p;
- j++;
- p=_u[_n-j-1];
- }
- if((k==0||_x[k]!=_x[k-1])&&_s[k])i+=p>>1;
- uprev64(_u,_n-j,2);
- }
- return i;
-}
-
/*Converts a combination _x of _m unit pulses with associated sign bits _s into
a pulse vector _y of length _n.
_y: Returns the vector of pulses.
@@ -405,31 +262,18 @@
RESTORE_STACK;
}
-static inline void encode_comb64(int _n,int _m,const int *_x,const int *_s,
- ec_enc *_enc){
- VARDECL(celt_uint64_t,u);
- celt_uint64_t nc;
- celt_uint64_t i;
- SAVE_STACK;
- ALLOC(u,_n,celt_uint64_t);
- nc=ncwrs_u64(_n,_m,u);
- i=icwrs64(_n,_m,_x,_s,u);
- ec_enc_uint64(_enc,i,nc);
- RESTORE_STACK;
-}
-
int get_required_bits(int N, int K, int frac)
{
int nbits = 0;
- if(fits_in64(N,K))
+ if(fits_in32(N,K))
{
- VARDECL(celt_uint64_t,u);
+ VARDECL(celt_uint32_t,u);
SAVE_STACK;
- ALLOC(u,N,celt_uint64_t);
- nbits = log2_frac64(ncwrs_u64(N,K,u), frac);
+ ALLOC(u,N,celt_uint32_t);
+ nbits = log2_frac(ncwrs_u32(N,K,u), frac);
RESTORE_STACK;
} else {
- nbits = log2_frac64(N, frac);
+ nbits = log2_frac(N, frac);
nbits += get_required_bits(N/2+1, (K+1)/2, frac);
nbits += get_required_bits(N/2+1, K/2, frac);
}
@@ -454,8 +298,6 @@
} else if(fits_in32(N,K))
{
encode_comb32(N, K, comb, signs, enc);
- } else if(fits_in64(N,K)) {
- encode_comb64(N, K, comb, signs, enc);
} else {
int i;
int count=0;
@@ -478,14 +320,6 @@
RESTORE_STACK;
}
-static inline void decode_comb64(int _n,int _m,int *_x,int *_s,ec_dec *_dec){
- VARDECL(celt_uint64_t,u);
- SAVE_STACK;
- ALLOC(u,_n,celt_uint64_t);
- cwrsi64(_n,_m,ec_dec_uint64(_dec,ncwrs_u64(_n,_m,u)),_x,_s,u);
- RESTORE_STACK;
-}
-
void decode_pulses(int *_y, int N, int K, ec_dec *dec)
{
VARDECL(int, comb);
@@ -508,9 +342,6 @@
} else if(fits_in32(N,K))
{
decode_comb32(N, K, comb, signs, dec);
- comb2pulse(N, K, _y, comb, signs);
- } else if(fits_in64(N,K)) {
- decode_comb64(N, K, comb, signs, dec);
comb2pulse(N, K, _y, comb, signs);
} else {
int split;
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,14 +1,13 @@
INCLUDES = -I$(top_srcdir)/libcelt
METASOURCES = AUTO
-TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test mathops-test
+TESTS = type-test ectest cwrs32-test real-fft-test dft-test laplace-test mdct-test mathops-test
-noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test mathops-test
+noinst_PROGRAMS = type-test ectest cwrs32-test real-fft-test dft-test laplace-test mdct-test mathops-test
type_test_SOURCES = type-test.c
ectest_SOURCES = ectest.c
cwrs32_test_SOURCES = cwrs32-test.c
-cwrs64_test_SOURCES = cwrs64-test.c
real_fft_test_SOURCES = real-fft-test.c
dft_test_SOURCES = dft-test.c
laplace_test_SOURCES = laplace-test.c