test_unit_cwrs32.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 (44)
  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
  53. };
  54. static const int pkmax[NDIMS]={
  55. 128, 128, 128, 128, 88, 52, 36, 26, 22,
  56. 18, 16, 15, 13, 12, 12, 11, 10, 9,
  57. 9, 8, 8, 7, 7, 7, 7, 6, 6,
  58. 6, 6, 6, 5, 5, 5, 5, 5, 5,
  59. 4, 4, 4, 4, 4, 4, 4, 4
  60. };
  61. #else /* TEST_CUSTOM_MODES */
  62. #define NDIMS (22)
  63. static const int pn[NDIMS]={
  64. 2, 3, 4, 6, 8, 9, 11, 12, 16,
  65. 18, 22, 24, 32, 36, 44, 48, 64, 72,
  66. 88, 96, 144, 176
  67. };
  68. static const int pkmax[NDIMS]={
  69. 128, 128, 128, 88, 36, 26, 18, 16, 12,
  70. 11, 9, 9, 7, 7, 6, 6, 5, 5,
  71. 5, 5, 4, 4
  72. };
  73. #endif
  74. int main(void){
  75. int t;
  76. int n;
  77. ALLOC_STACK;
  78. for(t=0;t<NDIMS;t++){
  79. int pseudo;
  80. n=pn[t];
  81. for(pseudo=1;pseudo<41;pseudo++)
  82. {
  83. int k;
  84. #if defined(SMALL_FOOTPRINT)
  85. opus_uint32 uu[KMAX+2U];
  86. #endif
  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. #if defined(SMALL_FOOTPRINT)
  94. nc=ncwrs_urow(n,k,uu);
  95. #else
  96. nc=CELT_PVQ_V(n,k);
  97. #endif
  98. inc=nc/20000;
  99. if(inc<1)inc=1;
  100. for(i=0;i<nc;i+=inc){
  101. #if defined(SMALL_FOOTPRINT)
  102. opus_uint32 u[KMAX+2U];
  103. #endif
  104. int y[NMAX];
  105. int sy;
  106. opus_uint32 v;
  107. opus_uint32 ii;
  108. int j;
  109. #if defined(SMALL_FOOTPRINT)
  110. memcpy(u,uu,(k+2U)*sizeof(*u));
  111. cwrsi(n,k,i,y,u);
  112. #else
  113. cwrsi(n,k,i,y);
  114. #endif
  115. sy=0;
  116. for(j=0;j<n;j++)sy+=abs(y[j]);
  117. if(sy!=k){
  118. fprintf(stderr,"N=%d Pulse count mismatch in cwrsi (%d!=%d).\n",
  119. n,sy,k);
  120. return 99;
  121. }
  122. /*printf("%6u of %u:",i,nc);
  123. for(j=0;j<n;j++)printf(" %+3i",y[j]);
  124. printf(" ->");*/
  125. #if defined(SMALL_FOOTPRINT)
  126. ii=icwrs(n,k,&v,y,u);
  127. #else
  128. ii=icwrs(n,y);
  129. v=CELT_PVQ_V(n,k);
  130. #endif
  131. if(ii!=i){
  132. fprintf(stderr,"Combination-index mismatch (%lu!=%lu).\n",
  133. (long)ii,(long)i);
  134. return 1;
  135. }
  136. if(v!=nc){
  137. fprintf(stderr,"Combination count mismatch (%lu!=%lu).\n",
  138. (long)v,(long)nc);
  139. return 2;
  140. }
  141. /*printf(" %6u\n",i);*/
  142. }
  143. /*printf("\n");*/
  144. }
  145. }
  146. return 0;
  147. }