2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "libavcodec/dcadata.h"
23 #include "libavcodec/dcadsp.h"
24 #include "libavutil/common.h"
25 #include "libavutil/mem_internal.h"
31 #define BUF_SIZE (N * BLOCKSIZE)
33 #define LFE_SIZE (N + LFE_HISTORY + 1)
35 /* sign_extend(rnd(), 23) would be the correct approach here,
36 * but it results in differences that would require a much
37 * bigger EPS value, thus we use 16 (simplified as a cast). */
38 #define randomize(buf, len) do { \
39 for (int i = 0; i < len; i++) \
40 (buf)[i] = (int16_t)rnd(); \
45 static void test_lfe_fir_float(const DCADSPContext
*dca
)
47 LOCAL_ALIGNED_16(float, dst0
, [BUF_SIZE
]);
48 LOCAL_ALIGNED_16(float, dst1
, [BUF_SIZE
]);
49 LOCAL_ALIGNED_16(int32_t, lfe
, [LFE_SIZE
]);
51 declare_func(void, float *pcm_samples
, const int32_t *lfe_samples
,
52 const float *filter_coeff
, ptrdiff_t npcmblocks
);
54 for (int i
= 0; i
< 2; i
++) {
55 const float *coeffs
= i
? ff_dca_lfe_fir_128
: ff_dca_lfe_fir_64
;
56 if (check_func(dca
->lfe_fir_float
[i
], "lfe_fir%d_float", i
)) {
57 memset(dst0
, 0, BUF_SIZE
* sizeof(float));
58 memset(dst1
, 0, BUF_SIZE
* sizeof(float));
59 randomize(lfe
, LFE_SIZE
);
60 call_ref(dst0
, lfe
+ LFE_HISTORY
, coeffs
, N
);
61 call_new(dst1
, lfe
+ LFE_HISTORY
, coeffs
, N
);
62 if (!float_near_abs_eps_array(dst0
, dst1
, EPS
, BUF_SIZE
))
64 bench_new(dst1
, lfe
+ LFE_HISTORY
, coeffs
, N
);
69 static void test_lfe_fir_fixed(void)
71 LOCAL_ALIGNED_16(int32_t, dst0
, [BUF_SIZE
]);
72 LOCAL_ALIGNED_16(int32_t, dst1
, [BUF_SIZE
]);
73 LOCAL_ALIGNED_16(int32_t, lfe
, [LFE_SIZE
]);
74 const int32_t *coeffs
= ff_dca_lfe_fir_64_fixed
;
76 declare_func(void, int32_t *pcm_samples
, const int32_t *lfe_samples
,
77 const int32_t *filter_coeff
, ptrdiff_t npcmblocks
);
79 memset(dst0
, 0, BUF_SIZE
* sizeof(int32_t));
80 memset(dst1
, 0, BUF_SIZE
* sizeof(int32_t));
81 randomize(lfe
, LFE_SIZE
);
82 call_ref(dst0
, lfe
+ LFE_HISTORY
, coeffs
, N
);
83 call_new(dst1
, lfe
+ LFE_HISTORY
, coeffs
, N
);
84 if (memcmp(dst0
, dst1
, BUF_SIZE
* sizeof(int32_t)))
86 bench_new(dst1
, lfe
+ LFE_HISTORY
, coeffs
, N
);
89 void checkasm_check_dcadsp(void)
95 test_lfe_fir_float(&dca
);
96 report("lfe_fir_float");
98 if (check_func(dca
.lfe_fir_fixed
, "lfe_fir_fixed"))
100 report("lfe_fir_fixed");