1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2015 James Almer
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or modify
7cabdff1aSopenharmony_ci * it under the terms of the GNU General Public License as published by
8cabdff1aSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
9cabdff1aSopenharmony_ci * (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14cabdff1aSopenharmony_ci * GNU General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU General Public License along
17cabdff1aSopenharmony_ci * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18cabdff1aSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#include <string.h>
22cabdff1aSopenharmony_ci#include "checkasm.h"
23cabdff1aSopenharmony_ci#include "libavcodec/flacdsp.h"
24cabdff1aSopenharmony_ci#include "libavutil/common.h"
25cabdff1aSopenharmony_ci#include "libavutil/internal.h"
26cabdff1aSopenharmony_ci#include "libavutil/intreadwrite.h"
27cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h"
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci#define BUF_SIZE 256
30cabdff1aSopenharmony_ci#define MAX_CHANNELS 8
31cabdff1aSopenharmony_ci
32cabdff1aSopenharmony_ci#define randomize_buffers()                                 \
33cabdff1aSopenharmony_ci    do {                                                    \
34cabdff1aSopenharmony_ci        int i, j;                                           \
35cabdff1aSopenharmony_ci        for (i = 0; i < BUF_SIZE; i += 4) {                 \
36cabdff1aSopenharmony_ci            for (j = 0; j < channels; j++) {                \
37cabdff1aSopenharmony_ci                uint32_t r = rnd() & (1 << (bits - 2)) - 1; \
38cabdff1aSopenharmony_ci                AV_WN32A(ref_src[j] + i, r);                \
39cabdff1aSopenharmony_ci                AV_WN32A(new_src[j] + i, r);                \
40cabdff1aSopenharmony_ci            }                                               \
41cabdff1aSopenharmony_ci        }                                                   \
42cabdff1aSopenharmony_ci    } while (0)
43cabdff1aSopenharmony_ci
44cabdff1aSopenharmony_cistatic void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **new_dst, uint8_t **new_src,
45cabdff1aSopenharmony_ci                              int channels, int bits) {
46cabdff1aSopenharmony_ci    declare_func(void, uint8_t **out, int32_t **in, int channels, int len, int shift);
47cabdff1aSopenharmony_ci
48cabdff1aSopenharmony_ci    randomize_buffers();
49cabdff1aSopenharmony_ci    call_ref(ref_dst, (int32_t **)ref_src, channels, BUF_SIZE / sizeof(int32_t), 8);
50cabdff1aSopenharmony_ci    call_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
51cabdff1aSopenharmony_ci    if (memcmp(*ref_dst, *new_dst, bits == 16 ? BUF_SIZE * (channels/2) : BUF_SIZE * channels) ||
52cabdff1aSopenharmony_ci        memcmp(*ref_src, *new_src, BUF_SIZE * channels))
53cabdff1aSopenharmony_ci        fail();
54cabdff1aSopenharmony_ci    bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
55cabdff1aSopenharmony_ci}
56cabdff1aSopenharmony_ci
57cabdff1aSopenharmony_civoid checkasm_check_flacdsp(void)
58cabdff1aSopenharmony_ci{
59cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(uint8_t, ref_dst, [BUF_SIZE*MAX_CHANNELS]);
60cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
61cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(uint8_t, new_dst, [BUF_SIZE*MAX_CHANNELS]);
62cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
63cabdff1aSopenharmony_ci    uint8_t *ref_src[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1], &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3],
64cabdff1aSopenharmony_ci                           &ref_buf[BUF_SIZE*4], &ref_buf[BUF_SIZE*5], &ref_buf[BUF_SIZE*6], &ref_buf[BUF_SIZE*7] };
65cabdff1aSopenharmony_ci    uint8_t *new_src[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1], &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3],
66cabdff1aSopenharmony_ci                           &new_buf[BUF_SIZE*4], &new_buf[BUF_SIZE*5], &new_buf[BUF_SIZE*6], &new_buf[BUF_SIZE*7] };
67cabdff1aSopenharmony_ci    static const char * const names[3] = { "ls", "rs", "ms" };
68cabdff1aSopenharmony_ci    static const struct {
69cabdff1aSopenharmony_ci        enum AVSampleFormat fmt;
70cabdff1aSopenharmony_ci        int bits;
71cabdff1aSopenharmony_ci    } fmts[] = {
72cabdff1aSopenharmony_ci        { AV_SAMPLE_FMT_S16, 16 },
73cabdff1aSopenharmony_ci        { AV_SAMPLE_FMT_S32, 32 },
74cabdff1aSopenharmony_ci    };
75cabdff1aSopenharmony_ci    FLACDSPContext h;
76cabdff1aSopenharmony_ci    int i, j;
77cabdff1aSopenharmony_ci
78cabdff1aSopenharmony_ci    for (i = 0; i < 2; i++) {
79cabdff1aSopenharmony_ci        ff_flacdsp_init(&h, fmts[i].fmt, 2, 0);
80cabdff1aSopenharmony_ci        for (j = 0; j < 3; j++)
81cabdff1aSopenharmony_ci            if (check_func(h.decorrelate[j], "flac_decorrelate_%s_%d", names[j], fmts[i].bits))
82cabdff1aSopenharmony_ci                check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, 2, fmts[i].bits);
83cabdff1aSopenharmony_ci        for (j = 2; j <= MAX_CHANNELS; j += 2) {
84cabdff1aSopenharmony_ci            ff_flacdsp_init(&h, fmts[i].fmt, j, 0);
85cabdff1aSopenharmony_ci            if (check_func(h.decorrelate[0], "flac_decorrelate_indep%d_%d", j, fmts[i].bits))
86cabdff1aSopenharmony_ci                check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, j, fmts[i].bits);
87cabdff1aSopenharmony_ci        }
88cabdff1aSopenharmony_ci    }
89cabdff1aSopenharmony_ci
90cabdff1aSopenharmony_ci    report("decorrelate");
91cabdff1aSopenharmony_ci}
92