audio_convert_init.c 14.9 KB
Newer Older
Justin Ruggles's avatar
Justin Ruggles committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
 *
 * This file is part of Libav.
 *
 * Libav is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Libav is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Libav; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "config.h"
#include "libavutil/cpu.h"
#include "libavresample/audio_convert.h"

25 26
/* flat conversions */

27 28
extern void ff_conv_s16_to_s32_sse2(int16_t *dst, const int32_t *src, int len);

29 30 31
extern void ff_conv_s16_to_flt_sse2(float *dst, const int16_t *src, int len);
extern void ff_conv_s16_to_flt_sse4(float *dst, const int16_t *src, int len);

32 33 34
extern void ff_conv_s32_to_s16_mmx (int16_t *dst, const int32_t *src, int len);
extern void ff_conv_s32_to_s16_sse2(int16_t *dst, const int32_t *src, int len);

35 36 37
extern void ff_conv_s32_to_flt_sse2(float *dst, const int32_t *src, int len);
extern void ff_conv_s32_to_flt_avx (float *dst, const int32_t *src, int len);

38 39
extern void ff_conv_flt_to_s16_sse2(int16_t *dst, const float *src, int len);

40 41 42
extern void ff_conv_flt_to_s32_sse2(int32_t *dst, const float *src, int len);
extern void ff_conv_flt_to_s32_avx (int32_t *dst, const float *src, int len);

43 44 45 46 47 48 49
/* interleave conversions */

extern void ff_conv_s16p_to_s16_2ch_sse2(int16_t *dst, int16_t *const *src,
                                         int len, int channels);
extern void ff_conv_s16p_to_s16_2ch_avx (int16_t *dst, int16_t *const *src,
                                         int len, int channels);

50 51 52 53 54 55 56
extern void ff_conv_s16p_to_s16_6ch_sse2(int16_t *dst, int16_t *const *src,
                                         int len, int channels);
extern void ff_conv_s16p_to_s16_6ch_sse2slow(int16_t *dst, int16_t *const *src,
                                             int len, int channels);
extern void ff_conv_s16p_to_s16_6ch_avx (int16_t *dst, int16_t *const *src,
                                         int len, int channels);

57 58 59 60 61
extern void ff_conv_s16p_to_flt_2ch_sse2(float *dst, int16_t *const *src,
                                         int len, int channels);
extern void ff_conv_s16p_to_flt_2ch_avx (float *dst, int16_t *const *src,
                                         int len, int channels);

62 63 64 65 66 67 68
extern void ff_conv_s16p_to_flt_6ch_sse2 (float *dst, int16_t *const *src,
                                          int len, int channels);
extern void ff_conv_s16p_to_flt_6ch_ssse3(float *dst, int16_t *const *src,
                                         int len, int channels);
extern void ff_conv_s16p_to_flt_6ch_avx  (float *dst, int16_t *const *src,
                                          int len, int channels);

69 70 71 72 73
extern void ff_conv_fltp_to_s16_2ch_sse2 (int16_t *dst, float *const *src,
                                          int len, int channels);
extern void ff_conv_fltp_to_s16_2ch_ssse3(int16_t *dst, float *const *src,
                                          int len, int channels);

74 75 76 77 78 79 80
extern void ff_conv_fltp_to_s16_6ch_sse (int16_t *dst, float *const *src,
                                         int len, int channels);
extern void ff_conv_fltp_to_s16_6ch_sse2(int16_t *dst, float *const *src,
                                         int len, int channels);
extern void ff_conv_fltp_to_s16_6ch_avx (int16_t *dst, float *const *src,
                                         int len, int channels);

81 82 83 84 85
extern void ff_conv_fltp_to_flt_2ch_sse(float *dst, float *const *src, int len,
                                        int channels);
extern void ff_conv_fltp_to_flt_2ch_avx(float *dst, float *const *src, int len,
                                        int channels);

86 87 88 89 90 91
extern void ff_conv_fltp_to_flt_6ch_mmx (float *dst, float *const *src, int len,
                                         int channels);
