mlpdsp_init_arm.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (c) 2014 RISC OS Open Ltd
  3. * Author: Ben Avison <bavison@riscosopen.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <stdint.h>
  22. #include "libavutil/arm/cpu.h"
  23. #include "libavutil/attributes.h"
  24. #include "libavcodec/mlpdsp.h"
  25. void ff_mlp_filter_channel_arm(int32_t *state, const int32_t *coeff,
  26. int firorder, int iirorder,
  27. unsigned int filter_shift, int32_t mask,
  28. int blocksize, int32_t *sample_buffer);
  29. void ff_mlp_rematrix_channel_arm(int32_t *samples,
  30. const int32_t *coeffs,
  31. const uint8_t *bypassed_lsbs,
  32. const int8_t *noise_buffer,
  33. int index,
  34. unsigned int dest_ch,
  35. uint16_t blockpos,
  36. unsigned int maxchan,
  37. int matrix_noise_shift,
  38. int access_unit_size_pow2,
  39. int32_t mask);
  40. #define DECLARE_PACK(order,channels,shift) \
  41. int32_t ff_mlp_pack_output_##order##order_##channels##ch_##shift##shift_armv6(int32_t, uint16_t, int32_t (*)[], void *, uint8_t*, int8_t *, uint8_t, int);
  42. #define ENUMERATE_PACK(order,channels,shift) \
  43. ff_mlp_pack_output_##order##order_##channels##ch_##shift##shift_armv6,
  44. #define PACK_CHANNELS(macro,order,channels) \
  45. macro(order,channels,0) \
  46. macro(order,channels,1) \
  47. macro(order,channels,2) \
  48. macro(order,channels,3) \
  49. macro(order,channels,4) \
  50. macro(order,channels,5) \
  51. macro(order,channels,mixed)
  52. #define PACK_ORDER(macro,order) \
  53. PACK_CHANNELS(macro,order,2) \
  54. PACK_CHANNELS(macro,order,6) \
  55. PACK_CHANNELS(macro,order,8)
  56. #define PACK_ALL(macro) \
  57. PACK_ORDER(macro,outof) \
  58. PACK_ORDER(macro,in)
  59. PACK_ALL(DECLARE_PACK)
  60. #define ff_mlp_pack_output_outoforder_2ch_mixedshift_armv6 0
  61. #define ff_mlp_pack_output_outoforder_6ch_mixedshift_armv6 0
  62. #define ff_mlp_pack_output_outoforder_8ch_mixedshift_armv6 0
  63. #if CONFIG_THUMB
  64. #define ff_mlp_pack_output_outoforder_2ch_0shift_armv6 0
  65. #define ff_mlp_pack_output_outoforder_2ch_1shift_armv6 0
  66. #define ff_mlp_pack_output_outoforder_2ch_2shift_armv6 0
  67. #define ff_mlp_pack_output_outoforder_2ch_3shift_armv6 0
  68. #define ff_mlp_pack_output_outoforder_2ch_4shift_armv6 0
  69. #define ff_mlp_pack_output_outoforder_2ch_5shift_armv6 0
  70. #define ff_mlp_pack_output_outoforder_6ch_0shift_armv6 0
  71. #define ff_mlp_pack_output_outoforder_6ch_1shift_armv6 0
  72. #define ff_mlp_pack_output_outoforder_6ch_2shift_armv6 0
  73. #define ff_mlp_pack_output_outoforder_6ch_3shift_armv6 0
  74. #define ff_mlp_pack_output_outoforder_6ch_4shift_armv6 0
  75. #define ff_mlp_pack_output_outoforder_6ch_5shift_armv6 0
  76. #define ff_mlp_pack_output_outoforder_8ch_0shift_armv6 0
  77. #define ff_mlp_pack_output_outoforder_8ch_1shift_armv6 0
  78. #define ff_mlp_pack_output_outoforder_8ch_2shift_armv6 0
  79. #define ff_mlp_pack_output_outoforder_8ch_3shift_armv6 0
  80. #define ff_mlp_pack_output_outoforder_8ch_4shift_armv6 0
  81. #define ff_mlp_pack_output_outoforder_8ch_5shift_armv6 0
  82. #endif
  83. static int32_t (*mlp_select_pack_output_armv6(uint8_t *ch_assign,
  84. int8_t *output_shift,
  85. uint8_t max_matrix_channel,
  86. int is32))(int32_t, uint16_t, int32_t (*)[], void *, uint8_t*, int8_t *, uint8_t, int)
  87. {
  88. int ch_index;
  89. int shift = output_shift[0] < 0 || output_shift[0] > 5 ? 6 : output_shift[0];
  90. int inorder = 1;
  91. static int32_t (*const routine[2*3*7])(int32_t, uint16_t, int32_t (*)[], void *, uint8_t*, int8_t *, uint8_t, int) = {
  92. PACK_ALL(ENUMERATE_PACK)
  93. };
  94. int i;
  95. if (!is32) // don't support 16-bit output (it's not used by TrueHD)
  96. return ff_mlp_pack_output;
  97. switch (max_matrix_channel) {
  98. case 1:
  99. ch_index = 0;
  100. break;
  101. case 5:
  102. ch_index = 1;
  103. break;
  104. case 7:
  105. ch_index = 2;
  106. break;
  107. default:
  108. return ff_mlp_pack_output;
  109. }
  110. for (i = 0; i <= max_matrix_channel; i++) {
  111. if (shift != 6 && output_shift[i] != shift)
  112. shift = 6; // indicate mixed shifts
  113. if (ch_assign[i] != i)
  114. inorder = 0;
  115. }
  116. #if CONFIG_THUMB
  117. if (!inorder)
  118. return ff_mlp_pack_output; // can't currently handle an order array except in ARM mode
  119. #else
  120. if (shift == 6 && !inorder)
  121. return ff_mlp_pack_output; // can't currently handle both an order array and a shift array
  122. #endif
  123. return routine[(inorder*3+ch_index)*7+shift];
  124. }
  125. av_cold void ff_mlpdsp_init_arm(MLPDSPContext *c)
  126. {
  127. int cpu_flags = av_get_cpu_flags();
  128. if (have_armv5te(cpu_flags)) {
  129. c->mlp_filter_channel = ff_mlp_filter_channel_arm;
  130. c->mlp_rematrix_channel = ff_mlp_rematrix_channel_arm;
  131. }
  132. if (have_armv6(cpu_flags))
  133. c->mlp_select_pack_output = mlp_select_pack_output_armv6;
  134. }