audio_convert_init.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * This file is part of libswresample
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #include "libavutil/x86/cpu.h"
  21. #include "libswresample/swresample_internal.h"
  22. #include "libswresample/audioconvert.h"
  23. #define PROTO(pre, in, out, cap) void ff ## pre ## in## _to_ ##out## _a_ ##cap(uint8_t **dst, const uint8_t **src, int len);
  24. #define PROTO2(pre, out, cap) PROTO(pre, int16, out, cap) PROTO(pre, int32, out, cap) PROTO(pre, float, out, cap)
  25. #define PROTO3(pre, cap) PROTO2(pre, int16, cap) PROTO2(pre, int32, cap) PROTO2(pre, float, cap)
  26. #define PROTO4(pre) PROTO3(pre, mmx) PROTO3(pre, sse) PROTO3(pre, sse2) PROTO3(pre, ssse3) PROTO3(pre, sse4) PROTO3(pre, avx) PROTO3(pre, avx2)
  27. PROTO4(_)
  28. PROTO4(_pack_2ch_)
  29. PROTO4(_pack_6ch_)
  30. PROTO4(_pack_8ch_)
  31. PROTO4(_unpack_2ch_)
  32. PROTO4(_unpack_6ch_)
  33. av_cold void swri_audio_convert_init_x86(struct AudioConvert *ac,
  34. enum AVSampleFormat out_fmt,
  35. enum AVSampleFormat in_fmt,
  36. int channels){
  37. int mm_flags = av_get_cpu_flags();
  38. ac->simd_f= NULL;
  39. //FIXME add memcpy case
  40. #define MULTI_CAPS_FUNC(flag, cap) \
  41. if (EXTERNAL_##flag(mm_flags)) {\
  42. 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)\
  43. ac->simd_f = ff_int16_to_int32_a_ ## cap;\
  44. 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)\
  45. ac->simd_f = ff_int32_to_int16_a_ ## cap;\
  46. }
  47. MULTI_CAPS_FUNC(MMX, mmx)
  48. MULTI_CAPS_FUNC(SSE2, sse2)
  49. if(EXTERNAL_MMX(mm_flags)) {
  50. if(channels == 6) {
  51. 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)
  52. ac->simd_f = ff_pack_6ch_float_to_float_a_mmx;
  53. }
  54. }
  55. if(EXTERNAL_SSE(mm_flags)) {
  56. if(channels == 6) {
  57. 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)
  58. ac->simd_f = ff_pack_6ch_float_to_float_a_sse;
  59. 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)
  60. ac->simd_f = ff_unpack_6ch_float_to_float_a_sse;
  61. }
  62. }
  63. if(EXTERNAL_SSE2(mm_flags)) {
  64. 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)
  65. ac->simd_f = ff_int32_to_float_a_sse2;
  66. 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)
  67. ac->simd_f = ff_int16_to_float_a_sse2;
  68. 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)
  69. ac->simd_f = ff_float_to_int32_a_sse2;
  70. 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)
  71. ac->simd_f = ff_float_to_int16_a_sse2;
  72. if(channels == 2) {
  73. 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)
  74. ac->simd_f = ff_pack_2ch_int32_to_int32_a_sse2;
  75. if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S16P)
  76. ac->simd_f = ff_pack_2ch_int16_to_int16_a_sse2;
  77. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16P)
  78. ac->simd_f = ff_pack_2ch_int16_to_int32_a_sse2;
  79. if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32P)
  80. ac->simd_f = ff_pack_2ch_int32_to_int16_a_sse2;
  81. 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)
  82. ac->simd_f = ff_unpack_2ch_int32_to_int32_a_sse2;
  83. if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16)
  84. ac->simd_f = ff_unpack_2ch_int16_to_int16_a_sse2;
  85. if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16)
  86. ac->simd_f = ff_unpack_2ch_int16_to_int32_a_sse2;
  87. if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32)
  88. ac->simd_f = ff_unpack_2ch_int32_to_int16_a_sse2;
  89. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
  90. ac->simd_f = ff_pack_2ch_int32_to_float_a_sse2;
  91. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
  92. ac->simd_f = ff_pack_2ch_float_to_int32_a_sse2;
  93. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16P)
  94. ac->simd_f = ff_pack_2ch_int16_to_float_a_sse2;
  95. if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP)
  96. ac->simd_f = ff_pack_2ch_float_to_int16_a_sse2;
  97. if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
  98. ac->simd_f = ff_unpack_2ch_int32_to_float_a_sse2;
  99. if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
  100. ac->simd_f = ff_unpack_2ch_float_to_int32_a_sse2;
  101. if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16)
  102. ac->simd_f = ff_unpack_2ch_int16_to_float_a_sse2;
  103. if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLT)
  104. ac->simd_f = ff_unpack_2ch_float_to_int16_a_sse2;
  105. }
  106. if(channels == 6) {
  107. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
  108. ac->simd_f = ff_pack_6ch_int32_to_float_a_sse2;
  109. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
  110. ac->simd_f = ff_pack_6ch_float_to_int32_a_sse2;
  111. if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
  112. ac->simd_f = ff_unpack_6ch_int32_to_float_a_sse2;
  113. if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
  114. ac->simd_f = ff_unpack_6ch_float_to_int32_a_sse2;
  115. }
  116. if(channels == 8) {
  117. 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)
  118. ac->simd_f = ff_pack_8ch_float_to_float_a_sse2;
  119. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
  120. ac->simd_f = ff_pack_8ch_int32_to_float_a_sse2;
  121. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
  122. ac->simd_f = ff_pack_8ch_float_to_int32_a_sse2;
  123. }
  124. }
  125. if(EXTERNAL_SSSE3(mm_flags)) {
  126. if(channels == 2) {
  127. if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16)
  128. ac->simd_f = ff_unpack_2ch_int16_to_int16_a_ssse3;
  129. if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16)
  130. ac->simd_f = ff_unpack_2ch_int16_to_int32_a_ssse3;
  131. if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16)
  132. ac->simd_f = ff_unpack_2ch_int16_to_float_a_ssse3;
  133. }
  134. }
  135. if(EXTERNAL_AVX_FAST(mm_flags)) {
  136. 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)
  137. ac->simd_f = ff_int32_to_float_a_avx;
  138. }
  139. if(EXTERNAL_AVX(mm_flags)) {
  140. if(channels == 6) {
  141. 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)
  142. ac->simd_f = ff_pack_6ch_float_to_float_a_avx;
  143. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
  144. ac->simd_f = ff_pack_6ch_int32_to_float_a_avx;
  145. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
  146. ac->simd_f = ff_pack_6ch_float_to_int32_a_avx;
  147. 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)
  148. ac->simd_f = ff_unpack_6ch_float_to_float_a_avx;
  149. if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32)
  150. ac->simd_f = ff_unpack_6ch_int32_to_float_a_avx;
  151. if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT)
  152. ac->simd_f = ff_unpack_6ch_float_to_int32_a_avx;
  153. }
  154. if(channels == 8) {
  155. 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)
  156. ac->simd_f = ff_pack_8ch_float_to_float_a_avx;
  157. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
  158. ac->simd_f = ff_pack_8ch_int32_to_float_a_avx;
  159. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
  160. ac->simd_f = ff_pack_8ch_float_to_int32_a_avx;
  161. }
  162. }
  163. if(EXTERNAL_AVX2_FAST(mm_flags)) {
  164. 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)
  165. ac->simd_f = ff_float_to_int32_a_avx2;
  166. }
  167. }