extern void ff_conv_fltp_to_flt_6ch_sse4(float *dst, float *const *src, int len,
                                         int channels);
extern void ff_conv_fltp_to_flt_6ch_avx (float *dst, float *const *src, int len,
                                         int channels);
Justin Ruggles's avatar
Justin Ruggles committed
92

93 94 95 96 97 98 99 100 101
/* deinterleave conversions */

extern void ff_conv_s16_to_s16p_2ch_sse2(int16_t *const *dst, int16_t *src,
                                         int len, int channels);
extern void ff_conv_s16_to_s16p_2ch_ssse3(int16_t *const *dst, int16_t *src,
                                          int len, int channels);
extern void ff_conv_s16_to_s16p_2ch_avx (int16_t *const *dst, int16_t *src,
                                         int len, int channels);

102 103 104 105 106 107 108
extern void ff_conv_s16_to_s16p_6ch_sse2 (int16_t *const *dst, int16_t *src,
                                          int len, int channels);
extern void ff_conv_s16_to_s16p_6ch_ssse3(int16_t *const *dst, int16_t *src,
                                          int len, int channels);
extern void ff_conv_s16_to_s16p_6ch_avx  (int16_t *const *dst, int16_t *src,
                                          int len, int channels);

109 110 111 112 113
extern void ff_conv_s16_to_fltp_2ch_sse2(float *const *dst, int16_t *src,
                                         int len, int channels);
extern void ff_conv_s16_to_fltp_2ch_avx (float *const *dst, int16_t *src,
                                         int len, int channels);

114 115 116 117 118 119 120 121 122
extern void ff_conv_s16_to_fltp_6ch_sse2 (float *const *dst, int16_t *src,
                                          int len, int channels);
extern void ff_conv_s16_to_fltp_6ch_ssse3(float *const *dst, int16_t *src,
                                          int len, int channels);
extern void ff_conv_s16_to_fltp_6ch_sse4 (float *const *dst, int16_t *src,
                                          int len, int channels);
extern void ff_conv_s16_to_fltp_6ch_avx  (float *const *dst, int16_t *src,
                                          int len, int channels);

123 124 125 126 127
extern void ff_conv_flt_to_s16p_2ch_sse2(int16_t *const *dst, float *src,
                                         int len, int channels);
extern void ff_conv_flt_to_s16p_2ch_avx (int16_t *const *dst, float *src,
                                         int len, int channels);

128 129 130 131 132 133 134
extern void ff_conv_flt_to_s16p_6ch_sse2 (int16_t *const *dst, float *src,
                                          int len, int channels);
extern void ff_conv_flt_to_s16p_6ch_ssse3(int16_t *const *dst, float *src,
                                          int len, int channels);
extern void ff_conv_flt_to_s16p_6ch_avx  (int16_t *const *dst, float *src,
                                          int len, int channels);

135 136 137 138 139
extern void ff_conv_flt_to_fltp_2ch_sse(float *const *dst, float *src, int len,
                                        int channels);
extern void ff_conv_flt_to_fltp_2ch_avx(float *const *dst, float *src, int len,
                                        int channels);

Justin Ruggles's avatar
Justin Ruggles committed
140 141 142 143 144 145
av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
{
#if HAVE_YASM
    int mm_flags = av_get_cpu_flags();

    if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) {
146 147
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
                                  0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx);
Justin Ruggles's avatar
Justin Ruggles committed
148 149 150
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
                                  6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
    }
151 152 153
    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
                                  6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse);
154 155
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
                                  2, 16, 8, "SSE", ff_conv_fltp_to_flt_2ch_sse);
156 157
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
                                  2, 16, 4, "SSE", ff_conv_flt_to_fltp_2ch_sse);
158
    }
159
    if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
160 161 162
        if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
            ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
                                      0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2);
163 164
            ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
                                      6, 16, 8, "SSE2", ff_conv_s16p_to_s16_6ch_sse2);
165 166
            ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
                                      6, 16, 4, "SSE2", ff_conv_fltp_to_s16_6ch_sse2);
