audio_convert_init.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * This file is part of libswresample.
  3. *
  4. * libswresample is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * libswresample is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with libswresample; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include "config.h"
  20. #include "libavutil/attributes.h"
  21. #include "libavutil/cpu.h"
  22. #include "libavutil/arm/cpu.h"
  23. #include "libavutil/samplefmt.h"
  24. #include "libswresample/swresample_internal.h"
  25. #include "libswresample/audioconvert.h"
  26. void swri_oldapi_conv_flt_to_s16_neon(int16_t *dst, const float *src, int len);
  27. void swri_oldapi_conv_fltp_to_s16_2ch_neon(int16_t *dst, float *const *src, int len, int channels);
  28. void swri_oldapi_conv_fltp_to_s16_nch_neon(int16_t *dst, float *const *src, int len, int channels);
  29. static void conv_flt_to_s16_neon(uint8_t **dst, const uint8_t **src, int len){
  30. swri_oldapi_conv_flt_to_s16_neon((int16_t*)*dst, (const float*)*src, len);
  31. }
  32. static void conv_fltp_to_s16_2ch_neon(uint8_t **dst, const uint8_t **src, int len){
  33. swri_oldapi_conv_fltp_to_s16_2ch_neon((int16_t*)*dst, (float *const*)src, len, 2);
  34. }
  35. static void conv_fltp_to_s16_nch_neon(uint8_t **dst, const uint8_t **src, int len){
  36. int channels;
  37. for(channels=3; channels<SWR_CH_MAX && src[channels]; channels++)
  38. ;
  39. swri_oldapi_conv_fltp_to_s16_nch_neon((int16_t*)*dst, (float *const*)src, len, channels);
  40. }
  41. av_cold void swri_audio_convert_init_arm(struct AudioConvert *ac,
  42. enum AVSampleFormat out_fmt,
  43. enum AVSampleFormat in_fmt,
  44. int channels)
  45. {
  46. int cpu_flags = av_get_cpu_flags();
  47. ac->simd_f= NULL;
  48. if (have_neon(cpu_flags)) {
  49. 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)
  50. ac->simd_f = conv_flt_to_s16_neon;
  51. if(out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP && channels == 2)
  52. ac->simd_f = conv_fltp_to_s16_2ch_neon;
  53. if(out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP && channels > 2)
  54. ac->simd_f = conv_fltp_to_s16_nch_neon;
  55. if(ac->simd_f)
  56. ac->in_simd_align_mask = ac->out_simd_align_mask = 15;
  57. }
  58. }