FFmpeg
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"
20 #include "libavutil/mem_internal.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 
36 static 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 
61 static 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 
75  src += MAX_LPC_ORDER;
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 }
checkasm_check_lpc
void checkasm_check_lpc(void)
Definition: lpc.c:96
mem_internal.h
out
FILE * out
Definition: movenc.c:55
randomize_int32
#define randomize_int32(buf, len)
Definition: lpc.c:26
ff_lpc_init
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
Definition: lpc.c:340
test_window
static void test_window(int len)
Definition: lpc.c:36
check_func
#define check_func(func,...)
Definition: checkasm.h:180
lpc.h
call_ref
#define call_ref(...)
Definition: checkasm.h:195
LPCContext
Definition: lpc.h:51
double_near_abs_eps
int double_near_abs_eps(double a, double b, double eps)
Definition: checkasm.c:489
fail
#define fail()
Definition: checkasm.h:189
checkasm.h
FF_LPC_TYPE_DEFAULT
@ FF_LPC_TYPE_DEFAULT
use the codec default LPC type
Definition: lpc.h:43
avassert.h
rnd
#define rnd()
Definition: checkasm.h:173
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:133
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
ctx
AVFormatContext * ctx
Definition: movenc.c:49
call_new
#define call_new(...)
Definition: checkasm.h:298
ff_lpc_end
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
Definition: lpc.c:365
double
double
Definition: af_crystalizer.c:132
MAX_LPC_ORDER
#define MAX_LPC_ORDER
Definition: lpc.h:37
EPS
#define EPS
Definition: lpc.c:34
report
#define report
Definition: checkasm.h:192
bench_new
#define bench_new(...)
Definition: checkasm.h:369
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
len
int len
Definition: vorbis_enc_data.h:426
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:184
test_compute_autocorr
static void test_compute_autocorr(ptrdiff_t len, int lag)
Definition: lpc.c:61
int32_t
int32_t
Definition: audioconvert.c:56
src
#define src
Definition: vp8dsp.c:248