FFmpeg
synth_filter.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Janne Grunau
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <math.h>
22 #include <string.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 #include "libavutil/internal.h"
27 #include "libavutil/intfloat.h"
28 #include "libavutil/mem_internal.h"
29 
30 #include "libavcodec/dcadata.h"
32 
33 #include "checkasm.h"
34 
35 #define BUF_SIZE 32
36 
37 #define randomize_input() \
38  do { \
39  int i; \
40  for (i = 0; i < BUF_SIZE; i++) { \
41  float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
42  in[i] = f; \
43  } \
44  } while (0)
45 
47 {
48  FFTContext imdct;
49  SynthFilterContext synth;
50 
51  ff_mdct_init(&imdct, 6, 1, 1.0);
52  ff_synth_filter_init(&synth);
53 
54  if (check_func(synth.synth_filter_float, "synth_filter_float")) {
55  LOCAL_ALIGNED(32, float, out0, [BUF_SIZE]);
56  LOCAL_ALIGNED(32, float, out1, [BUF_SIZE]);
57  LOCAL_ALIGNED(32, float, out_b, [BUF_SIZE]);
58  LOCAL_ALIGNED(32, float, in, [BUF_SIZE]);
59  LOCAL_ALIGNED(32, float, buf2_0, [BUF_SIZE]);
60  LOCAL_ALIGNED(32, float, buf2_1, [BUF_SIZE]);
61  LOCAL_ALIGNED(32, float, buf2_b, [BUF_SIZE]);
62  LOCAL_ALIGNED(32, float, buf0, [512]);
63  LOCAL_ALIGNED(32, float, buf1, [512]);
64  LOCAL_ALIGNED(32, float, buf_b, [512]);
65  float scale = 1.0f;
66  int i, offset0 = 0, offset1 = 0, offset_b = 0;
67 
68  declare_func(void, FFTContext *, float *, int *, float[32], const float[512],
69  float[32], float[32], float);
70 
71  memset(buf2_0, 0, sizeof(*buf2_0) * BUF_SIZE);
72  memset(buf2_1, 0, sizeof(*buf2_1) * BUF_SIZE);
73  memset(buf2_b, 0, sizeof(*buf2_b) * BUF_SIZE);
74  memset(buf0, 0, sizeof(*buf2_0) * 512);
75  memset(buf1, 0, sizeof(*buf2_1) * 512);
76  memset(buf_b, 0, sizeof(*buf2_b) * 512);
77 
78  /* more than 1 synth_buf_offset wrap-around */
79  for (i = 0; i < 20; i++) {
80  int j;
82 
83  memset(out0, 0, sizeof(*out0) * BUF_SIZE);
84  memset(out1, 0, sizeof(*out1) * BUF_SIZE);
85  memset(out_b, 0, sizeof(*out_b) * BUF_SIZE);
86 
88 
89  call_ref(&imdct, buf0, &offset0, buf2_0, window,
90  out0, in, scale);
91  call_new(&imdct, buf1, &offset1, buf2_1, window,
92  out1, in, scale);
93 
94  if (offset0 != offset1) {
95  fail();
96  fprintf(stderr, "offsets do not match: %d, %d", offset0, offset1);
97  break;
98  }
99 
100  for (j = 0; j < BUF_SIZE; j++) {
101  if (!float_near_abs_eps_ulp(out0[j], out1[j], 7.0e-7, 16) ||
102  !float_near_abs_eps_ulp(buf2_0[j], buf2_1[j], 7.0e-7, 16)) {
103  union av_intfloat32 o0, o1, b0, b1;
104 
105  fail();
106  o0.f = out0[j]; o1.f = out1[j];
107  b0.f = buf2_0[j], b1.f = buf2_1[j];
108  fprintf(stderr, "out: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
109  o0.f, o0.i, o1.f, o1.i, fabsf(o0.f - o1.f));
110  fprintf(stderr, "buf2: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
111  b0.f, b0.i, b1.f, b1.i, fabsf(b0.f - b1.f));
112  break;
113  }
114  }
115 
116  bench_new(&imdct, buf_b, &offset_b, buf2_b, window,
117  out_b, in, scale);
118  }
119  }
120  ff_mdct_end(&imdct);
121 
122  report("synth_filter");
123 }
BUF_SIZE
#define BUF_SIZE
Definition: synth_filter.c:35
mem_internal.h
synth_filter.h
SynthFilterContext::synth_filter_float
void(* synth_filter_float)(FFTContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[32], const float window[512], float out[32], const float in[32], float scale)
Definition: synth_filter.h:28
av_intfloat32::i
uint32_t i
Definition: intfloat.h:28
check_func
#define check_func(func,...)
Definition: checkasm.h:122
ff_mdct_init
#define ff_mdct_init
Definition: fft.h:153
call_ref
#define call_ref(...)
Definition: checkasm.h:137
intfloat.h
ff_synth_filter_init
av_cold void ff_synth_filter_init(SynthFilterContext *c)
Definition: synth_filter.c:171
window
static SDL_Window * window
Definition: ffplay.c:365
randomize_input
#define randomize_input()
Definition: synth_filter.c:37
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1771
ff_dca_fir_32bands_nonperfect
const float ff_dca_fir_32bands_nonperfect[512]
Definition: dcadata.c:6808
SynthFilterContext
Definition: synth_filter.h:27
fail
#define fail()
Definition: checkasm.h:131
checkasm.h
float_near_abs_eps_ulp
int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
Definition: checkasm.c:357
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
dcadata.h
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
checkasm_check_synth_filter
void checkasm_check_synth_filter(void)
Definition: synth_filter.c:46
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:113
call_new
#define call_new(...)
Definition: checkasm.h:209
av_intfloat32
Definition: intfloat.h:27
ff_mdct_end
#define ff_mdct_end
Definition: fft.h:154
report
#define report
Definition: checkasm.h:134
FFTContext
Definition: fft.h:75
bench_new
#define bench_new(...)
Definition: checkasm.h:272
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
internal.h
av_intfloat32::f
float f
Definition: intfloat.h:29
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:126
ff_dca_fir_32bands_perfect
const float ff_dca_fir_32bands_perfect[512]
Definition: dcadata.c:6293
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:1770