FFmpeg
dcadsp.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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.
17  */
18 
19 #include <stdint.h>
20 #include <string.h>
21 
22 #include "libavcodec/dcadata.h"
23 #include "libavcodec/dcadsp.h"
24 #include "libavutil/common.h"
25 #include "libavutil/mem_internal.h"
26 
27 #include "checkasm.h"
28 
29 #define N 32
30 #define BLOCKSIZE 128
31 #define BUF_SIZE (N * BLOCKSIZE)
32 #define LFE_HISTORY 8
33 #define LFE_SIZE (N + LFE_HISTORY + 1)
34 
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(); \
41 } while (0)
42 
43 #define EPS 0.0005f
44 
45 static void test_lfe_fir_float(const DCADSPContext *dca)
46 {
47  LOCAL_ALIGNED_16(float, dst0, [BUF_SIZE]);
48  LOCAL_ALIGNED_16(float, dst1, [BUF_SIZE]);
50 
51  declare_func(void, float *pcm_samples, const int32_t *lfe_samples,
52  const float *filter_coeff, ptrdiff_t npcmblocks);
53 
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))
63  fail();
64  bench_new(dst1, lfe + LFE_HISTORY, coeffs, N);
65  }
66  }
67 }
68 
69 static void test_lfe_fir_fixed(void)
70 {
74  const int32_t *coeffs = ff_dca_lfe_fir_64_fixed;
75 
76  declare_func(void, int32_t *pcm_samples, const int32_t *lfe_samples,
77  const int32_t *filter_coeff, ptrdiff_t npcmblocks);
78 
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)))
85  fail();
86  bench_new(dst1, lfe + LFE_HISTORY, coeffs, N);
87 }
88 
90 {
91  DCADSPContext dca;
92 
93  ff_dcadsp_init(&dca);
94 
95  test_lfe_fir_float(&dca);
96  report("lfe_fir_float");
97 
98  if (check_func(dca.lfe_fir_fixed, "lfe_fir_fixed"))
100  report("lfe_fir_fixed");
101 }
mem_internal.h
float_near_abs_eps_array
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
Definition: checkasm.c:488
EPS
#define EPS
Definition: dcadsp.c:43
DCADSPContext::lfe_fir_fixed
void(* lfe_fir_fixed)(int32_t *pcm_samples, const int32_t *lfe_samples, const int32_t *filter_coeff, ptrdiff_t npcmblocks)
Definition: dcadsp.h:59
randomize
#define randomize(buf, len)
Definition: dcadsp.c:38
check_func
#define check_func(func,...)
Definition: checkasm.h:195
call_ref
#define call_ref(...)
Definition: checkasm.h:210
ff_dca_lfe_fir_128
const float ff_dca_lfe_fir_128[256]
Definition: dcadata.c:7482
fail
#define fail()
Definition: checkasm.h:204
checkasm.h
DCADSPContext::lfe_fir_float
void(* lfe_fir_float[2])(float *pcm_samples, const int32_t *lfe_samples, const float *filter_coeff, ptrdiff_t npcmblocks)
Definition: dcadsp.h:43
dcadata.h
ff_dca_lfe_fir_64_fixed
const int32_t ff_dca_lfe_fir_64_fixed[256]
Definition: dcadata.c:8336
test_lfe_fir_fixed
static void test_lfe_fir_fixed(void)
Definition: dcadsp.c:69
LFE_HISTORY
#define LFE_HISTORY
Definition: dcadsp.c:32
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:130
N
#define N
Definition: dcadsp.c:29
checkasm_check_dcadsp
void checkasm_check_dcadsp(void)
Definition: dcadsp.c:89
call_new
#define call_new(...)
Definition: checkasm.h:313
LFE_SIZE
#define LFE_SIZE
Definition: dcadsp.c:33
ff_dca_lfe_fir_64
const float ff_dca_lfe_fir_64[256]
Definition: dcadata.c:7339
test_lfe_fir_float
static void test_lfe_fir_float(const DCADSPContext *dca)
Definition: dcadsp.c:45
BUF_SIZE
#define BUF_SIZE
Definition: dcadsp.c:31
DCADSPContext
Definition: dcadsp.h:30
dcadsp.h
report
#define report
Definition: checkasm.h:207
ff_dcadsp_init
av_cold void ff_dcadsp_init(DCADSPContext *s)
Definition: dcadsp.c:461
bench_new
#define bench_new(...)
Definition: checkasm.h:398
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
common.h
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:199
int32_t
int32_t
Definition: audioconvert.c:56