rematrix_init.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #define D(type, simd) \
  22. mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
  23. mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
  24. D(float, sse)
  25. D(float, avx)
  26. D(int16, mmx)
  27. D(int16, sse2)
  28. av_cold void swri_rematrix_init_x86(struct SwrContext *s){
  29. int mm_flags = av_get_cpu_flags();
  30. int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
  31. int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
  32. int num = nb_in * nb_out;
  33. int i,j;
  34. s->mix_1_1_simd = NULL;
  35. s->mix_2_1_simd = NULL;
  36. if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
  37. if(mm_flags & AV_CPU_FLAG_MMX) {
  38. s->mix_1_1_simd = ff_mix_1_1_a_int16_mmx;
  39. s->mix_2_1_simd = ff_mix_2_1_a_int16_mmx;
  40. }
  41. if(mm_flags & AV_CPU_FLAG_SSE2) {
  42. s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
  43. s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
  44. }
  45. s->native_simd_matrix = av_mallocz(2 * num * sizeof(int16_t));
  46. s->native_simd_one = av_mallocz(2 * sizeof(int16_t));
  47. for(i=0; i<nb_out; i++){
  48. int sh = 0;
  49. for(j=0; j<nb_in; j++)
  50. sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
  51. sh = FFMAX(av_log2(sh) - 14, 0);
  52. for(j=0; j<nb_in; j++) {
  53. ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
  54. ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
  55. ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
  56. }
  57. }
  58. ((int16_t*)s->native_simd_one)[1] = 14;
  59. ((int16_t*)s->native_simd_one)[0] = 16384;
  60. } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
  61. if(mm_flags & AV_CPU_FLAG_SSE) {
  62. s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
  63. s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
  64. }
  65. if(HAVE_AVX_EXTERNAL && mm_flags & AV_CPU_FLAG_AVX) {
  66. s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
  67. s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
  68. }
  69. s->native_simd_matrix = av_mallocz(num * sizeof(float));
  70. memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
  71. s->native_simd_one = av_mallocz(sizeof(float));
  72. memcpy(s->native_simd_one, s->native_one, sizeof(float));
  73. }
  74. }