1 /* Copyright (c) 2008-2011 Xiph.Org Foundation, Mozilla Corporation, 2 Gregory Maxwell 3 Written by Jean-Marc Valin, Gregory Maxwell, and Timothy B. Terriberry */ 4 /* 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 9 - Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 - Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifdef HAVE_CONFIG_H 30 #include "config.h" 31 #endif 32 33 #include <stdio.h> 34 #include <string.h> 35 36 #ifndef CUSTOM_MODES 37 #define CUSTOM_MODES 38 #else 39 #define TEST_CUSTOM_MODES 40 #endif 41 42 #define CELT_C 43 #include "stack_alloc.h" 44 #include "entenc.c" 45 #include "entdec.c" 46 #include "entcode.c" 47 #include "cwrs.c" 48 #include "mathops.c" 49 #include "rate.h" 50 51 #define NMAX (240) 52 #define KMAX (128) 53 54 #ifdef TEST_CUSTOM_MODES 55 56 #define NDIMS (46) 57 static const int pn[NDIMS]={ 58 2, 3, 4, 5, 6, 7, 8, 9, 10, 59 11, 12, 13, 14, 15, 16, 18, 20, 22, 60 24, 26, 28, 30, 32, 36, 40, 44, 48, 61 52, 56, 60, 64, 72, 80, 88, 96, 104, 62 112, 120, 128, 144, 160, 176, 192, 208, 224, 63 240 64 }; 65 static const int pkmax[NDIMS]={ 66 128, 128, 128, 128, 88, 52, 36, 26, 22, 67 18, 16, 15, 13, 12, 12, 11, 10, 9, 68 9, 8, 8, 7, 7, 7, 7, 6, 6, 69 6, 6, 6, 5, 5, 5, 5, 5, 5, 70 4, 4, 4, 4, 4, 4, 4, 4, 4, 71 4 72 }; 73 74 #else /* TEST_CUSTOM_MODES */ 75 76 #define NDIMS (22) 77 static const int pn[NDIMS]={ 78 2, 3, 4, 6, 8, 9, 11, 12, 16, 79 18, 22, 24, 32, 36, 44, 48, 64, 72, 80 88, 96, 144, 176 81 }; 82 static const int pkmax[NDIMS]={ 83 128, 128, 128, 88, 36, 26, 18, 16, 12, 84 11, 9, 9, 7, 7, 6, 6, 5, 5, 85 5, 5, 4, 4 86 }; 87 88 #endif 89 90 int main(void){ 91 int t; 92 int n; 93 ALLOC_STACK; 94 for(t=0;t<NDIMS;t++){ 95 int pseudo; 96 n=pn[t]; 97 for(pseudo=1;pseudo<41;pseudo++) 98 { 99 int k; 100 opus_uint32 uu[KMAX+2U]; 101 opus_uint32 inc; 102 opus_uint32 nc; 103 opus_uint32 i; 104 k=get_pulses(pseudo); 105 if (k>pkmax[t])break; 106 printf("Testing CWRS with N=%i, K=%i...\n",n,k); 107 nc=ncwrs_urow(n,k,uu); 108 inc=nc/20000; 109 if(inc<1)inc=1; 110 for(i=0;i<nc;i+=inc){ 111 opus_uint32 u[KMAX+2U]; 112 int y[NMAX]; 113 int sy; 114 int yy[5]; 115 opus_uint32 v; 116 opus_uint32 ii; 117 int kk; 118 int j; 119 memcpy(u,uu,(k+2U)*sizeof(*u)); 120 cwrsi(n,k,i,y,u); 121 sy=0; 122 for(j=0;j<n;j++)sy+=ABS(y[j]); 123 if(sy!=k){ 124 fprintf(stderr,"N=%d Pulse count mismatch in cwrsi (%d!=%d).\n", 125 n,sy,k); 126 return 99; 127 } 128 /*printf("%6u of %u:",i,nc); 129 for(j=0;j<n;j++)printf(" %+3i",y[j]); 130 printf(" ->");*/ 131 ii=icwrs(n,k,&v,y,u); 132 if(ii!=i){ 133 fprintf(stderr,"Combination-index mismatch (%lu!=%lu).\n", 134 (long)ii,(long)i); 135 return 1; 136 } 137 if(v!=nc){ 138 fprintf(stderr,"Combination count mismatch (%lu!=%lu).\n", 139 (long)v,(long)nc); 140 return 2; 141 } 142 #ifndef SMALL_FOOTPRINT 143 if(n==2){ 144 cwrsi2(k,i,yy); 145 for(j=0;j<2;j++)if(yy[j]!=y[j]){ 146 fprintf(stderr,"N=2 pulse vector mismatch ({%i,%i}!={%i,%i}).\n", 147 yy[0],yy[1],y[0],y[1]); 148 return 3; 149 } 150 ii=icwrs2(yy,&kk); 151 if(ii!=i){ 152 fprintf(stderr,"N=2 combination-index mismatch (%lu!=%lu).\n", 153 (long)ii,(long)i); 154 return 4; 155 } 156 if(kk!=k){ 157 fprintf(stderr,"N=2 pulse count mismatch (%i,%i).\n",kk,k); 158 return 5; 159 } 160 v=ncwrs2(k); 161 if(v!=nc){ 162 fprintf(stderr,"N=2 combination count mismatch (%lu,%lu).\n", 163 (long)v,(long)nc); 164 return 6; 165 } 166 } 167 else if(n==3){ 168 cwrsi3(k,i,yy); 169 for(j=0;j<3;j++)if(yy[j]!=y[j]){ 170 fprintf(stderr,"N=3 pulse vector mismatch " 171 "({%i,%i,%i}!={%i,%i,%i}).\n",yy[0],yy[1],yy[2],y[0],y[1],y[2]); 172 return 7; 173 } 174 ii=icwrs3(yy,&kk); 175 if(ii!=i){ 176 fprintf(stderr,"N=3 combination-index mismatch (%lu!=%lu).\n", 177 (long)ii,(long)i); 178 return 8; 179 } 180 if(kk!=k){ 181 fprintf(stderr,"N=3 pulse count mismatch (%i!=%i).\n",kk,k); 182 return 9; 183 } 184 v=ncwrs3(k); 185 if(v!=nc){ 186 fprintf(stderr,"N=3 combination count mismatch (%lu!=%lu).\n", 187 (long)v,(long)nc); 188 return 10; 189 } 190 } 191 else if(n==4){ 192 cwrsi4(k,i,yy); 193 for(j=0;j<4;j++)if(yy[j]!=y[j]){ 194 fprintf(stderr,"N=4 pulse vector mismatch " 195 "({%i,%i,%i,%i}!={%i,%i,%i,%i}.\n", 196 yy[0],yy[1],yy[2],yy[3],y[0],y[1],y[2],y[3]); 197 return 11; 198 } 199 ii=icwrs4(yy,&kk); 200 if(ii!=i){ 201 fprintf(stderr,"N=4 combination-index mismatch (%lu!=%lu).\n", 202 (long)ii,(long)i); 203 return 12; 204 } 205 if(kk!=k){ 206 fprintf(stderr,"N=4 pulse count mismatch (%i!=%i).\n",kk,k); 207 return 13; 208 } 209 v=ncwrs4(k); 210 if(v!=nc){ 211 fprintf(stderr,"N=4 combination count mismatch (%lu!=%lu).\n", 212 (long)v,(long)nc); 213 return 14; 214 } 215 } 216 #endif /* SMALL_FOOTPRINT */ 217 /*printf(" %6u\n",i);*/ 218 } 219 /*printf("\n");*/ 220 } 221 } 222 return 0; 223 } 224