diff --git a/libcelt/cwrs.c b/libcelt/cwrs.c index 9680233f2c2feb300a8b93be27a3d527cef95890..c678578689d588053f1b819e38298b8ce6ad06a3 100644 --- a/libcelt/cwrs.c +++ b/libcelt/cwrs.c @@ -269,15 +269,12 @@ celt_uint64_t icwrs64(int _n,int _m,const int *_x,const int *_s, _x: The combination with elements sorted in ascending order. _x[_m] = -1 _s: The associated sign bits.*/ void comb2pulse(int _n,int _m,int * restrict _y,const int *_x,const int *_s){ - int j; int k; - int n; + const int signs[2]={1,-1}; CELT_MEMSET(_y, 0, _n); - for(k=j=0;k<_m;k+=n){ - /* _x[_m] = -1 so we won't overflow */ - for(n=1;_x[k+n]==_x[k];n++); - _y[_x[k]]=_s[k]?-n:n; - } + k=0; do { + _y[_x[k]]+=signs[_s[k]]; + } while (++k<_m); } /*Converts a pulse vector vector _y of length _n into a combination of _m unit @@ -371,7 +368,7 @@ void decode_pulses(int *_y, int N, int K, ec_dec *dec) VARDECL(int, signs); SAVE_STACK; - ALLOC(comb, K+1, int); + ALLOC(comb, K, int); ALLOC(signs, K, int); /* Simple heuristic to figure out whether it fits in 32 bits */ if((N+4)*(K+4)<250 || (celt_ilog2(N)+1)*K<31) @@ -380,7 +377,6 @@ void decode_pulses(int *_y, int N, int K, ec_dec *dec) } else { decode_comb64(N, K, comb, signs, dec); } - comb[K] = -1; comb2pulse(N, K, _y, comb, signs); RESTORE_STACK; } diff --git a/tests/cwrs32-test.c b/tests/cwrs32-test.c index 13e5ec642a660ace18af87e5809d1139105316c6..b9ea1a8e72c46d1634fcd3243118198ec76d92a1 100644 --- a/tests/cwrs32-test.c +++ b/tests/cwrs32-test.c @@ -12,7 +12,7 @@ int main(int _argc,char **_argv){ int n; for(n=2;n<=NMAX;n++){ int m; - for(m=0;m<=MMAX;m++){ + for(m=1;m<=MMAX;m++){ celt_uint32_t uu[NMAX]; celt_uint32_t inc; celt_uint32_t nc; @@ -22,7 +22,7 @@ int main(int _argc,char **_argv){ if(inc<1)inc=1; for(i=0;i<nc;i+=inc){ celt_uint32_t u[NMAX]; - int x[MMAX+1]; + int x[MMAX]; int s[MMAX]; int x2[MMAX]; int s2[MMAX]; @@ -40,7 +40,6 @@ int main(int _argc,char **_argv){ fprintf(stderr,"Combination-index mismatch.\n"); return 1; } - x[m] = -1; comb2pulse(n,m,y,x,s); /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j])); printf("\n");*/ diff --git a/tests/cwrs64-test.c b/tests/cwrs64-test.c index 862f124ac361819a4a2021ce38fa8bd1d71b2a2b..e476367c8f055fbe2c92fd3b4a6031b09c5e7cca 100644 --- a/tests/cwrs64-test.c +++ b/tests/cwrs64-test.c @@ -13,7 +13,7 @@ int main(int _argc,char **_argv){ int n; for(n=2;n<=NMAX;n+=3){ int m; - for(m=0;m<=MMAX;m++){ + for(m=1;m<=MMAX;m++){ celt_uint64_t uu[NMAX]; celt_uint64_t inc; celt_uint64_t nc; @@ -25,7 +25,7 @@ int main(int _argc,char **_argv){ /*printf("%d/%d: %llu",n,m, nc);*/ for(i=0;i<nc;i+=inc){ celt_uint64_t u[NMAX]; - int x[MMAX+1]; + int x[MMAX]; int s[MMAX]; int x2[MMAX]; int s2[MMAX]; @@ -43,7 +43,6 @@ int main(int _argc,char **_argv){ fprintf(stderr,"Combination-index mismatch.\n"); return 1; } - x[m] = -1; comb2pulse(n,m,y,x,s); /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j])); printf("\n");*/