FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fmtconvert.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 <stdint.h>
23 #include <string.h>
24 
25 #include "libavutil/internal.h"
26 #include "libavutil/common.h"
27 #include "libavcodec/fmtconvert.h"
28 
29 #include "checkasm.h"
30 
31 #define BUF_SIZE 1024
32 
33 #define randomize_input(len) \
34  do { \
35  int k; \
36  for (k = 0; k < len; k++) { \
37  in[k] = rnd() - INT32_MAX; \
38  } \
39  for ( ; k < BUF_SIZE; k++) { \
40  in[k] = INT32_MAX; \
41  } \
42  } while (0)
43 
45 {
47  LOCAL_ALIGNED(32, float, dst0, [BUF_SIZE]);
48  LOCAL_ALIGNED(32, float, dst1, [BUF_SIZE]);
50  float scale_arr[128];
51  int length[] = {8, 16, 24, 56, 72, 128, 512, 520, 656, 768, 992};
52  int i, j;
53 
54  for (i = 0; i < FF_ARRAY_ELEMS(scale_arr); i++)
55  scale_arr[i] = (FF_ARRAY_ELEMS(scale_arr) - FF_ARRAY_ELEMS(scale_arr) / 2) / 13;
56 
58 
59  memset(dst0, 0, sizeof(*dst0) * BUF_SIZE);
60  memset(dst1, 0, sizeof(*dst1) * BUF_SIZE);
61 
62  if (check_func(c.int32_to_float_fmul_scalar, "int32_to_float_fmul_scalar")) {
63  declare_func(void, float *, const int32_t *, float, int);
64 
65  for (i = 0; i < FF_ARRAY_ELEMS(scale_arr); i++) {
66  for (j = 0; j < FF_ARRAY_ELEMS(length); j++) {
67 
68  randomize_input(length[j]);
69 
70  call_ref(dst0, in, scale_arr[i], length[j]);
71  call_new(dst1, in, scale_arr[i], length[j]);
72 
73  if (!float_near_ulp_array(dst0, dst1, 3, length[j])) {
74  fail();
75  break;
76  }
77 
78  bench_new(dst1, in, scale_arr[i], length[j]);
79  }
80  }
81  }
82  if (check_func(c.int32_to_float_fmul_array8, "int32_to_float_fmul_array8")) {
83  declare_func(void, FmtConvertContext *, float *, const int32_t *,
84  const float *, int);
85 
86  for (i = 0; i < 4; i++) {
87  for (j = 0; j < FF_ARRAY_ELEMS(length); j++) {
88 
89  randomize_input(length[j]);
90 
91  call_ref(&c, dst0, in, scale_arr, length[j]);
92  call_new(&c, dst1, in, scale_arr, length[j]);
93 
94  if (!float_near_ulp_array(dst0, dst1, 3, length[j])) {
95  fail();
96  fprintf(stderr, "int32_to_float_fmul_array8: len: %d\n", length[j]);
97  break;
98  }
99 
100  bench_new(&c, dst1, in, scale_arr, length[j]);
101  }
102  }
103  }
104  report("fmtconvert");
105 }
#define NULL
Definition: coverity.c:32
#define randomize_input(len)
Definition: fmtconvert.c:33
void checkasm_check_fmtconvert(void)
Definition: fmtconvert.c:44
#define report
Definition: checkasm.h:119
void(* int32_to_float_fmul_array8)(struct FmtConvertContext *c, float *dst, const int32_t *src, const float *mul, int len)
Convert an array of int32_t to float and multiply by a float value from another array, stepping along the float array once for each 8 integers.
Definition: fmtconvert.h:63
#define declare_func(ret,...)
Definition: checkasm.h:111
GLsizei GLsizei * length
Definition: opengl_enc.c:115
#define fail()
Definition: checkasm.h:116
#define BUF_SIZE
Definition: fmtconvert.c:31
common internal API header
int32_t
void(* int32_to_float_fmul_scalar)(float *dst, const int32_t *src, float mul, int len)
Convert an array of int32_t to float and multiply by a float value.
Definition: fmtconvert.h:38
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
Definition: fmtconvert.c:52
#define FF_ARRAY_ELEMS(a)
int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp, unsigned len)
Definition: checkasm.c:282
#define call_ref(...)
Definition: checkasm.h:122
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 check_func(func,...)
Definition: checkasm.h:107
common internal and external API header
#define LOCAL_ALIGNED(a, t, v,...)
Definition: internal.h:114
static double c[64]
#define bench_new(...)
Definition: checkasm.h:249
#define call_new(...)
Definition: checkasm.h:189