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 
89 static void test_lfe_x96_fixed(const DCADSPContext *dca)
90 {
91  LOCAL_ALIGNED_16(int32_t, dst0, [2 * BUF_SIZE]);
92  LOCAL_ALIGNED_16(int32_t, dst1, [2 * BUF_SIZE]);
94  int32_t hist0, hist1;
95 
96  declare_func(void, int32_t *dst, const int32_t *src, int32_t *hist, ptrdiff_t len);
97 
98  if (check_func(dca->lfe_x96_fixed, "lfe_x96_fixed")) {
100  hist0 = hist1 = (int16_t)rnd();
101  call_ref(dst0, src, &hist0, BUF_SIZE);
102  call_new(dst1, src, &hist1, BUF_SIZE);
103  if (memcmp(dst0, dst1, 2 * BUF_SIZE * sizeof(int32_t)))
104  fail();
105  bench_new(dst1, src, &hist1, BUF_SIZE);
106  }
107 }
108 
110 {
111  DCADSPContext dca;
112 
113  ff_dcadsp_init(&dca);
114 
115  test_lfe_fir_float(&dca);
116  report("lfe_fir_float");
117 
118  if (check_func(dca.lfe_fir_fixed, "lfe_fir_fixed"))
120  report("lfe_fir_fixed");
121 
122  test_lfe_x96_fixed(&dca);
123  report("lfe_x96_fixed");
124 }
mem_internal.h
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
Definition: test.h:481
bench_new
#define bench_new
Definition: test.h:487
call_ref
#define call_ref
Definition: test.h:485
ff_dca_lfe_fir_128
const float ff_dca_lfe_fir_128[256]
Definition: dcadata.c:7482
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
DCADSPContext::lfe_x96_fixed
void(* lfe_x96_fixed)(int32_t *dst, const int32_t *src, int32_t *hist, ptrdiff_t len)
Definition: dcadsp.h:62
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
declare_func
#define declare_func
Definition: test.h:489
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:109
fail
#define fail
Definition: test.h:479
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
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
rnd
#define rnd
Definition: checkasm.h:136
dcadsp.h
ff_dcadsp_init
av_cold void ff_dcadsp_init(DCADSPContext *s)
Definition: dcadsp.c:461
common.h
len
int len
Definition: vorbis_enc_data.h:426
call_new
#define call_new
Definition: test.h:486
report
#define report
Definition: test.h:480
float_near_abs_eps_array
#define float_near_abs_eps_array
Definition: utils.h:452
int32_t
int32_t
Definition: audioconvert.c:56
test_lfe_x96_fixed
static void test_lfe_x96_fixed(const DCADSPContext *dca)
Definition: dcadsp.c:89
src
#define src
Definition: vp8dsp.c:248