167 168 169
        } else {
            ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
                                      6, 1, 4, "SSE2SLOW", ff_conv_s16p_to_s16_6ch_sse2slow);
170
        }
171 172
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16,
                                  0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2);
173 174
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
                                  0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2);
175 176
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
                                  0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2);
177 178
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT,
                                  0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2);
179 180
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
                                  0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2);
181 182
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
                                  2, 16, 16, "SSE2", ff_conv_s16p_to_s16_2ch_sse2);
183 184
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
                                  2, 16, 8, "SSE2", ff_conv_s16p_to_flt_2ch_sse2);
185 186
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
                                  6, 16, 4, "SSE2", ff_conv_s16p_to_flt_6ch_sse2);
187 188
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
                                  2, 16, 4, "SSE2", ff_conv_fltp_to_s16_2ch_sse2);
189 190
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
                                  2, 16, 8, "SSE2", ff_conv_s16_to_s16p_2ch_sse2);
191 192
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
                                  6, 16, 4, "SSE2", ff_conv_s16_to_s16p_6ch_sse2);
193 194
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
                                  2, 16, 8, "SSE2", ff_conv_s16_to_fltp_2ch_sse2);
195 196
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
                                  6, 16, 4, "SSE2", ff_conv_s16_to_fltp_6ch_sse2);
197 198
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
                                  2, 16, 8, "SSE2", ff_conv_flt_to_s16p_2ch_sse2);
199 200
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
                                  6, 16, 4, "SSE2", ff_conv_flt_to_s16p_6ch_sse2);
201 202 203 204
    }
    if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSE) {
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
                                  6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3);
205 206
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
                                  2, 16, 4, "SSSE3", ff_conv_fltp_to_s16_2ch_ssse3);
207 208
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
                                  2, 16, 8, "SSSE3", ff_conv_s16_to_s16p_2ch_ssse3);
209 210
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
                                  6, 16, 4, "SSSE3", ff_conv_s16_to_s16p_6ch_ssse3);
211 212
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
                                  6, 16, 4, "SSSE3", ff_conv_s16_to_fltp_6ch_ssse3);
213 214
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
                                  6, 16, 4, "SSSE3", ff_conv_flt_to_s16p_6ch_ssse3);
215 216 217 218
    }
    if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
                                  0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4);
219 220
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
                                  6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
221
    }
222 223 224
    if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
                                  0, 32, 16, "AVX", ff_conv_s32_to_flt_avx);
225 226
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
                                  0, 32, 32, "AVX", ff_conv_flt_to_s32_avx);
227 228
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
                                  2, 16, 16, "AVX", ff_conv_s16p_to_s16_2ch_avx);
229 230
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
                                  6, 16, 8, "AVX", ff_conv_s16p_to_s16_6ch_avx);
231 232
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
                                  2, 16, 8, "AVX", ff_conv_s16p_to_flt_2ch_avx);
233 234
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
                                  6, 16, 4, "AVX", ff_conv_s16p_to_flt_6ch_avx);
235 236
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
                                  6, 16, 4, "AVX", ff_conv_fltp_to_s16_6ch_avx);
237 238
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
                                  6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx);
239 240
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
                                  2, 16, 8, "AVX", ff_conv_s16_to_s16p_2ch_avx);
241 242
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
                                  6, 16, 4, "AVX", ff_conv_s16_to_s16p_6ch_avx);
243 244
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
                                  2, 16, 8, "AVX", ff_conv_s16_to_fltp_2ch_avx);
245 246
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
                                  6, 16, 4, "AVX", ff_conv_s16_to_fltp_6ch_avx);
247 248
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
                                  2, 16, 8, "AVX", ff_conv_flt_to_s16p_2ch_avx);
249 250
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
                                  6, 16, 4, "AVX", ff_conv_flt_to_s16p_6ch_avx);
251 252
        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
                                  2, 16, 4, "AVX", ff_conv_flt_to_fltp_2ch_avx);
253
    }
Justin Ruggles's avatar
Justin Ruggles committed
254 255
#endif
}