FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "libavcodec/dcadata.h"
30 
31 #include "checkasm.h"
32 
33 #define BUF_SIZE 32
34 
35 #define randomize_input() \
36  do { \
37  int i; \
38  for (i = 0; i < BUF_SIZE; i++) { \
39  float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
40  in[i] = f; \
41  } \
42  } while (0)
43 
45 {
46  FFTContext imdct;
47  SynthFilterContext synth;
48 
49  ff_mdct_init(&imdct, 6, 1, 1.0);
50  ff_synth_filter_init(&synth);
51 
52  if (check_func(synth.synth_filter_float, "synth_filter_float")) {
53  LOCAL_ALIGNED(32, float, out0, [BUF_SIZE]);
54  LOCAL_ALIGNED(32, float, out1, [BUF_SIZE]);
55  LOCAL_ALIGNED(32, float, out_b, [BUF_SIZE]);
56  LOCAL_ALIGNED(32, float, in, [BUF_SIZE]);
57  LOCAL_ALIGNED(32, float, buf2_0, [BUF_SIZE]);
58  LOCAL_ALIGNED(32, float, buf2_1, [BUF_SIZE]);
59  LOCAL_ALIGNED(32, float, buf2_b, [BUF_SIZE]);
60  LOCAL_ALIGNED(32, float, buf0, [512]);
61  LOCAL_ALIGNED(32, float, buf1, [512]);
62  LOCAL_ALIGNED(32, float, buf_b, [512]);
63  float scale = 1.0f;
64  int i, offset0 = 0, offset1 = 0, offset_b = 0;
65 
66  declare_func(void, FFTContext *, float *, int *, float[32], const float[512],
67  float[32], float[32], float);
68 
69  memset(buf2_0, 0, sizeof(*buf2_0) * BUF_SIZE);
70  memset(buf2_1, 0, sizeof(*buf2_1) * BUF_SIZE);
71  memset(buf2_b, 0, sizeof(*buf2_b) * BUF_SIZE);
72  memset(buf0, 0, sizeof(*buf2_0) * 512);
73  memset(buf1, 0, sizeof(*buf2_1) * 512);
74  memset(buf_b, 0, sizeof(*buf2_b) * 512);
75 
76  /* more than 1 synth_buf_offset wrap-around */
77  for (i = 0; i < 20; i++) {
78  int j;
79  const float * window = (i & 1) ? ff_dca_fir_32bands_perfect : ff_dca_fir_32bands_nonperfect;
80 
81  memset(out0, 0, sizeof(*out0) * BUF_SIZE);
82  memset(out1, 0, sizeof(*out1) * BUF_SIZE);
83  memset(out_b, 0, sizeof(*out_b) * BUF_SIZE);
84 
86 
87  call_ref(&imdct, buf0, &offset0, buf2_0, window,
88  out0, in, scale);
89  call_new(&imdct, buf1, &offset1, buf2_1, window,
90  out1, in, scale);
91 
92  if (offset0 != offset1) {
93  fail();
94  fprintf(stderr, "offsets do not match: %d, %d", offset0, offset1);
95  break;
96  }
97 
98  for (j = 0; j < BUF_SIZE; j++) {
99  if (!float_near_abs_eps_ulp(out0[j], out1[j], 7.0e-7, 16) ||
100  !float_near_abs_eps_ulp(buf2_0[j], buf2_1[j], 7.0e-7, 16)) {
101  union av_intfloat32 o0, o1, b0, b1;
102 
103  fail();
104  o0.f = out0[j]; o1.f = out1[j];
105  b0.f = buf2_0[j], b1.f = buf2_1[j];
106  fprintf(stderr, "out: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
107  o0.f, o0.i, o1.f, o1.i, fabsf(o0.f - o1.f));
108  fprintf(stderr, "buf2: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
109  b0.f, b0.i, b1.f, b1.i, fabsf(b0.f - b1.f));
110  break;
111  }
112  }
113 
114  bench_new(&imdct, buf_b, &offset_b, buf2_b, window,
115  out_b, in, scale);
116  }
117  }
118  ff_mdct_end(&imdct);
119 
120  report("synth_filter");
121 }
av_cold void ff_synth_filter_init(SynthFilterContext *c)
Definition: synth_filter.c:171
const float ff_dca_fir_32bands_nonperfect[512]
Definition: dcadata.c:6804
#define report
Definition: checkasm.h:84
#define BUF_SIZE
Definition: synth_filter.c:33
#define declare_func(ret,...)
Definition: checkasm.h:77
#define ff_mdct_init
Definition: fft.h:169
#define fail()
Definition: checkasm.h:81
common internal API header
Definition: fft.h:88
uint32_t i
Definition: intfloat.h:28
#define call_ref(...)
Definition: checkasm.h:87
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define randomize_input()
Definition: synth_filter.c:35
#define check_func(func,...)
Definition: checkasm.h:73
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
int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
Definition: checkasm.c:248
#define LOCAL_ALIGNED(a, t, v,...)
Definition: internal.h:110
#define ff_mdct_end
Definition: fft.h:170
#define bench_new(...)
Definition: checkasm.h:173
#define call_new(...)
Definition: checkasm.h:142
void checkasm_check_synth_filter(void)
Definition: synth_filter.c:44
const float ff_dca_fir_32bands_perfect[512]
Definition: dcadata.c:6289