2 * Copyright (c) 2015 James Almer
4 * This file is part of FFmpeg.
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.
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.
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.
23 #include "libavcodec/alacdsp.h"
24 #include "libavcodec/mathops.h"
25 #include "libavutil/common.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/mem_internal.h"
30 #define MAX_CHANNELS 2
32 #define randomize_buffers() \
35 for (i = 0; i < BUF_SIZE*MAX_CHANNELS; i++) { \
36 int32_t r = sign_extend(rnd(), 24); \
42 static void check_decorrelate_stereo(void)
44 LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
45 LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
46 int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
47 int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
51 if (check_func(c.decorrelate_stereo, "alac_decorrelate_stereo")) {
52 int len = (rnd() & 0xFF) + 1;
53 int shift = rnd() & 0x1F;
54 int weight = rnd() & 0xFF;
55 declare_func(void, int32_t *buf[2], int len, int shift, int weight);
58 call_ref(ref, len, shift, weight);
59 call_new(new, len, shift, weight);
60 if (memcmp(ref[0], new[0], len * sizeof(int32_t)) ||
61 memcmp(ref[1], new[1], len * sizeof(int32_t)))
63 bench_new(new, BUF_SIZE, shift, weight);
66 report("decorrelate_stereo");
69 #undef randomize_buffers
70 #define randomize_buffers() \
73 for (i = 0; i < BUF_SIZE; i++) { \
74 for (j = 0; j < ch; j++) { \
75 int32_t r = sign_extend(rnd(), 24); \
85 static void check_append_extra_bits(void)
87 LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS*2]);
88 LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS*2]);
89 int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
90 int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
91 int32_t *ref_ebb[2] = { &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3] };
92 int32_t *new_ebb[2] = { &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3] };
94 static const char * const channels[2] = { "mono", "stereo" };
98 for (ch = 1; ch <= 2; ch++) {
99 if (check_func(c.append_extra_bits[ch-1], "alac_append_extra_bits_%s", channels[ch-1])) {
100 int len = (rnd() & 0xFF) + 1;
101 declare_func(void, int32_t *buf[2], int32_t *ebb[2], int ebits, int ch, int len);
104 call_ref(ref, ref_ebb, 8, ch, len);
105 call_new(new, new_ebb, 8, ch, len);
106 if ( memcmp(ref[0], new[0], len * sizeof(int32_t)) ||
107 (ch == 2 && memcmp(ref[1], new[1], len * sizeof(int32_t))))
109 bench_new(new, new_ebb, 8, ch, BUF_SIZE);
113 report("append_extra_bits");
116 void checkasm_check_alacdsp(void)
118 check_decorrelate_stereo();
119 check_append_extra_bits();