synth_filter.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2015 Janne Grunau
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 <stdio.h>
  23. #include <stdlib.h>
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intfloat.h"
  26. #include "libavutil/mem_internal.h"
  27. #include "libavutil/tx.h"
  28. #include "libavcodec/dcadata.h"
  29. #include "libavcodec/synth_filter.h"
  30. #include "checkasm.h"
  31. #define BUF_SIZE 32
  32. #define randomize_input() \
  33. do { \
  34. int i; \
  35. for (i = 0; i < BUF_SIZE; i++) { \
  36. float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
  37. in[i] = f; \
  38. } \
  39. } while (0)
  40. void checkasm_check_synth_filter(void)
  41. {
  42. float scale = 1.0;
  43. AVTXContext *imdct;
  44. av_tx_fn imdct_fn;
  45. SynthFilterContext synth;
  46. av_tx_init(&imdct, &imdct_fn, AV_TX_FLOAT_MDCT, 0, 16, &scale, 0);
  47. ff_synth_filter_init(&synth);
  48. if (check_func(synth.synth_filter_float, "synth_filter_float")) {
  49. LOCAL_ALIGNED(32, float, out0, [BUF_SIZE]);
  50. LOCAL_ALIGNED(32, float, out1, [BUF_SIZE]);
  51. LOCAL_ALIGNED(32, float, out_b, [BUF_SIZE]);
  52. LOCAL_ALIGNED(32, float, in, [BUF_SIZE]);
  53. LOCAL_ALIGNED(32, float, buf2_0, [BUF_SIZE]);
  54. LOCAL_ALIGNED(32, float, buf2_1, [BUF_SIZE]);
  55. LOCAL_ALIGNED(32, float, buf2_b, [BUF_SIZE]);
  56. LOCAL_ALIGNED(32, float, buf0, [512]);
  57. LOCAL_ALIGNED(32, float, buf1, [512]);
  58. LOCAL_ALIGNED(32, float, buf_b, [512]);
  59. float scale = 1.0f;
  60. int i, offset0 = 0, offset1 = 0, offset_b = 0;
  61. declare_func(void, AVTXContext *, float *, int *,
  62. float[32], const float[512], float[32], float[32], float, av_tx_fn);
  63. memset(buf2_0, 0, sizeof(*buf2_0) * BUF_SIZE);
  64. memset(buf2_1, 0, sizeof(*buf2_1) * BUF_SIZE);
  65. memset(buf2_b, 0, sizeof(*buf2_b) * BUF_SIZE);
  66. memset(buf0, 0, sizeof(*buf2_0) * 512);
  67. memset(buf1, 0, sizeof(*buf2_1) * 512);
  68. memset(buf_b, 0, sizeof(*buf2_b) * 512);
  69. /* more than 1 synth_buf_offset wrap-around */
  70. for (i = 0; i < 20; i++) {
  71. int j;
  72. const float * window = (i & 1) ? ff_dca_fir_32bands_perfect : ff_dca_fir_32bands_nonperfect;
  73. memset(out0, 0, sizeof(*out0) * BUF_SIZE);
  74. memset(out1, 0, sizeof(*out1) * BUF_SIZE);
  75. memset(out_b, 0, sizeof(*out_b) * BUF_SIZE);
  76. randomize_input();
  77. call_ref(imdct, buf0, &offset0, buf2_0, window,
  78. out0, in, scale, imdct_fn);
  79. call_new(imdct, buf1, &offset1, buf2_1, window,
  80. out1, in, scale, imdct_fn);
  81. if (offset0 != offset1) {
  82. fail();
  83. fprintf(stderr, "offsets do not match: %d, %d", offset0, offset1);
  84. break;
  85. }
  86. for (j = 0; j < BUF_SIZE; j++) {
  87. if (!float_near_abs_eps_ulp(out0[j], out1[j], 7.0e-7, 16) ||
  88. !float_near_abs_eps_ulp(buf2_0[j], buf2_1[j], 7.0e-7, 16)) {
  89. union av_intfloat32 o0, o1, b0, b1;
  90. fail();
  91. o0.f = out0[j]; o1.f = out1[j];
  92. b0.f = buf2_0[j], b1.f = buf2_1[j];
  93. fprintf(stderr, "out: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
  94. o0.f, o0.i, o1.f, o1.i, fabsf(o0.f - o1.f));
  95. fprintf(stderr, "buf2: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
  96. b0.f, b0.i, b1.f, b1.i, fabsf(b0.f - b1.f));
  97. break;
  98. }
  99. }
  100. bench_new(imdct, buf_b, &offset_b, buf2_b, window,
  101. out_b, in, scale, imdct_fn);
  102. }
  103. }
  104. av_tx_uninit(&imdct);
  105. report("synth_filter");
  106. }