Switch iteration over channels to the do{}while(); construct in order to inform the...
[opus.git] / tests / cwrs32-test.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #define CELT_C 
9 #include "../libcelt/stack_alloc.h"
10 #include "../libcelt/rangeenc.c"
11 #include "../libcelt/rangedec.c"
12 #include "../libcelt/entenc.c"
13 #include "../libcelt/entdec.c"
14 #include "../libcelt/entcode.c"
15 #include "../libcelt/cwrs.c"
16 #include "../libcelt/mathops.c"
17
18 #define NMAX (14)
19 #define KMAX (32767)
20
21 static const int kmax[15]={
22   32767,32767,32767,32767, 1172,
23     238,   95,   53,   36,   27,
24      22,   18,   16,   15,   13
25 };
26
27
28 int main(int _argc,char **_argv){
29   int n;
30   ALLOC_STACK;
31   for(n=2;n<=NMAX;n++){
32     int dk;
33     int k;
34     dk=kmax[n]>7?kmax[n]/7:1;
35     k=1-dk;
36     do{
37       celt_uint32 uu[KMAX+2U];
38       celt_uint32 inc;
39       celt_uint32 nc;
40       celt_uint32 i;
41       k=kmax[n]-dk<k?kmax[n]:k+dk;
42       printf("Testing CWRS with N=%i, K=%i...\n",n,k);
43       nc=ncwrs_urow(n,k,uu);
44       inc=nc/10000;
45       if(inc<1)inc=1;
46       for(i=0;i<nc;i+=inc){
47         celt_uint32 u[KMAX+2U];
48         int           y[NMAX];
49         int           yy[5];
50         celt_uint32 v;
51         celt_uint32 ii;
52         int           kk;
53         int           j;
54         memcpy(u,uu,(k+2U)*sizeof(*u));
55         cwrsi(n,k,i,y,u);
56         /*printf("%6u of %u:",i,nc);
57         for(j=0;j<n;j++)printf(" %+3i",y[j]);
58         printf(" ->");*/
59         ii=icwrs(n,k,&v,y,u);
60         if(ii!=i){
61           fprintf(stderr,"Combination-index mismatch (%lu!=%lu).\n",
62            (long)ii,(long)i);
63           return 1;
64         }
65         if(v!=nc){
66           fprintf(stderr,"Combination count mismatch (%lu!=%lu).\n",
67            (long)v,(long)nc);
68           return 2;
69         }
70 #ifndef SMALL_FOOTPRINT
71         if(n==2){
72           cwrsi2(k,i,yy);
73           for(j=0;j<2;j++)if(yy[j]!=y[j]){
74             fprintf(stderr,"N=2 pulse vector mismatch ({%i,%i}!={%i,%i}).\n",
75              yy[0],yy[1],y[0],y[1]);
76             return 3;
77           }
78           ii=icwrs2(yy,&kk);
79           if(ii!=i){
80             fprintf(stderr,"N=2 combination-index mismatch (%lu!=%lu).\n",
81              (long)ii,(long)i);
82             return 4;
83           }
84           if(kk!=k){
85             fprintf(stderr,"N=2 pulse count mismatch (%i,%i).\n",kk,k);
86             return 5;
87           }
88           v=ncwrs2(k);
89           if(v!=nc){
90             fprintf(stderr,"N=2 combination count mismatch (%lu,%lu).\n",
91              (long)v,(long)nc);
92             return 6;
93           }
94         }
95         else if(n==3){
96           cwrsi3(k,i,yy);
97           for(j=0;j<3;j++)if(yy[j]!=y[j]){
98             fprintf(stderr,"N=3 pulse vector mismatch "
99              "({%i,%i,%i}!={%i,%i,%i}).\n",yy[0],yy[1],yy[2],y[0],y[1],y[2]);
100             return 7;
101           }
102           ii=icwrs3(yy,&kk);
103           if(ii!=i){
104             fprintf(stderr,"N=3 combination-index mismatch (%lu!=%lu).\n",
105              (long)ii,(long)i);
106             return 8;
107           }
108           if(kk!=k){
109             fprintf(stderr,"N=3 pulse count mismatch (%i!=%i).\n",kk,k);
110             return 9;
111           }
112           v=ncwrs3(k);
113           if(v!=nc){
114             fprintf(stderr,"N=3 combination count mismatch (%lu!=%lu).\n",
115              (long)v,(long)nc);
116             return 10;
117           }
118         }
119         else if(n==4){
120           cwrsi4(k,i,yy);
121           for(j=0;j<4;j++)if(yy[j]!=y[j]){
122             fprintf(stderr,"N=4 pulse vector mismatch "
123              "({%i,%i,%i,%i}!={%i,%i,%i,%i}.\n",
124              yy[0],yy[1],yy[2],yy[3],y[0],y[1],y[2],y[3]);
125             return 11;
126           }
127           ii=icwrs4(yy,&kk);
128           if(ii!=i){
129             fprintf(stderr,"N=4 combination-index mismatch (%lu!=%lu).\n",
130              (long)ii,(long)i);
131             return 12;
132           }
133           if(kk!=k){
134             fprintf(stderr,"N=4 pulse count mismatch (%i!=%i).\n",kk,k);
135             return 13;
136           }
137           v=ncwrs4(k);
138           if(v!=nc){
139             fprintf(stderr,"N=4 combination count mismatch (%lu!=%lu).\n",
140              (long)v,(long)nc);
141             return 14;
142           }
143         }
144         else if(n==5){
145           cwrsi5(k,i,yy);
146           for(j=0;j<5;j++)if(yy[j]!=y[j]){
147             fprintf(stderr,"N=5 pulse vector mismatch "
148              "({%i,%i,%i,%i,%i}!={%i,%i,%i,%i,%i}).\n",
149              yy[0],yy[1],yy[2],yy[3],yy[4],y[0],y[1],y[2],y[3],y[4]);
150             return 15;
151           }
152           ii=icwrs5(yy,&kk);
153           if(ii!=i){
154             fprintf(stderr,"N=5 combination-index mismatch (%lu!=%lu).\n",
155              (long)ii,(long)i);
156             return 16;
157           }
158           if(kk!=k){
159             fprintf(stderr,"N=5 pulse count mismatch (%i!=%i).\n",kk,k);
160             return 17;
161           }
162           v=ncwrs5(k);
163           if(v!=nc){
164             fprintf(stderr,"N=5 combination count mismatch (%lu!=%lu).\n",
165              (long)v,(long)nc);
166             return 18;
167           }
168         }
169 #endif /* SMALL_FOOTPRINT */
170
171         /*printf(" %6u\n",i);*/
172       }
173       /*printf("\n");*/
174     }
175     while(k<kmax[n]);
176   }
177   return 0;
178 }