FFmpeg
resample_init.c
Go to the documentation of this file.
1 /*
2  * audio resampling
3  * Copyright (c) 2004-2012 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * audio resampling
25  * @author Michael Niedermayer <michaelni@gmx.at>
26  */
27 
28 #include "libavutil/attributes.h"
29 #include "libavutil/x86/cpu.h"
30 #include "libswresample/resample.h"
31 
32 #define RESAMPLE_FUNCS(type, opt) \
33 int ff_resample_common_##type##_##opt(ResampleContext *c, void *dst, \
34  const void *src, int sz, int upd); \
35 int ff_resample_linear_##type##_##opt(ResampleContext *c, void *dst, \
36  const void *src, int sz, int upd)
37 
38 RESAMPLE_FUNCS(int16, mmxext);
39 RESAMPLE_FUNCS(int16, sse2);
40 RESAMPLE_FUNCS(int16, xop);
41 RESAMPLE_FUNCS(float, sse);
42 RESAMPLE_FUNCS(float, avx);
43 RESAMPLE_FUNCS(float, fma3);
44 RESAMPLE_FUNCS(float, fma4);
45 RESAMPLE_FUNCS(double, sse2);
46 RESAMPLE_FUNCS(double, avx);
47 RESAMPLE_FUNCS(double, fma3);
48 
50 {
51  int av_unused mm_flags = av_get_cpu_flags();
52 
53  switch(c->format){
54  case AV_SAMPLE_FMT_S16P:
55  if (ARCH_X86_32 && EXTERNAL_MMXEXT(mm_flags)) {
56  c->dsp.resample_linear = ff_resample_linear_int16_mmxext;
57  c->dsp.resample_common = ff_resample_common_int16_mmxext;
58  }
59  if (EXTERNAL_SSE2(mm_flags)) {
60  c->dsp.resample_linear = ff_resample_linear_int16_sse2;
61  c->dsp.resample_common = ff_resample_common_int16_sse2;
62  }
63  if (EXTERNAL_XOP(mm_flags)) {
64  c->dsp.resample_linear = ff_resample_linear_int16_xop;
65  c->dsp.resample_common = ff_resample_common_int16_xop;
66  }
67  break;
68  case AV_SAMPLE_FMT_FLTP:
69  if (EXTERNAL_SSE(mm_flags)) {
70  c->dsp.resample_linear = ff_resample_linear_float_sse;
71  c->dsp.resample_common = ff_resample_common_float_sse;
72  }
73  if (EXTERNAL_AVX_FAST(mm_flags)) {
74  c->dsp.resample_linear = ff_resample_linear_float_avx;
75  c->dsp.resample_common = ff_resample_common_float_avx;
76  }
77  if (EXTERNAL_FMA3_FAST(mm_flags)) {
78  c->dsp.resample_linear = ff_resample_linear_float_fma3;
79  c->dsp.resample_common = ff_resample_common_float_fma3;
80  }
81  if (EXTERNAL_FMA4(mm_flags)) {
82  c->dsp.resample_linear = ff_resample_linear_float_fma4;
83  c->dsp.resample_common = ff_resample_common_float_fma4;
84  }
85  break;
86  case AV_SAMPLE_FMT_DBLP:
87  if (EXTERNAL_SSE2(mm_flags)) {
88  c->dsp.resample_linear = ff_resample_linear_double_sse2;
89  c->dsp.resample_common = ff_resample_common_double_sse2;
90  }
91  if (EXTERNAL_AVX_FAST(mm_flags)) {
92  c->dsp.resample_linear = ff_resample_linear_double_avx;
93  c->dsp.resample_common = ff_resample_common_double_avx;
94  }
95  if (EXTERNAL_FMA3_FAST(mm_flags)) {
96  c->dsp.resample_linear = ff_resample_linear_double_fma3;
97  c->dsp.resample_common = ff_resample_common_double_fma3;
98  }
99  break;
100  }
101 }
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
cpu.h
av_unused
#define av_unused
Definition: attributes.h:131
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:98
av_cold
#define av_cold
Definition: attributes.h:90
ResampleContext
Definition: resample.h:30
EXTERNAL_SSE
#define EXTERNAL_SSE(flags)
Definition: cpu.h:58
sse
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
Definition: mpegvideo_enc.c:2571
EXTERNAL_AVX_FAST
#define EXTERNAL_AVX_FAST(flags)
Definition: cpu.h:71
EXTERNAL_FMA4
#define EXTERNAL_FMA4(flags)
Definition: cpu.h:77
RESAMPLE_FUNCS
#define RESAMPLE_FUNCS(type, opt)
Definition: resample_init.c:32
EXTERNAL_XOP
#define EXTERNAL_XOP(flags)
Definition: cpu.h:73
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
EXTERNAL_FMA3_FAST
#define EXTERNAL_FMA3_FAST(flags)
Definition: cpu.h:75
resample.h
swri_resample_dsp_x86_init
av_cold void swri_resample_dsp_x86_init(ResampleContext *c)
Definition: resample_init.c:49
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
EXTERNAL_MMXEXT
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:57