test_unit_rotation.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (c) 2008-2011 Xiph.Org Foundation
  2. Written by Jean-Marc Valin */
  3. /*
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  16. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #ifndef CUSTOM_MODES
  28. #define CUSTOM_MODES
  29. #endif
  30. #define CELT_C
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include "vq.c"
  34. #include "cwrs.c"
  35. #include "entcode.c"
  36. #include "entenc.c"
  37. #include "entdec.c"
  38. #include "mathops.c"
  39. #include "bands.h"
  40. #include "pitch.c"
  41. #include "celt_lpc.c"
  42. #include "celt.c"
  43. #include <math.h>
  44. #if defined(OPUS_X86_MAY_HAVE_SSE) || defined(OPUS_X86_MAY_HAVE_SSE2) || defined(OPUS_X86_MAY_HAVE_SSE4_1)
  45. # if defined(OPUS_X86_MAY_HAVE_SSE)
  46. # include "x86/pitch_sse.c"
  47. # endif
  48. # if defined(OPUS_X86_MAY_HAVE_SSE2)
  49. # include "x86/pitch_sse2.c"
  50. # endif
  51. # if defined(OPUS_X86_MAY_HAVE_SSE4_1)
  52. # include "x86/pitch_sse4_1.c"
  53. # include "x86/celt_lpc_sse.c"
  54. # endif
  55. # include "x86/x86_celt_map.c"
  56. #elif defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
  57. # include "arm/armcpu.c"
  58. # if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
  59. # include "arm/celt_neon_intr.c"
  60. # if defined(HAVE_ARM_NE10)
  61. # include "kiss_fft.c"
  62. # include "mdct.c"
  63. # include "arm/celt_ne10_fft.c"
  64. # include "arm/celt_ne10_mdct.c"
  65. # endif
  66. # endif
  67. # include "arm/arm_celt_map.c"
  68. #endif
  69. #define MAX_SIZE 100
  70. int ret=0;
  71. void test_rotation(int N, int K)
  72. {
  73. int i;
  74. double err = 0, ener = 0, snr, snr0;
  75. opus_val16 x0[MAX_SIZE];
  76. opus_val16 x1[MAX_SIZE];
  77. for (i=0;i<N;i++)
  78. x1[i] = x0[i] = rand()%32767-16384;
  79. exp_rotation(x1, N, 1, 1, K, SPREAD_NORMAL);
  80. for (i=0;i<N;i++)
  81. {
  82. err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
  83. ener += x0[i]*(double)x0[i];
  84. }
  85. snr0 = 20*log10(ener/err);
  86. err = ener = 0;
  87. exp_rotation(x1, N, -1, 1, K, SPREAD_NORMAL);
  88. for (i=0;i<N;i++)
  89. {
  90. err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
  91. ener += x0[i]*(double)x0[i];
  92. }
  93. snr = 20*log10(ener/err);
  94. printf ("SNR for size %d (%d pulses) is %f (was %f without inverse)\n", N, K, snr, snr0);
  95. if (snr < 60 || snr0 > 20)
  96. {
  97. fprintf(stderr, "FAIL!\n");
  98. ret = 1;
  99. }
  100. }
  101. int main(void)
  102. {
  103. ALLOC_STACK;
  104. test_rotation(15, 3);
  105. test_rotation(23, 5);
  106. test_rotation(50, 3);
  107. test_rotation(80, 1);
  108. return ret;
  109. }