FFmpeg
opusdsp.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 "libavutil/mem_internal.h"
20 
21 #include "libavcodec/opus/dsp.h"
22 #include "libavcodec/opus/tab.h"
23 
24 #include "checkasm.h"
25 
26 #define randomize_float(buf, len) \
27  do { \
28  for (int i = 0; i < len; i++) { \
29  float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
30  buf[i] = f; \
31  } \
32  } while (0)
33 
34 #define EPS 0.005
35 #define MAX_SIZE (960)
36 
37 /* period is between 15 and 1022, inclusive */
38 static void test_postfilter(int period)
39 {
40  LOCAL_ALIGNED(16, float, data0, [MAX_SIZE + 1024]);
41  LOCAL_ALIGNED(16, float, data1, [MAX_SIZE + 1024]);
42 
43  /* This filter can explode very easily, so use a tapset from the codec.
44  * In the codec these are usually multiplied by at least 0.09375f,
45  * so its outside the largest filter value, but the filter is still stable
46  * so use it. */
47  float gains[3] = { 0.3066406250f, 0.2170410156f, 0.1296386719f };
48 
49  /* The codec will always call with an offset which is aligned once
50  * (period + 2) is subtracted, but here we have to align it outselves. */
51  int offset = FFALIGN(period + 2, 4);
52 
53  declare_func(void, float *data, int period, float *gains, int len);
54 
55  randomize_float(data0, MAX_SIZE + 1024);
56  memcpy(data1, data0, (MAX_SIZE + 1024)*sizeof(float));
57 
58  call_ref(data0 + offset, period, gains, MAX_SIZE);
59  call_new(data1 + offset, period, gains, MAX_SIZE);
60 
61  if (!float_near_abs_eps_array(data0 + offset, data1 + offset, EPS, MAX_SIZE))
62  fail();
63  bench_new(data1 + offset, period, gains, MAX_SIZE);
64 }
65 
66 static void test_deemphasis(void)
67 {
68  LOCAL_ALIGNED(16, float, src, [FFALIGN(MAX_SIZE, 4)]);
69  LOCAL_ALIGNED(16, float, dst0, [FFALIGN(MAX_SIZE, 4)]);
70  LOCAL_ALIGNED(16, float, dst1, [FFALIGN(MAX_SIZE, 4)]);
71  float coeff0 = (float)rnd() / (UINT_MAX >> 5) - 16.0f, coeff1 = coeff0;
72 
73  declare_func_float(float, float *out, float *in, float coeff, const float *weights, int len);
74 
76 
77  coeff0 = call_ref(dst0, src, coeff0, ff_opus_deemph_weights, MAX_SIZE);
78  coeff1 = call_new(dst1, src, coeff1, ff_opus_deemph_weights, MAX_SIZE);
79 
80  if (!float_near_abs_eps(coeff0, coeff1, EPS) ||
81  !float_near_abs_eps_array(dst0, dst1, EPS, MAX_SIZE))
82  fail();
84 }
85 
87 {
88  OpusDSP ctx;
90 
91  if (check_func(ctx.postfilter, "postfilter_15"))
92  test_postfilter(15);
93  report("postfilter_15");
94 
95  if (check_func(ctx.postfilter, "postfilter_512"))
96  test_postfilter(512);
97  report("postfilter_512");
98 
99  if (check_func(ctx.postfilter, "postfilter_1022"))
100  test_postfilter(1022);
101  report("postfilter_1022");
102 
103  if (check_func(ctx.deemphasis, "deemphasis"))
104  test_deemphasis();
105  report("deemphasis");
106 }
mem_internal.h
out
FILE * out
Definition: movenc.c:55
float_near_abs_eps_array
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
Definition: checkasm.c:455
float_near_abs_eps
int float_near_abs_eps(float a, float b, float eps)
Definition: checkasm.c:444
check_func
#define check_func(func,...)
Definition: checkasm.h:179
data
const char data[16]
Definition: mxf.c:148
declare_func_float
#define declare_func_float(ret,...)
Definition: checkasm.h:184
call_ref
#define call_ref(...)
Definition: checkasm.h:194
ff_opus_deemph_weights
const float ff_opus_deemph_weights[]
Definition: tab.c:1169
fail
#define fail()
Definition: checkasm.h:188
checkasm.h
rnd
#define rnd()
Definition: checkasm.h:172
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:133
float
float
Definition: af_crystalizer.c:122
MAX_SIZE
#define MAX_SIZE
Definition: opusdsp.c:35
ctx
AVFormatContext * ctx
Definition: movenc.c:49
call_new
#define call_new(...)
Definition: checkasm.h:297
EPS
#define EPS
Definition: opusdsp.c:34
period
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without period
Definition: writing_filters.txt:89
f
f
Definition: af_crystalizer.c:122
ff_opus_dsp_init
av_cold void ff_opus_dsp_init(OpusDSP *ctx)
Definition: dsp.c:56
test_postfilter
static void test_postfilter(int period)
Definition: opusdsp.c:38
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
report
#define report
Definition: checkasm.h:191
tab.h
bench_new
#define bench_new(...)
Definition: checkasm.h:368
weights
static const int weights[]
Definition: hevc_pel.c:32
dsp.h
len
int len
Definition: vorbis_enc_data.h:426
randomize_float
#define randomize_float(buf, len)
Definition: opusdsp.c:26
test_deemphasis
static void test_deemphasis(void)
Definition: opusdsp.c:66
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:183
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
checkasm_check_opusdsp
void checkasm_check_opusdsp(void)
Definition: opusdsp.c:86
src
#define src
Definition: vp8dsp.c:248
OpusDSP
Definition: dsp.h:22