test_unit_cwrs32.c 6.5 KB

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