aacencdsp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
  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 <string.h>
  21. #include "libavutil/mem_internal.h"
  22. #include "libavcodec/aacenc_utils.h"
  23. #include "libavcodec/aacencdsp.h"
  24. #include "libavcodec/aactab.h"
  25. #include "checkasm.h"
  26. #define randomize_float(buf, len) \
  27. do { \
  28. int i; \
  29. for (i = 0; i < len; i++) { \
  30. float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
  31. buf[i] = f; \
  32. } \
  33. } while (0)
  34. #define randomize_elem(tab) (tab[rnd() % FF_ARRAY_ELEMS(tab)])
  35. static void test_abs_pow34(AACEncDSPContext *s)
  36. {
  37. #define BUF_SIZE 1024
  38. LOCAL_ALIGNED_32(float, in, [BUF_SIZE]);
  39. declare_func(void, float *, const float *, int);
  40. randomize_float(in, BUF_SIZE);
  41. if (check_func(s->abs_pow34, "abs_pow34")) {
  42. LOCAL_ALIGNED_32(float, out, [BUF_SIZE]);
  43. LOCAL_ALIGNED_32(float, out2, [BUF_SIZE]);
  44. call_ref(out, in, BUF_SIZE);
  45. call_new(out2, in, BUF_SIZE);
  46. if (!float_near_ulp_array(out, out2, 1, BUF_SIZE))
  47. fail();
  48. bench_new(out, in, BUF_SIZE);
  49. }
  50. report("abs_pow34");
  51. }
  52. static void test_quant_bands(AACEncDSPContext *s)
  53. {
  54. int maxval = randomize_elem(aac_cb_maxval);
  55. float q34 = randomize_elem(ff_aac_pow34sf_tab);
  56. float rounding = (rnd() & 1) ? ROUND_TO_ZERO : ROUND_STANDARD;
  57. LOCAL_ALIGNED_16(float, in, [BUF_SIZE]);
  58. LOCAL_ALIGNED_16(float, scaled, [BUF_SIZE]);
  59. declare_func(void, int *, const float *, const float *, int, int, int,
  60. const float, const float);
  61. randomize_float(in, BUF_SIZE);
  62. randomize_float(scaled, BUF_SIZE);
  63. for (int sign = 0; sign <= 1; sign++) {
  64. if (check_func(s->quant_bands, "quant_bands_%s",
  65. sign ? "signed" : "unsigned")) {
  66. LOCAL_ALIGNED_32(int, out, [BUF_SIZE]);
  67. LOCAL_ALIGNED_32(int, out2, [BUF_SIZE]);
  68. call_ref(out, in, scaled, BUF_SIZE, sign, maxval, q34, rounding);
  69. call_new(out2, in, scaled, BUF_SIZE, sign, maxval, q34, rounding);
  70. if (memcmp(out, out2, BUF_SIZE * sizeof (int)))
  71. fail();
  72. bench_new(out, in, scaled, BUF_SIZE, sign, maxval, q34, rounding);
  73. }
  74. }
  75. report("quant_bands");
  76. }
  77. void checkasm_check_aacencdsp(void)
  78. {
  79. AACEncDSPContext s = { 0 };
  80. ff_aacenc_dsp_init(&s);
  81. test_abs_pow34(&s);
  82. test_quant_bands(&s);
  83. }