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