2
0

flacdsp_init.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2014 James Almer
  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 "libavcodec/flacdsp.h"
  21. #include "libavutil/x86/cpu.h"
  22. #include "config.h"
  23. void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order,
  24. int qlevel, int len);
  25. void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order,
  26. int qlevel, int len);
  27. void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int, const int32_t *,int);
  28. #define DECORRELATE_FUNCS(fmt, opt) \
  29. void ff_flac_decorrelate_ls_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  30. int len, int shift); \
  31. void ff_flac_decorrelate_rs_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  32. int len, int shift); \
  33. void ff_flac_decorrelate_ms_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  34. int len, int shift); \
  35. void ff_flac_decorrelate_indep2_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  36. int len, int shift); \
  37. void ff_flac_decorrelate_indep4_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  38. int len, int shift); \
  39. void ff_flac_decorrelate_indep6_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  40. int len, int shift); \
  41. void ff_flac_decorrelate_indep8_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
  42. int len, int shift)
  43. DECORRELATE_FUNCS(16, sse2);
  44. DECORRELATE_FUNCS(16, avx);
  45. DECORRELATE_FUNCS(32, sse2);
  46. DECORRELATE_FUNCS(32, avx);
  47. av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int channels,
  48. int bps)
  49. {
  50. #if HAVE_X86ASM
  51. int cpu_flags = av_get_cpu_flags();
  52. #if CONFIG_FLAC_DECODER
  53. if (EXTERNAL_SSE2(cpu_flags)) {
  54. if (fmt == AV_SAMPLE_FMT_S16) {
  55. if (channels == 2)
  56. c->decorrelate[0] = ff_flac_decorrelate_indep2_16_sse2;
  57. else if (channels == 4)
  58. c->decorrelate[0] = ff_flac_decorrelate_indep4_16_sse2;
  59. else if (channels == 6)
  60. c->decorrelate[0] = ff_flac_decorrelate_indep6_16_sse2;
  61. else if (ARCH_X86_64 && channels == 8)
  62. c->decorrelate[0] = ff_flac_decorrelate_indep8_16_sse2;
  63. c->decorrelate[1] = ff_flac_decorrelate_ls_16_sse2;
  64. c->decorrelate[2] = ff_flac_decorrelate_rs_16_sse2;
  65. c->decorrelate[3] = ff_flac_decorrelate_ms_16_sse2;
  66. } else if (fmt == AV_SAMPLE_FMT_S32) {
  67. if (channels == 2)
  68. c->decorrelate[0] = ff_flac_decorrelate_indep2_32_sse2;
  69. else if (channels == 4)
  70. c->decorrelate[0] = ff_flac_decorrelate_indep4_32_sse2;
  71. else if (channels == 6)
  72. c->decorrelate[0] = ff_flac_decorrelate_indep6_32_sse2;
  73. else if (ARCH_X86_64 && channels == 8)
  74. c->decorrelate[0] = ff_flac_decorrelate_indep8_32_sse2;
  75. c->decorrelate[1] = ff_flac_decorrelate_ls_32_sse2;
  76. c->decorrelate[2] = ff_flac_decorrelate_rs_32_sse2;
  77. c->decorrelate[3] = ff_flac_decorrelate_ms_32_sse2;
  78. }
  79. }
  80. if (EXTERNAL_SSE4(cpu_flags)) {
  81. c->lpc32 = ff_flac_lpc_32_sse4;
  82. }
  83. if (EXTERNAL_AVX(cpu_flags)) {
  84. if (fmt == AV_SAMPLE_FMT_S16) {
  85. if (ARCH_X86_64 && channels == 8)
  86. c->decorrelate[0] = ff_flac_decorrelate_indep8_16_avx;
  87. } else if (fmt == AV_SAMPLE_FMT_S32) {
  88. if (channels == 4)
  89. c->decorrelate[0] = ff_flac_decorrelate_indep4_32_avx;
  90. else if (channels == 6)
  91. c->decorrelate[0] = ff_flac_decorrelate_indep6_32_avx;
  92. else if (ARCH_X86_64 && channels == 8)
  93. c->decorrelate[0] = ff_flac_decorrelate_indep8_32_avx;
  94. }
  95. }
  96. if (EXTERNAL_XOP(cpu_flags)) {
  97. c->lpc32 = ff_flac_lpc_32_xop;
  98. }
  99. #endif
  100. #if CONFIG_FLAC_ENCODER
  101. if (EXTERNAL_SSE4(cpu_flags)) {
  102. if (CONFIG_GPL)
  103. c->lpc16_encode = ff_flac_enc_lpc_16_sse4;
  104. }
  105. #endif
  106. #endif /* HAVE_X86ASM */
  107. }