alacdsp.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2015 James Almer
  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 "checkasm.h"
  22. #include "libavcodec/alacdsp.h"
  23. #include "libavcodec/mathops.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/internal.h"
  26. #include "libavutil/mem_internal.h"
  27. #define BUF_SIZE 256
  28. #define MAX_CHANNELS 2
  29. #define randomize_buffers() \
  30. do { \
  31. int i; \
  32. for (i = 0; i < BUF_SIZE*MAX_CHANNELS; i++) { \
  33. int32_t r = sign_extend(rnd(), 24); \
  34. ref_buf[i] = r; \
  35. new_buf[i] = r; \
  36. } \
  37. } while (0)
  38. static void check_decorrelate_stereo(void)
  39. {
  40. LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
  41. LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
  42. int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
  43. int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
  44. ALACDSPContext c;
  45. ff_alacdsp_init(&c);
  46. if (check_func(c.decorrelate_stereo, "alac_decorrelate_stereo")) {
  47. int len = (rnd() & 0xFF) + 1;
  48. int shift = rnd() & 0x1F;
  49. int weight = rnd() & 0xFF;
  50. declare_func(void, int32_t *buf[2], int len, int shift, int weight);
  51. randomize_buffers();
  52. call_ref(ref, len, shift, weight);
  53. call_new(new, len, shift, weight);
  54. if (memcmp(ref[0], new[0], len * sizeof(int32_t)) ||
  55. memcmp(ref[1], new[1], len * sizeof(int32_t)))
  56. fail();
  57. bench_new(new, BUF_SIZE, shift, weight);
  58. }
  59. report("decorrelate_stereo");
  60. }
  61. #undef randomize_buffers
  62. #define randomize_buffers() \
  63. do { \
  64. int i, j; \
  65. for (i = 0; i < BUF_SIZE; i++) { \
  66. for (j = 0; j < ch; j++) { \
  67. int32_t r = sign_extend(rnd(), 24); \
  68. ref[j][i] = r; \
  69. new[j][i] = r; \
  70. r = rnd() & 0xFF; \
  71. ref_ebb[j][i] = r; \
  72. new_ebb[j][i] = r; \
  73. } \
  74. } \
  75. } while (0)
  76. static void check_append_extra_bits(void)
  77. {
  78. LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS*2]);
  79. LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS*2]);
  80. int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
  81. int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
  82. int32_t *ref_ebb[2] = { &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3] };
  83. int32_t *new_ebb[2] = { &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3] };
  84. ALACDSPContext c;
  85. static const char * const channels[2] = { "mono", "stereo" };
  86. int ch;
  87. ff_alacdsp_init(&c);
  88. for (ch = 1; ch <= 2; ch++) {
  89. if (check_func(c.append_extra_bits[ch-1], "alac_append_extra_bits_%s", channels[ch-1])) {
  90. int len = (rnd() & 0xFF) + 1;
  91. declare_func(void, int32_t *buf[2], int32_t *ebb[2], int ebits, int ch, int len);
  92. randomize_buffers();
  93. call_ref(ref, ref_ebb, 8, ch, len);
  94. call_new(new, new_ebb, 8, ch, len);
  95. if ( memcmp(ref[0], new[0], len * sizeof(int32_t)) ||
  96. (ch == 2 && memcmp(ref[1], new[1], len * sizeof(int32_t))))
  97. fail();
  98. bench_new(new, new_ebb, 8, ch, BUF_SIZE);
  99. }
  100. }
  101. report("append_extra_bits");
  102. }
  103. void checkasm_check_alacdsp(void)
  104. {
  105. check_decorrelate_stereo();
  106. check_append_extra_bits();
  107. }