summaryrefslogtreecommitdiffstats
path: root/tests/checkasm/dcadsp.c
blob: 809a0a09746c0c574954aff0675a0e8b288c2797 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdint.h>
#include <string.h>

#include "libavcodec/dcadata.h"
#include "libavcodec/dcadsp.h"
#include "libavutil/common.h"
#include "libavutil/mem_internal.h"

#include "checkasm.h"

#define N 32
#define BLOCKSIZE 128
#define BUF_SIZE (N * BLOCKSIZE)
#define LFE_HISTORY 8
#define LFE_SIZE (N + LFE_HISTORY + 1)

/* sign_extend(rnd(), 23) would be the correct approach here,
 * but it results in differences that would require a much
 * bigger EPS value, thus we use 16 (simplified as a cast). */
#define randomize(buf, len) do {   \
    for (int i = 0; i < len; i++)  \
        (buf)[i] = (int16_t)rnd(); \
} while (0)

#define EPS 0.0005f

static void test_lfe_fir_float(const DCADSPContext *dca)
{
    LOCAL_ALIGNED_16(float, dst0,  [BUF_SIZE]);
    LOCAL_ALIGNED_16(float, dst1,  [BUF_SIZE]);
    LOCAL_ALIGNED_16(int32_t, lfe, [LFE_SIZE]);

    declare_func(void, float *pcm_samples, const int32_t *lfe_samples,
                       const float *filter_coeff, ptrdiff_t npcmblocks);

    for (int i = 0; i < 2; i++) {
        const float *coeffs = i ? ff_dca_lfe_fir_128 : ff_dca_lfe_fir_64;
        if (check_func(dca->lfe_fir_float[i], "lfe_fir%d_float", i)) {
            memset(dst0, 0, BUF_SIZE * sizeof(float));
            memset(dst1, 0, BUF_SIZE * sizeof(float));
            randomize(lfe, LFE_SIZE);
            call_ref(dst0, lfe + LFE_HISTORY, coeffs, N);
            call_new(dst1, lfe + LFE_HISTORY, coeffs, N);
            if (!float_near_abs_eps_array(dst0, dst1, EPS, BUF_SIZE))
                fail();
            bench_new(dst1, lfe + LFE_HISTORY, coeffs, N);
        }
    }
}

static void test_lfe_fir_fixed(void)
{
    LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]);
    LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]);
    LOCAL_ALIGNED_16(int32_t, lfe,  [LFE_SIZE]);
    const int32_t *coeffs = ff_dca_lfe_fir_64_fixed;

    declare_func(void, int32_t *pcm_samples, const int32_t *lfe_samples,
                       const int32_t *filter_coeff, ptrdiff_t npcmblocks);

    memset(dst0, 0, BUF_SIZE * sizeof(int32_t));
    memset(dst1, 0, BUF_SIZE * sizeof(int32_t));
    randomize(lfe, LFE_SIZE);
    call_ref(dst0, lfe + LFE_HISTORY, coeffs, N);
    call_new(dst1, lfe + LFE_HISTORY, coeffs, N);
    if (memcmp(dst0, dst1, BUF_SIZE * sizeof(int32_t)))
        fail();
    bench_new(dst1, lfe + LFE_HISTORY, coeffs, N);
}

void checkasm_check_dcadsp(void)
{
    DCADSPContext dca;

    ff_dcadsp_init(&dca);

    test_lfe_fir_float(&dca);
    report("lfe_fir_float");

    if (check_func(dca.lfe_fir_fixed, "lfe_fir_fixed"))
        test_lfe_fir_fixed();
    report("lfe_fir_fixed");
}