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.

116 lines
7.3KB

  1. /*
  2. * Audio resampling
  3. *
  4. * Copyright (c) 2004-2012 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "config.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/avassert.h"
  25. #include "libavutil/arm/cpu.h"
  26. #include "libswresample/resample.h"
  27. #define DECLARE_RESAMPLE_COMMON_TEMPLATE(TYPE, DELEM, FELEM, FELEM2, OUT) \
  28. \
  29. void ff_resample_common_apply_filter_x4_##TYPE##_neon(FELEM2 *acc, const DELEM *src, \
  30. const FELEM *filter, int length); \
  31. \
  32. void ff_resample_common_apply_filter_x8_##TYPE##_neon(FELEM2 *acc, const DELEM *src, \
  33. const FELEM *filter, int length); \
  34. \
  35. static int ff_resample_common_##TYPE##_neon(ResampleContext *c, void *dest, const void *source, \
  36. int n, int update_ctx) \
  37. { \
  38. DELEM *dst = dest; \
  39. const DELEM *src = source; \
  40. int dst_index; \
  41. int index= c->index; \
  42. int frac= c->frac; \
  43. int sample_index = index >> c->phase_shift; \
  44. int x4_aligned_filter_length = c->filter_length & ~3; \
  45. int x8_aligned_filter_length = c->filter_length & ~7; \
  46. \
  47. index &= c->phase_mask; \
  48. for (dst_index = 0; dst_index < n; dst_index++) { \
  49. FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index; \
  50. \
  51. FELEM2 val=0; \
  52. int i = 0; \
  53. if (x8_aligned_filter_length >= 8) { \
  54. ff_resample_common_apply_filter_x8_##TYPE##_neon(&val, &src[sample_index], \
  55. filter, x8_aligned_filter_length); \
  56. i += x8_aligned_filter_length; \
  57. \
  58. } else if (x4_aligned_filter_length >= 4) { \
  59. ff_resample_common_apply_filter_x4_##TYPE##_neon(&val, &src[sample_index], \
  60. filter, x4_aligned_filter_length); \
  61. i += x4_aligned_filter_length; \
  62. } \
  63. for (; i < c->filter_length; i++) { \
  64. val += src[sample_index + i] * (FELEM2)filter[i]; \
  65. } \
  66. OUT(dst[dst_index], val); \
  67. \
  68. frac += c->dst_incr_mod; \
  69. index += c->dst_incr_div; \
  70. if (frac >= c->src_incr) { \
  71. frac -= c->src_incr; \
  72. index++; \
  73. } \
  74. sample_index += index >> c->phase_shift; \
  75. index &= c->phase_mask; \
  76. } \
  77. \
  78. if(update_ctx){ \
  79. c->frac= frac; \
  80. c->index= index; \
  81. } \
  82. \
  83. return sample_index; \
  84. } \
  85. #define OUT(d, v) d = v
  86. DECLARE_RESAMPLE_COMMON_TEMPLATE(float, float, float, float, OUT)
  87. #undef OUT
  88. #define OUT(d, v) (v) = ((v) + (1<<(14)))>>15; (d) = av_clip_int16(v)
  89. DECLARE_RESAMPLE_COMMON_TEMPLATE(s16, int16_t, int16_t, int32_t, OUT)
  90. #undef OUT
  91. av_cold void swri_resample_dsp_arm_init(ResampleContext *c)
  92. {
  93. int cpu_flags = av_get_cpu_flags();
  94. if (!have_neon(cpu_flags))
  95. return;
  96. switch(c->format) {
  97. case AV_SAMPLE_FMT_FLTP:
  98. if (!c->linear)
  99. c->dsp.resample = ff_resample_common_float_neon;
  100. break;
  101. case AV_SAMPLE_FMT_S16P:
  102. if (!c->linear)
  103. c->dsp.resample = ff_resample_common_s16_neon;
  104. break;
  105. }
  106. }