alacdsp.c 4.5 KB

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