You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
4.3KB

  1. /*
  2. * Copyright (c) 2015 Janne Grunau
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with Libav; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <math.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include "libavutil/internal.h"
  24. #include "libavutil/intfloat.h"
  25. #include "libavcodec/dca.h"
  26. #include "libavcodec/dcadsp.h"
  27. #include "libavcodec/dcadata.h"
  28. #include "checkasm.h"
  29. #define randomize_lfe_fir(size) \
  30. do { \
  31. int i; \
  32. for (i = 0; i < size; i++) { \
  33. float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f; \
  34. in[i] = f; \
  35. } \
  36. for (i = 0; i < 256; i++) { \
  37. float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f; \
  38. coeffs[i] = f; \
  39. } \
  40. } while (0)
  41. #define check_lfe_fir(decifactor, eps) \
  42. do { \
  43. LOCAL_ALIGNED_16(float, in, [256 / decifactor]); \
  44. LOCAL_ALIGNED_16(float, out0, [decifactor * 2]); \
  45. LOCAL_ALIGNED_16(float, out1, [decifactor * 2]); \
  46. LOCAL_ALIGNED_16(float, coeffs, [256]); \
  47. int i; \
  48. const float * in_ptr = in + (256 / decifactor) - 1; \
  49. declare_func(void, float *out, const float *in, const float *coeffs); \
  50. /* repeat the test several times */ \
  51. for (i = 0; i < 32; i++) { \
  52. int j; \
  53. memset(out0, 0, sizeof(*out0) * 2 * decifactor); \
  54. memset(out1, 0xFF, sizeof(*out1) * 2 * decifactor); \
  55. randomize_lfe_fir(256 / decifactor); \
  56. call_ref(out0, in_ptr, coeffs); \
  57. call_new(out1, in_ptr, coeffs); \
  58. for (j = 0; j < 2 * decifactor; j++) { \
  59. if (!float_near_abs_eps(out0[j], out1[j], eps)) { \
  60. if (0) { \
  61. union av_intfloat32 x, y; x.f = out0[j]; y.f = out1[j]; \
  62. fprintf(stderr, "%3d: %11g (0x%08x); %11g (0x%08x)\n", \
  63. j, x.f, x.i, y.f, y.i); \
  64. } \
  65. fail(); \
  66. break; \
  67. } \
  68. } \
  69. bench_new(out1, in_ptr, coeffs); \
  70. } \
  71. } while (0)
  72. void checkasm_check_dcadsp(void)
  73. {
  74. DCADSPContext c;
  75. ff_dcadsp_init(&c);
  76. /* values are limited to {-8, 8} so absolute epsilon is good enough */
  77. if (check_func(c.lfe_fir[0], "dca_lfe_fir0"))
  78. check_lfe_fir(32, 1.0e-6f);
  79. if (check_func(c.lfe_fir[1], "dca_lfe_fir1"))
  80. check_lfe_fir(64, 1.0e-6f);
  81. report("dcadsp");
  82. }