2 * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at)
4 * This file is part of libswresample
6 * libswresample is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * libswresample 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with libswresample; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libswresample/swresample_internal.h"
22 #include "libswresample/audioconvert.h"
24 #define PROTO(pre, in, out, cap) void ff ## pre ## _ ##in## _to_ ##out## _a_ ##cap(uint8_t **dst, const uint8_t **src, int len);
25 #define PROTO2(pre, out, cap) PROTO(pre, int16, out, cap) PROTO(pre, int32, out, cap) PROTO(pre, float, out, cap)
26 #define PROTO3(pre, cap) PROTO2(pre, int16, cap) PROTO2(pre, int32, cap) PROTO2(pre, float, cap)
27 #define PROTO4(pre) PROTO3(pre, mmx) PROTO3(pre, sse) PROTO3(pre, sse2) PROTO3(pre, ssse3) PROTO3(pre, sse4) PROTO3(pre, avx)
33 void swri_audio_convert_init_x86(struct AudioConvert *ac,
34 enum AVSampleFormat out_fmt,
35 enum AVSampleFormat in_fmt,
37 int mm_flags = av_get_cpu_flags();
41 //FIXME add memcpy case
43 #define MULTI_CAPS_FUNC(flag, cap) \
44 if (mm_flags & flag) {\
45 if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16P)\
46 ac->simd_f = ff_int16_to_int32_a_ ## cap;\
47 if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32P)\
48 ac->simd_f = ff_int32_to_int16_a_ ## cap;\
51 MULTI_CAPS_FUNC(AV_CPU_FLAG_MMX, mmx)
52 MULTI_CAPS_FUNC(AV_CPU_FLAG_SSE, sse)
54 if(mm_flags & AV_CPU_FLAG_MMX) {
56 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
57 ac->simd_f = ff_pack_6ch_float_to_float_a_mmx;
61 if(mm_flags & AV_CPU_FLAG_SSE) {
63 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
64 ac->simd_f = ff_pack_2ch_int32_to_int32_a_sse;
65 if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S16P)
66 ac->simd_f = ff_pack_2ch_int16_to_int16_a_sse;
67 if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16P)
68 ac->simd_f = ff_pack_2ch_int16_to_int32_a_sse;
69 if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32P)
70 ac->simd_f = ff_pack_2ch_int32_to_int16_a_sse;
72 if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32)
73 ac->simd_f = ff_unpack_2ch_int32_to_int32_a_sse;
74 if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16)
75 ac->simd_f = ff_unpack_2ch_int16_to_int16_a_sse;
76 if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16)
77 ac->simd_f = ff_unpack_2ch_int16_to_int32_a_sse;
78 if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32)
79 ac->simd_f = ff_unpack_2ch_int32_to_int16_a_sse;
83 if(mm_flags & AV_CPU_FLAG_SSE2) {
84 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P)
85 ac->simd_f = ff_int32_to_float_a_sse2;
86 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16P)
87 ac->simd_f = ff_int16_to_float_a_sse2;
88 if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP)
89 ac->simd_f = ff_float_to_int32_a_sse2;
90 if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLTP)
91 ac->simd_f = ff_float_to_int16_a_sse2;
94 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
95 ac->simd_f = ff_pack_2ch_int32_to_float_a_sse2;
96 if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
97 ac->simd_f = ff_pack_2ch_float_to_int32_a_sse2;
98 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16P)
99 ac->simd_f = ff_pack_2ch_int16_to_float_a_sse2;
100 if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP)
101 ac->simd_f = ff_pack_2ch_float_to_int16_a_sse2;
102 if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
103 ac->simd_f = ff_unpack_2ch_int32_to_float_a_sse2;
104 if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
105 ac->simd_f = ff_unpack_2ch_float_to_int32_a_sse2;
106 if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16)
107 ac->simd_f = ff_unpack_2ch_int16_to_float_a_sse2;
108 if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLT)
109 ac->simd_f = ff_unpack_2ch_float_to_int16_a_sse2;
112 if(mm_flags & AV_CPU_FLAG_SSSE3) {
114 if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16)
115 ac->simd_f = ff_unpack_2ch_int16_to_int16_a_ssse3;
116 if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16)
117 ac->simd_f = ff_unpack_2ch_int16_to_int32_a_ssse3;
118 if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16)
119 ac->simd_f = ff_unpack_2ch_int16_to_float_a_ssse3;
122 if(mm_flags & AV_CPU_FLAG_SSE4) {
124 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
125 ac->simd_f = ff_pack_6ch_float_to_float_a_sse4;
126 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
127 ac->simd_f = ff_pack_6ch_int32_to_float_a_sse4;
128 if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
129 ac->simd_f = ff_pack_6ch_float_to_int32_a_sse4;
132 if(HAVE_AVX && mm_flags & AV_CPU_FLAG_AVX) {
133 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P)
134 ac->simd_f = ff_int32_to_float_a_avx;
136 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
137 ac->simd_f = ff_pack_6ch_float_to_float_a_avx;
138 if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
139 ac->simd_f = ff_pack_6ch_int32_to_float_a_avx;
140 if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
141 ac->simd_f = ff_pack_6ch_float_to_int32_a_avx;