af_afir.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "config.h"
  19. #include <float.h>
  20. #include <stdint.h>
  21. #include "libavfilter/af_afir.h"
  22. #include "libavutil/internal.h"
  23. #include "checkasm.h"
  24. #define LEN 256
  25. #define randomize_buffer(buf) \
  26. do { \
  27. int i; \
  28. double bmg[2], stddev = 10.0, mean = 0.0; \
  29. \
  30. for (i = 0; i < LEN*2+8; i += 2) { \
  31. av_bmg_get(&checkasm_lfg, bmg); \
  32. buf[i] = bmg[0] * stddev + mean; \
  33. buf[i + 1] = bmg[1] * stddev + mean; \
  34. } \
  35. } while(0);
  36. static void test_fcmul_add(const float *src0, const float *src1, const float *src2)
  37. {
  38. LOCAL_ALIGNED_32(float, cdst, [LEN*2+8]);
  39. LOCAL_ALIGNED_32(float, odst, [LEN*2+8]);
  40. int i;
  41. declare_func(void, float *sum, const float *t, const float *c,
  42. ptrdiff_t len);
  43. memcpy(cdst, src0, (LEN*2+8) * sizeof(float));
  44. memcpy(odst, src0, (LEN*2+8) * sizeof(float));
  45. call_ref(cdst, src1, src2, LEN);
  46. call_new(odst, src1, src2, LEN);
  47. for (i = 0; i <= LEN*2; i++) {
  48. if (!float_near_abs_eps(cdst[i], odst[i], 6.2e-05)) {
  49. fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
  50. i, cdst[i], odst[i], cdst[i] - odst[i]);
  51. fail();
  52. break;
  53. }
  54. }
  55. memcpy(odst, src0, (LEN*2+8) * sizeof(float));
  56. bench_new(odst, src1, src2, LEN);
  57. }
  58. void checkasm_check_afir(void)
  59. {
  60. LOCAL_ALIGNED_32(float, src0, [LEN*2+8]);
  61. LOCAL_ALIGNED_32(float, src1, [LEN*2+8]);
  62. LOCAL_ALIGNED_32(float, src2, [LEN*2+8]);
  63. AudioFIRDSPContext fir = { 0 };
  64. ff_afir_init(&fir);
  65. randomize_buffer(src0);
  66. randomize_buffer(src1);
  67. randomize_buffer(src2);
  68. if (check_func(fir.fcmul_add, "fcmul_add"))
  69. test_fcmul_add(src0, src1, src2);
  70. report("fcmul_add");
  71. }