FFmpeg
Loading...
Searching...
No Matches
lpc.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/avassert.h"
21
22#include "libavcodec/lpc.h"
23
24#include "checkasm.h"
25
26#define randomize_int32(buf, len) \
27 do { \
28 for (int i = 0; i < len; i++) { \
29 int32_t f = ((int)(UINT32_MAX >> 17)) - ((int)(rnd() >> 16)); \
30 buf[i] = f; \
31 } \
32 } while (0)
33
34#define EPS 0.005
35
36static void test_window(int len)
37{
38 LOCAL_ALIGNED(16, int32_t, src, [5000]);
39 LOCAL_ALIGNED(16, double, dst0, [5000]);
40 LOCAL_ALIGNED(16, double, dst1, [5000]);
41
42 declare_func(void, const int32_t *in, ptrdiff_t len, double *out);
43
45
46 call_ref(src, len, dst0);
47 call_new(src, len, dst1);
48
49 for (int i = 0; i < len; i++) {
50 if (!double_near_abs_eps(dst0[i], dst1[i], EPS)) {
51 fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
52 i, dst0[i], dst1[i], dst0[i] - dst1[i]);
53 fail();
54 break;
55 }
56 }
57
58 bench_new(src, 4608 + (len & 1), dst1);
59}
60
61static void test_compute_autocorr(ptrdiff_t len, int lag)
62{
63 const double eps = EPS * (double)len;
64 LOCAL_ALIGNED(32, double, src, [5000 + 2 + MAX_LPC_ORDER]);
65 LOCAL_ALIGNED(16, double, dst0, [MAX_LPC_ORDER + 1]);
66 LOCAL_ALIGNED(16, double, dst1, [MAX_LPC_ORDER + 1]);
67
68 declare_func(void, const double *in, ptrdiff_t len, int lag, double *out);
69
70 av_assert0(lag >= 0 && lag <= MAX_LPC_ORDER);
71
72 for (int i = 0; i < MAX_LPC_ORDER; i++)
73 src[i] = 0.;
74
76
77 for (int i = 0; i < 5000 + 2; i++) {
78 src[i] = (double)rnd() / (double)UINT_MAX;
79 }
80
81 call_ref(src, len, lag, dst0);
82 call_new(src, len, lag, dst1);
83
84 for (size_t i = 0; i <= lag; i++) {
85 if (!double_near_abs_eps(dst0[i], dst1[i], eps)) {
86 fprintf(stderr, "%zu: %- .12f - %- .12f = % .12g\n",
87 i, dst0[i], dst1[i], dst0[i] - dst1[i]);
88 fail();
89 break;
90 }
91 }
92
93 bench_new(src, 4608 + (len & 1), lag, dst1);
94}
95
97{
99 int len = 2000 + rnd() % 3000;
100 static const int lags[] = { 8, 12, };
101
103
104 if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_even")) {
105 test_window(len & ~1);
106 }
107 report("apply_welch_window_even");
108
109 if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_odd")) {
110 test_window(len | 1);
111 }
112 report("apply_welch_window_odd");
113 ff_lpc_end(&ctx);
114
115 for (size_t i = 0; i < FF_ARRAY_ELEMS(lags); i++) {
117 if (check_func(ctx.lpc_compute_autocorr, "autocorr_%d_even", lags[i]))
118 test_compute_autocorr(len & ~1, lags[i]);
119#if !ARCH_X86
120 if (check_func(ctx.lpc_compute_autocorr, "autocorr_%d_odd", lags[i]))
121 test_compute_autocorr(len | 1, lags[i]);
122#endif
123 ff_lpc_end(&ctx);
124 }
125 report("compute_autocorr");
126}
#define EPS
Definition aacpsdsp.c:39
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#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 check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define double_near_abs_eps
Definition utils.h:454
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
Definition lpc.c:367
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
Definition lpc.c:342
#define MAX_LPC_ORDER
Definition lpc.h:37
@ FF_LPC_TYPE_DEFAULT
use the codec default LPC type
Definition lpc.h:43
#define LOCAL_ALIGNED(a, t, v,...)
#define FF_ARRAY_ELEMS(a)
#define randomize_int32(buf, len)
Definition lpc.c:26
static void test_window(int len)
Definition lpc.c:36
void checkasm_check_lpc(void)
Definition lpc.c:96
static void test_compute_autocorr(ptrdiff_t len, int lag)
Definition lpc.c:61
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
int len