af_afir.c 3.2 KB

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