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/mem_internal.h"
20 
21 #include "libavcodec/lpc.h"
22 
23 #include "checkasm.h"
24 
25 #define randomize_int32(buf, len) \
26  do { \
27  for (int i = 0; i < len; i++) { \
28  int32_t f = ((int)(UINT32_MAX >> 17)) - ((int)(rnd() >> 16)); \
29  buf[i] = f; \
30  } \
31  } while (0)
32 
33 #define EPS 0.005
34 
35 static void test_window(int len)
36 {
37  LOCAL_ALIGNED(16, int32_t, src, [5000]);
38  LOCAL_ALIGNED(16, double, dst0, [5000]);
39  LOCAL_ALIGNED(16, double, dst1, [5000]);
40 
41  declare_func(void, const int32_t *in, ptrdiff_t len, double *out);
42 
44 
45  call_ref(src, len, dst0);
46  call_new(src, len, dst1);
47 
48  for (int i = 0; i < len; i++) {
49  if (!double_near_abs_eps(dst0[i], dst1[i], EPS)) {
50  fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
51  i, dst0[i], dst1[i], dst0[i] - dst1[i]);
52  fail();
53  break;
54  }
55  }
56 
57  bench_new(src, len, dst1);
58 }
59 
61 {
63  int len = rnd() % 5000;
65 
66  if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_even")) {
67  test_window(len & ~1);
68  }
69  report("apply_welch_window_even");
70 
71  if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_odd")) {
72  test_window(len | 1);
73  }
74  report("apply_welch_window_odd");
75 
76  ff_lpc_end(&ctx);
77 }
checkasm_check_lpc
void checkasm_check_lpc(void)
Definition: lpc.c:60
mem_internal.h
out
FILE * out
Definition: movenc.c:55
randomize_int32
#define randomize_int32(buf, len)
Definition: lpc.c:25
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:339
test_window
static void test_window(int len)
Definition: lpc.c:35
check_func
#define check_func(func,...)
Definition: checkasm.h:170
lpc.h
call_ref
#define call_ref(...)
Definition: checkasm.h:185
LPCContext
Definition: lpc.h:51
double_near_abs_eps
int double_near_abs_eps(double a, double b, double eps)
Definition: checkasm.c:428
fail
#define fail()
Definition: checkasm.h:179
checkasm.h
FF_LPC_TYPE_DEFAULT
@ FF_LPC_TYPE_DEFAULT
use the codec default LPC type
Definition: lpc.h:43
rnd
#define rnd()
Definition: checkasm.h:163
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:133
ctx
AVFormatContext * ctx
Definition: movenc.c:49
call_new
#define call_new(...)
Definition: checkasm.h:288
ff_lpc_end
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
Definition: lpc.c:364
EPS
#define EPS
Definition: lpc.c:33
report
#define report
Definition: checkasm.h:182
bench_new
#define bench_new(...)
Definition: checkasm.h:358
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:174
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
int32_t
int32_t
Definition: audioconvert.c:56