FFmpeg
Loading...
Searching...
No Matches
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 <string.h>
20
22
23#include "libavcodec/opus/dsp.h"
24#include "libavcodec/opus/tab.h"
25
26#include "checkasm.h"
27
28#define randomize_float(buf, len) \
29 do { \
30 for (int i = 0; i < len; i++) { \
31 float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
32 buf[i] = f; \
33 } \
34 } while (0)
35
36#define EPS 0.005
37#define MAX_SIZE (960)
38
39/* period is between 15 and 1022, inclusive */
40static void test_postfilter(int period)
41{
42 LOCAL_ALIGNED(16, float, data0, [MAX_SIZE + 1024]);
43 LOCAL_ALIGNED(16, float, data1, [MAX_SIZE + 1024]);
44
45 /* This filter can explode very easily, so use a tapset from the codec.
46 * In the codec these are usually multiplied by at least 0.09375f,
47 * so its outside the largest filter value, but the filter is still stable
48 * so use it. */
49 float gains[3] = { 0.3066406250f, 0.2170410156f, 0.1296386719f };
50
51 /* The codec will always call with an offset which is aligned once
52 * (period + 2) is subtracted, but here we have to align it ourselves. */
53 int offset = FFALIGN(period + 2, 4);
54
55 declare_func(void, float *data, int period, float *gains, int len);
56
57 randomize_float(data0, MAX_SIZE + 1024);
58 memcpy(data1, data0, (MAX_SIZE + 1024)*sizeof(float));
59
60 call_ref(data0 + offset, period, gains, MAX_SIZE);
61 call_new(data1 + offset, period, gains, MAX_SIZE);
62
63 if (!float_near_abs_eps_array(data0 + offset, data1 + offset, EPS, MAX_SIZE))
64 fail();
65 bench_new(data1 + offset, period, gains, MAX_SIZE);
66}
67
68static void test_deemphasis(void)
69{
70 LOCAL_ALIGNED(16, float, src, [FFALIGN(MAX_SIZE, 4)]);
71 LOCAL_ALIGNED(16, float, dst0, [FFALIGN(MAX_SIZE, 4)]);
72 LOCAL_ALIGNED(16, float, dst1, [FFALIGN(MAX_SIZE, 4)]);
73 float coeff0 = (float)rnd() / (UINT_MAX >> 5) - 16.0f, coeff1 = coeff0;
74
75 declare_func_float(float, float *out, float *in, float coeff, const float *weights, int len);
76
78
79 coeff0 = call_ref(dst0, src, coeff0, ff_opus_deemph_weights, MAX_SIZE);
80 coeff1 = call_new(dst1, src, coeff1, ff_opus_deemph_weights, MAX_SIZE);
81
82 if (!float_near_abs_eps(coeff0, coeff1, EPS) ||
84 fail();
86}
87
89{
92
93 if (check_func(ctx.postfilter, "postfilter_15"))
95 report("postfilter_15");
96
97 if (check_func(ctx.postfilter, "postfilter_512"))
98 test_postfilter(512);
99 report("postfilter_512");
100
101 if (check_func(ctx.postfilter, "postfilter_1022"))
102 test_postfilter(1022);
103 report("postfilter_1022");
104
105 if (check_func(ctx.deemphasis, "deemphasis"))
107 report("deemphasis");
108}
#define EPS
Definition aacpsdsp.c:39
#define declare_func_float
Definition checkasm.h:137
#define rnd
Definition checkasm.h:136
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define float_near_abs_eps_array
Definition utils.h:452
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define float_near_abs_eps
Definition utils.h:449
#define report
Definition test.h:480
static const int weights[]
Definition hevc_pel.c:32
unsigned offset
Definition libaomenc.c:763
#define FFALIGN(x, a)
Definition macros.h:78
#define LOCAL_ALIGNED(a, t, v,...)
const char data[16]
Definition mxf.c:149
av_cold void ff_opus_dsp_init(OpusDSP *ctx)
Definition dsp.c:56
void checkasm_check_opusdsp(void)
Definition opusdsp.c:88
static void test_postfilter(int period)
Definition opusdsp.c:40
static void test_deemphasis(void)
Definition opusdsp.c:68
#define randomize_float(buf, len)
Definition opusdsp.c:28
Definition dsp.h:22
const float ff_opus_deemph_weights[]
Definition tab.c:1233
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
#define MAX_SIZE
Definition vf_colormap.c:35
static const double coeff[2][5]
int len