You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
5.4KB

  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 "libswresample/swresample_internal.h"
  21. #include "libswresample/audioconvert.h"
  22. #define MULTI_CAPS_FUNC_DECL(cap) \
  23. void ff_int16_to_int32_a_ ## cap(uint8_t **dst, const uint8_t **src, int len);\
  24. void ff_int32_to_int16_a_ ## cap(uint8_t **dst, const uint8_t **src, int len);\
  25. MULTI_CAPS_FUNC_DECL(mmx)
  26. MULTI_CAPS_FUNC_DECL(sse)
  27. void ff_int32_to_float_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  28. void ff_int16_to_float_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  29. void ff_float_to_int32_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  30. void ff_float_to_int16_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  31. void ff_int32_to_float_a_avx(uint8_t **dst, const uint8_t **src, int len);
  32. void ff_pack_2ch_int16_to_int16_a_sse(uint8_t **dst, const uint8_t **src, int len);
  33. void ff_pack_2ch_int32_to_int32_a_sse(uint8_t **dst, const uint8_t **src, int len);
  34. void ff_pack_2ch_int16_to_int32_a_sse(uint8_t **dst, const uint8_t **src, int len);
  35. void ff_pack_2ch_int32_to_int16_a_sse(uint8_t **dst, const uint8_t **src, int len);
  36. void ff_pack_2ch_int32_to_float_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  37. void ff_pack_2ch_float_to_int32_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  38. void ff_pack_2ch_int16_to_float_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  39. void ff_pack_2ch_float_to_int16_a_sse2(uint8_t **dst, const uint8_t **src, int len);
  40. void swri_audio_convert_init_x86(struct AudioConvert *ac,
  41. enum AVSampleFormat out_fmt,
  42. enum AVSampleFormat in_fmt,
  43. int channels){
  44. int mm_flags = av_get_cpu_flags();
  45. ac->simd_f= NULL;
  46. //FIXME add memcpy case
  47. #define MULTI_CAPS_FUNC(flag, cap) \
  48. if (mm_flags & flag) {\
  49. 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)\
  50. ac->simd_f = ff_int16_to_int32_a_ ## cap;\
  51. 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)\
  52. ac->simd_f = ff_int32_to_int16_a_ ## cap;\
  53. }
  54. MULTI_CAPS_FUNC(AV_CPU_FLAG_MMX, mmx)
  55. MULTI_CAPS_FUNC(AV_CPU_FLAG_SSE, sse)
  56. if(mm_flags & AV_CPU_FLAG_SSE) {
  57. if(channels == 2) {
  58. 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)
  59. ac->simd_f = ff_pack_2ch_int32_to_int32_a_sse;
  60. if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S16P)
  61. ac->simd_f = ff_pack_2ch_int16_to_int16_a_sse;
  62. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16P)
  63. ac->simd_f = ff_pack_2ch_int16_to_int32_a_sse;
  64. if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32P)
  65. ac->simd_f = ff_pack_2ch_int32_to_int16_a_sse;
  66. }
  67. }
  68. if(mm_flags & AV_CPU_FLAG_SSE2) {
  69. 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)
  70. ac->simd_f = ff_int32_to_float_a_sse2;
  71. 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)
  72. ac->simd_f = ff_int16_to_float_a_sse2;
  73. 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)
  74. ac->simd_f = ff_float_to_int32_a_sse2;
  75. 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)
  76. ac->simd_f = ff_float_to_int16_a_sse2;
  77. if(channels == 2) {
  78. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P)
  79. ac->simd_f = ff_pack_2ch_int32_to_float_a_sse2;
  80. if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP)
  81. ac->simd_f = ff_pack_2ch_float_to_int32_a_sse2;
  82. if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16P)
  83. ac->simd_f = ff_pack_2ch_int16_to_float_a_sse2;
  84. if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP)
  85. ac->simd_f = ff_pack_2ch_float_to_int16_a_sse2;
  86. }
  87. }
  88. if(HAVE_AVX && mm_flags & AV_CPU_FLAG_AVX) {
  89. 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)
  90. ac->simd_f = ff_int32_to_float_a_avx;
  91. }
  92. }