audio_convert_init.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * 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 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config.h"
  21. #include "libavutil/cpu.h"
  22. #include "libavutil/x86/cpu.h"
  23. #include "libavresample/audio_convert.h"
  24. /* flat conversions */
  25. void ff_conv_s16_to_s32_sse2(int16_t *dst, const int32_t *src, int len);
  26. void ff_conv_s16_to_flt_sse2(float *dst, const int16_t *src, int len);
  27. void ff_conv_s16_to_flt_sse4(float *dst, const int16_t *src, int len);
  28. void ff_conv_s32_to_s16_mmx (int16_t *dst, const int32_t *src, int len);
  29. void ff_conv_s32_to_s16_sse2(int16_t *dst, const int32_t *src, int len);
  30. void ff_conv_s32_to_flt_sse2(float *dst, const int32_t *src, int len);
  31. void ff_conv_s32_to_flt_avx (float *dst, const int32_t *src, int len);
  32. void ff_conv_flt_to_s16_sse2(int16_t *dst, const float *src, int len);
  33. void ff_conv_flt_to_s32_sse2(int32_t *dst, const float *src, int len);
  34. void ff_conv_flt_to_s32_avx (int32_t *dst, const float *src, int len);
  35. /* interleave conversions */
  36. void ff_conv_s16p_to_s16_2ch_sse2(int16_t *dst, int16_t *const *src,
  37. int len, int channels);
  38. void ff_conv_s16p_to_s16_2ch_avx (int16_t *dst, int16_t *const *src,
  39. int len, int channels);
  40. void ff_conv_s16p_to_s16_6ch_sse2(int16_t *dst, int16_t *const *src,
  41. int len, int channels);
  42. void ff_conv_s16p_to_s16_6ch_sse2slow(int16_t *dst, int16_t *const *src,
  43. int len, int channels);
  44. void ff_conv_s16p_to_s16_6ch_avx (int16_t *dst, int16_t *const *src,
  45. int len, int channels);
  46. void ff_conv_s16p_to_flt_2ch_sse2(float *dst, int16_t *const *src,
  47. int len, int channels);
  48. void ff_conv_s16p_to_flt_2ch_avx (float *dst, int16_t *const *src,
  49. int len, int channels);
  50. void ff_conv_s16p_to_flt_6ch_sse2 (float *dst, int16_t *const *src,
  51. int len, int channels);
  52. void ff_conv_s16p_to_flt_6ch_ssse3(float *dst, int16_t *const *src,
  53. int len, int channels);
  54. void ff_conv_s16p_to_flt_6ch_avx (float *dst, int16_t *const *src,
  55. int len, int channels);
  56. void ff_conv_fltp_to_s16_2ch_sse2 (int16_t *dst, float *const *src,
  57. int len, int channels);
  58. void ff_conv_fltp_to_s16_2ch_ssse3(int16_t *dst, float *const *src,
  59. int len, int channels);
  60. void ff_conv_fltp_to_s16_6ch_sse (int16_t *dst, float *const *src,
  61. int len, int channels);
  62. void ff_conv_fltp_to_s16_6ch_sse2(int16_t *dst, float *const *src,
  63. int len, int channels);
  64. void ff_conv_fltp_to_s16_6ch_avx (int16_t *dst, float *const *src,
  65. int len, int channels);
  66. void ff_conv_fltp_to_flt_2ch_sse(float *dst, float *const *src, int len,
  67. int channels);
  68. void ff_conv_fltp_to_flt_2ch_avx(float *dst, float *const *src, int len,
  69. int channels);
  70. void ff_conv_fltp_to_flt_6ch_mmx (float *dst, float *const *src, int len,
  71. int channels);
  72. void ff_conv_fltp_to_flt_6ch_sse4(float *dst, float *const *src, int len,
  73. int channels);
  74. void ff_conv_fltp_to_flt_6ch_avx (float *dst, float *const *src, int len,
  75. int channels);
  76. /* deinterleave conversions */
  77. void ff_conv_s16_to_s16p_2ch_sse2(int16_t *const *dst, int16_t *src,
  78. int len, int channels);
  79. void ff_conv_s16_to_s16p_2ch_ssse3(int16_t *const *dst, int16_t *src,
  80. int len, int channels);
  81. void ff_conv_s16_to_s16p_2ch_avx (int16_t *const *dst, int16_t *src,
  82. int len, int channels);
  83. void ff_conv_s16_to_s16p_6ch_sse2 (int16_t *const *dst, int16_t *src,
  84. int len, int channels);
  85. void ff_conv_s16_to_s16p_6ch_ssse3(int16_t *const *dst, int16_t *src,
  86. int len, int channels);
  87. void ff_conv_s16_to_s16p_6ch_avx (int16_t *const *dst, int16_t *src,
  88. int len, int channels);
  89. void ff_conv_s16_to_fltp_2ch_sse2(float *const *dst, int16_t *src,
  90. int len, int channels);
  91. void ff_conv_s16_to_fltp_2ch_avx (float *const *dst, int16_t *src,
  92. int len, int channels);
  93. void ff_conv_s16_to_fltp_6ch_sse2 (float *const *dst, int16_t *src,
  94. int len, int channels);
  95. void ff_conv_s16_to_fltp_6ch_ssse3(float *const *dst, int16_t *src,
  96. int len, int channels);
  97. void ff_conv_s16_to_fltp_6ch_sse4 (float *const *dst, int16_t *src,
  98. int len, int channels);
  99. void ff_conv_s16_to_fltp_6ch_avx (float *const *dst, int16_t *src,
  100. int len, int channels);
  101. void ff_conv_flt_to_s16p_2ch_sse2(int16_t *const *dst, float *src,
  102. int len, int channels);
  103. void ff_conv_flt_to_s16p_2ch_avx (int16_t *const *dst, float *src,
  104. int len, int channels);
  105. void ff_conv_flt_to_s16p_6ch_sse2 (int16_t *const *dst, float *src,
  106. int len, int channels);
  107. void ff_conv_flt_to_s16p_6ch_ssse3(int16_t *const *dst, float *src,
  108. int len, int channels);
  109. void ff_conv_flt_to_s16p_6ch_avx (int16_t *const *dst, float *src,
  110. int len, int channels);
  111. void ff_conv_flt_to_fltp_2ch_sse(float *const *dst, float *src, int len,
  112. int channels);
  113. void ff_conv_flt_to_fltp_2ch_avx(float *const *dst, float *src, int len,
  114. int channels);
  115. void ff_conv_flt_to_fltp_6ch_sse2(float *const *dst, float *src, int len,
  116. int channels);
  117. void ff_conv_flt_to_fltp_6ch_avx (float *const *dst, float *src, int len,
  118. int channels);
  119. av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
  120. {
  121. int cpu_flags = av_get_cpu_flags();
  122. if (EXTERNAL_MMX(cpu_flags)) {
  123. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  124. 0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx);
  125. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  126. 6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
  127. }
  128. if (EXTERNAL_SSE(cpu_flags)) {
  129. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  130. 6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse);
  131. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  132. 2, 16, 8, "SSE", ff_conv_fltp_to_flt_2ch_sse);
  133. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
  134. 2, 16, 4, "SSE", ff_conv_flt_to_fltp_2ch_sse);
  135. }
  136. if (EXTERNAL_SSE2(cpu_flags)) {
  137. if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
  138. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  139. 0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2);
  140. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  141. 6, 16, 8, "SSE2", ff_conv_s16p_to_s16_6ch_sse2);
  142. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  143. 6, 16, 4, "SSE2", ff_conv_fltp_to_s16_6ch_sse2);
  144. } else {
  145. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  146. 6, 1, 4, "SSE2SLOW", ff_conv_s16p_to_s16_6ch_sse2slow);
  147. }
  148. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16,
  149. 0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2);
  150. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  151. 0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2);
  152. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  153. 0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2);
  154. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT,
  155. 0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2);
  156. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  157. 0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2);
  158. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  159. 2, 16, 16, "SSE2", ff_conv_s16p_to_s16_2ch_sse2);
  160. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  161. 2, 16, 8, "SSE2", ff_conv_s16p_to_flt_2ch_sse2);
  162. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  163. 6, 16, 4, "SSE2", ff_conv_s16p_to_flt_6ch_sse2);
  164. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  165. 2, 16, 4, "SSE2", ff_conv_fltp_to_s16_2ch_sse2);
  166. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  167. 2, 16, 8, "SSE2", ff_conv_s16_to_s16p_2ch_sse2);
  168. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  169. 6, 16, 4, "SSE2", ff_conv_s16_to_s16p_6ch_sse2);
  170. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  171. 2, 16, 8, "SSE2", ff_conv_s16_to_fltp_2ch_sse2);
  172. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  173. 6, 16, 4, "SSE2", ff_conv_s16_to_fltp_6ch_sse2);
  174. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  175. 2, 16, 8, "SSE2", ff_conv_flt_to_s16p_2ch_sse2);
  176. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  177. 6, 16, 4, "SSE2", ff_conv_flt_to_s16p_6ch_sse2);
  178. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
  179. 6, 16, 4, "SSE2", ff_conv_flt_to_fltp_6ch_sse2);
  180. }
  181. if (EXTERNAL_SSSE3(cpu_flags)) {
  182. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  183. 6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3);
  184. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  185. 2, 16, 4, "SSSE3", ff_conv_fltp_to_s16_2ch_ssse3);
  186. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  187. 2, 16, 8, "SSSE3", ff_conv_s16_to_s16p_2ch_ssse3);
  188. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  189. 6, 16, 4, "SSSE3", ff_conv_s16_to_s16p_6ch_ssse3);
  190. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  191. 6, 16, 4, "SSSE3", ff_conv_s16_to_fltp_6ch_ssse3);
  192. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  193. 6, 16, 4, "SSSE3", ff_conv_flt_to_s16p_6ch_ssse3);
  194. }
  195. if (EXTERNAL_SSE4(cpu_flags)) {
  196. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  197. 0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4);
  198. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  199. 6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
  200. }
  201. if (EXTERNAL_AVX_FAST(cpu_flags)) {
  202. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  203. 0, 32, 16, "AVX", ff_conv_s32_to_flt_avx);
  204. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  205. 0, 32, 32, "AVX", ff_conv_flt_to_s32_avx);
  206. }
  207. if (EXTERNAL_AVX(cpu_flags)) {
  208. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  209. 2, 16, 16, "AVX", ff_conv_s16p_to_s16_2ch_avx);
  210. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  211. 6, 16, 8, "AVX", ff_conv_s16p_to_s16_6ch_avx);
  212. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  213. 2, 16, 8, "AVX", ff_conv_s16p_to_flt_2ch_avx);
  214. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  215. 6, 16, 4, "AVX", ff_conv_s16p_to_flt_6ch_avx);
  216. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  217. 6, 16, 4, "AVX", ff_conv_fltp_to_s16_6ch_avx);
  218. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  219. 6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx);
  220. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  221. 2, 16, 8, "AVX", ff_conv_s16_to_s16p_2ch_avx);
  222. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  223. 6, 16, 4, "AVX", ff_conv_s16_to_s16p_6ch_avx);
  224. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  225. 2, 16, 8, "AVX", ff_conv_s16_to_fltp_2ch_avx);
  226. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  227. 6, 16, 4, "AVX", ff_conv_s16_to_fltp_6ch_avx);
  228. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  229. 2, 16, 8, "AVX", ff_conv_flt_to_s16p_2ch_avx);
  230. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  231. 6, 16, 4, "AVX", ff_conv_flt_to_s16p_6ch_avx);
  232. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
  233. 2, 16, 4, "AVX", ff_conv_flt_to_fltp_2ch_avx);
  234. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
  235. 6, 16, 4, "AVX", ff_conv_flt_to_fltp_6ch_avx);
  236. }
  237. }