diff --git a/libcelt/arch.h b/libcelt/arch.h index a12a0d0b..610f6e21 100644 --- a/libcelt/arch.h +++ b/libcelt/arch.h @@ -66,6 +66,7 @@ #endif +typedef unsigned long long celt_uint64_t; typedef int spx_int32_t; typedef short spx_int16_t; diff --git a/libcelt/cwrs.c b/libcelt/cwrs.c index 19e9731f..91a408b0 100644 --- a/libcelt/cwrs.c +++ b/libcelt/cwrs.c @@ -95,6 +95,30 @@ unsigned ncwrs(int _n,int _m){ } #endif +celt_uint64_t ncwrs64(int _n,int _m){ + celt_uint64_t ret; + celt_uint64_t f; + celt_uint64_t d; + int i; + if(_n<0||_m<0)return 0; + if(_m==0)return 1; + if(_n==0)return 0; + ret=0; + f=_n; + d=1; + for(i=1;i<=_m;i++){ + ret+=f*d<0){ + t=p>>1; + if(t<=_i||_s[k-1])_i+=t; + } + pn=ncwrs64(_n-j-1,_m-k-1); + while(p<=_i){ + pp=p; + j++; + p+=pn; + pn=ncwrs64(_n-j-1,_m-k-1); + p+=pn; + } + t=p-pp>>1; + _s[k]=_i-pp>=t; + _x[k]=j; + _i-=pp; + if(_s[k])_i-=t; + } +} + +/*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. + _s: The associated sign bits.*/ +celt_uint64_t icwrs64(int _n,int _m,const int *_x,const int *_s){ + celt_uint64_t pn; + celt_uint64_t i; + int j; + int k; + i=0; + pn=ncwrs64(_n-1,_m); + for(k=j=0;k<_m;k++){ + celt_uint64_t pp; + celt_uint64_t p; + pp=0; + p=ncwrs64(_n-j,_m-k)-pn; + if(k>0)p>>=1; + pn=ncwrs64(_n-j-1,_m-k-1); + while(j<_x[k]){ + pp=p; + j++; + p+=pn; + pn=ncwrs64(_n-j-1,_m-k-1); + p+=pn; + } + i+=pp; + if((k==0||_x[k]!=_x[k-1])&&_s[k])i+=p-pp>>1; + } + 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. @@ -244,3 +336,50 @@ int main(int _argc,char **_argv){ return 0; } */ + +/* +#include +#define NMAX (32) +#define MMAX (16) + +int main(int _argc,char **_argv){ + int n; + for(n=0;n<=NMAX;n+=3){ + int m; + for(m=0;m<=MMAX;m++){ + celt_uint64_t nc; + celt_uint64_t i; + nc=ncwrs64(n,m); + printf("%d/%d: %llu",n,m, nc); + for(i=0;i0&&x[k]==x[k-1]?' ':s[k]?'-':'+',x[k]); + } + //printf(" ->"); + if(icwrs64(n,m,x,s)!=i){ + fprintf(stderr,"Combination-index mismatch.\n"); + } + comb2pulse(n,m,y,x,s); + //for(j=0;j