vorbisdsp.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <float.h>
  19. #include "libavutil/mem_internal.h"
  20. #include "libavcodec/vorbisdsp.h"
  21. #include "checkasm.h"
  22. #define LEN 512
  23. #define randomize_buffer(buf) \
  24. do { \
  25. double bmg[2], stddev = 10.0, mean = 0.0; \
  26. \
  27. for (int i = 0; i < LEN; i += 2) { \
  28. av_bmg_get(&checkasm_lfg, bmg); \
  29. buf[i] = bmg[0] * stddev + mean; \
  30. buf[i + 1] = bmg[1] * stddev + mean; \
  31. } \
  32. } while(0);
  33. static void test_inverse_coupling(void)
  34. {
  35. LOCAL_ALIGNED_16(float, src0, [LEN]);
  36. LOCAL_ALIGNED_16(float, src1, [LEN]);
  37. LOCAL_ALIGNED_16(float, cdst, [LEN]);
  38. LOCAL_ALIGNED_16(float, odst, [LEN]);
  39. LOCAL_ALIGNED_16(float, cdst1, [LEN]);
  40. LOCAL_ALIGNED_16(float, odst1, [LEN]);
  41. declare_func(void, float *restrict mag, float *restrict ang,
  42. ptrdiff_t blocksize);
  43. randomize_buffer(src0);
  44. randomize_buffer(src1);
  45. memcpy(cdst, src0, LEN * sizeof(*src0));
  46. memcpy(cdst1, src1, LEN * sizeof(*src1));
  47. memcpy(odst, src0, LEN * sizeof(*src0));
  48. memcpy(odst1, src1, LEN * sizeof(*src1));
  49. call_ref(cdst, cdst1, LEN);
  50. call_new(odst, odst1, LEN);
  51. for (int i = 0; i < LEN; i++) {
  52. if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON) ||
  53. !float_near_abs_eps(cdst1[i], odst1[i], FLT_EPSILON)) {
  54. fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
  55. i, cdst[i], odst[i], cdst[i] - odst[i]);
  56. fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
  57. i, cdst1[i], odst1[i], cdst1[i] - odst1[i]);
  58. fail();
  59. break;
  60. }
  61. }
  62. bench_new(src0, src1, LEN);
  63. }
  64. void checkasm_check_vorbisdsp(void)
  65. {
  66. VorbisDSPContext dsp;
  67. ff_vorbisdsp_init(&dsp);
  68. if (check_func(dsp.vorbis_inverse_coupling, "inverse_coupling"))
  69. test_inverse_coupling();
  70. report("inverse_coupling");
  71. }