2
0

aacpsdsp_template.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
  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. * Note: Rounding-to-nearest used unless otherwise stated
  21. *
  22. */
  23. #include <stdint.h>
  24. #include "config.h"
  25. #include "libavutil/attributes.h"
  26. #include "aacpsdsp.h"
  27. static void ps_add_squares_c(INTFLOAT *dst, const INTFLOAT (*src)[2], int n)
  28. {
  29. int i;
  30. for (i = 0; i < n; i++)
  31. dst[i] += (UINTFLOAT)AAC_MADD28(src[i][0], src[i][0], src[i][1], src[i][1]);
  32. }
  33. static void ps_mul_pair_single_c(INTFLOAT (*dst)[2], INTFLOAT (*src0)[2], INTFLOAT *src1,
  34. int n)
  35. {
  36. int i;
  37. for (i = 0; i < n; i++) {
  38. dst[i][0] = AAC_MUL16(src0[i][0], src1[i]);
  39. dst[i][1] = AAC_MUL16(src0[i][1], src1[i]);
  40. }
  41. }
  42. static void ps_hybrid_analysis_c(INTFLOAT (*out)[2], INTFLOAT (*in)[2],
  43. const INTFLOAT (*filter)[8][2],
  44. ptrdiff_t stride, int n)
  45. {
  46. int i, j;
  47. for (i = 0; i < n; i++) {
  48. INT64FLOAT sum_re = (INT64FLOAT)filter[i][6][0] * in[6][0];
  49. INT64FLOAT sum_im = (INT64FLOAT)filter[i][6][0] * in[6][1];
  50. for (j = 0; j < 6; j++) {
  51. INT64FLOAT in0_re = in[j][0];
  52. INT64FLOAT in0_im = in[j][1];
  53. INT64FLOAT in1_re = in[12-j][0];
  54. INT64FLOAT in1_im = in[12-j][1];
  55. sum_re += (INT64FLOAT)filter[i][j][0] * (in0_re + in1_re) -
  56. (INT64FLOAT)filter[i][j][1] * (in0_im - in1_im);
  57. sum_im += (INT64FLOAT)filter[i][j][0] * (in0_im + in1_im) +
  58. (INT64FLOAT)filter[i][j][1] * (in0_re - in1_re);
  59. }
  60. #if USE_FIXED
  61. out[i * stride][0] = (int)((sum_re + 0x40000000) >> 31);
  62. out[i * stride][1] = (int)((sum_im + 0x40000000) >> 31);
  63. #else
  64. out[i * stride][0] = sum_re;
  65. out[i * stride][1] = sum_im;
  66. #endif /* USE_FIXED */
  67. }
  68. }
  69. static void ps_hybrid_analysis_ileave_c(INTFLOAT (*out)[32][2], INTFLOAT L[2][38][64],
  70. int i, int len)
  71. {
  72. int j;
  73. for (; i < 64; i++) {
  74. for (j = 0; j < len; j++) {
  75. out[i][j][0] = L[0][j][i];
  76. out[i][j][1] = L[1][j][i];
  77. }
  78. }
  79. }
  80. static void ps_hybrid_synthesis_deint_c(INTFLOAT out[2][38][64],
  81. INTFLOAT (*in)[32][2],
  82. int i, int len)
  83. {
  84. int n;
  85. for (; i < 64; i++) {
  86. for (n = 0; n < len; n++) {
  87. out[0][n][i] = in[i][n][0];
  88. out[1][n][i] = in[i][n][1];
  89. }
  90. }
  91. }
  92. static void ps_decorrelate_c(INTFLOAT (*out)[2], INTFLOAT (*delay)[2],
  93. INTFLOAT (*ap_delay)[PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2],
  94. const INTFLOAT phi_fract[2], const INTFLOAT (*Q_fract)[2],
  95. const INTFLOAT *transient_gain,
  96. INTFLOAT g_decay_slope,
  97. int len)
  98. {
  99. static const INTFLOAT a[] = { Q31(0.65143905753106f),
  100. Q31(0.56471812200776f),
  101. Q31(0.48954165955695f) };
  102. INTFLOAT ag[PS_AP_LINKS];
  103. int m, n;
  104. for (m = 0; m < PS_AP_LINKS; m++)
  105. ag[m] = AAC_MUL30(a[m], g_decay_slope);
  106. for (n = 0; n < len; n++) {
  107. INTFLOAT in_re = AAC_MSUB30(delay[n][0], phi_fract[0], delay[n][1], phi_fract[1]);
  108. INTFLOAT in_im = AAC_MADD30(delay[n][0], phi_fract[1], delay[n][1], phi_fract[0]);
  109. for (m = 0; m < PS_AP_LINKS; m++) {
  110. INTFLOAT a_re = AAC_MUL31(ag[m], in_re);
  111. INTFLOAT a_im = AAC_MUL31(ag[m], in_im);
  112. INTFLOAT link_delay_re = ap_delay[m][n+2-m][0];
  113. INTFLOAT link_delay_im = ap_delay[m][n+2-m][1];
  114. INTFLOAT fractional_delay_re = Q_fract[m][0];
  115. INTFLOAT fractional_delay_im = Q_fract[m][1];
  116. INTFLOAT apd_re = in_re;
  117. INTFLOAT apd_im = in_im;
  118. in_re = AAC_MSUB30(link_delay_re, fractional_delay_re,
  119. link_delay_im, fractional_delay_im);
  120. in_re -= (UINTFLOAT)a_re;
  121. in_im = AAC_MADD30(link_delay_re, fractional_delay_im,
  122. link_delay_im, fractional_delay_re);
  123. in_im -= (UINTFLOAT)a_im;
  124. ap_delay[m][n+5][0] = apd_re + (UINTFLOAT)AAC_MUL31(ag[m], in_re);
  125. ap_delay[m][n+5][1] = apd_im + (UINTFLOAT)AAC_MUL31(ag[m], in_im);
  126. }
  127. out[n][0] = AAC_MUL16(transient_gain[n], in_re);
  128. out[n][1] = AAC_MUL16(transient_gain[n], in_im);
  129. }
  130. }
  131. static void ps_stereo_interpolate_c(INTFLOAT (*l)[2], INTFLOAT (*r)[2],
  132. INTFLOAT h[2][4], INTFLOAT h_step[2][4],
  133. int len)
  134. {
  135. INTFLOAT h0 = h[0][0];
  136. INTFLOAT h1 = h[0][1];
  137. INTFLOAT h2 = h[0][2];
  138. INTFLOAT h3 = h[0][3];
  139. UINTFLOAT hs0 = h_step[0][0];
  140. UINTFLOAT hs1 = h_step[0][1];
  141. UINTFLOAT hs2 = h_step[0][2];
  142. UINTFLOAT hs3 = h_step[0][3];
  143. int n;
  144. for (n = 0; n < len; n++) {
  145. //l is s, r is d
  146. INTFLOAT l_re = l[n][0];
  147. INTFLOAT l_im = l[n][1];
  148. INTFLOAT r_re = r[n][0];
  149. INTFLOAT r_im = r[n][1];
  150. h0 += hs0;
  151. h1 += hs1;
  152. h2 += hs2;
  153. h3 += hs3;
  154. l[n][0] = AAC_MADD30(h0, l_re, h2, r_re);
  155. l[n][1] = AAC_MADD30(h0, l_im, h2, r_im);
  156. r[n][0] = AAC_MADD30(h1, l_re, h3, r_re);
  157. r[n][1] = AAC_MADD30(h1, l_im, h3, r_im);
  158. }
  159. }
  160. static void ps_stereo_interpolate_ipdopd_c(INTFLOAT (*l)[2], INTFLOAT (*r)[2],
  161. INTFLOAT h[2][4], INTFLOAT h_step[2][4],
  162. int len)
  163. {
  164. INTFLOAT h00 = h[0][0], h10 = h[1][0];
  165. INTFLOAT h01 = h[0][1], h11 = h[1][1];
  166. INTFLOAT h02 = h[0][2], h12 = h[1][2];
  167. INTFLOAT h03 = h[0][3], h13 = h[1][3];
  168. UINTFLOAT hs00 = h_step[0][0], hs10 = h_step[1][0];
  169. UINTFLOAT hs01 = h_step[0][1], hs11 = h_step[1][1];
  170. UINTFLOAT hs02 = h_step[0][2], hs12 = h_step[1][2];
  171. UINTFLOAT hs03 = h_step[0][3], hs13 = h_step[1][3];
  172. int n;
  173. for (n = 0; n < len; n++) {
  174. //l is s, r is d
  175. INTFLOAT l_re = l[n][0];
  176. INTFLOAT l_im = l[n][1];
  177. INTFLOAT r_re = r[n][0];
  178. INTFLOAT r_im = r[n][1];
  179. h00 += hs00;
  180. h01 += hs01;
  181. h02 += hs02;
  182. h03 += hs03;
  183. h10 += hs10;
  184. h11 += hs11;
  185. h12 += hs12;
  186. h13 += hs13;
  187. l[n][0] = AAC_MSUB30_V8(h00, l_re, h02, r_re, h10, l_im, h12, r_im);
  188. l[n][1] = AAC_MADD30_V8(h00, l_im, h02, r_im, h10, l_re, h12, r_re);
  189. r[n][0] = AAC_MSUB30_V8(h01, l_re, h03, r_re, h11, l_im, h13, r_im);
  190. r[n][1] = AAC_MADD30_V8(h01, l_im, h03, r_im, h11, l_re, h13, r_re);
  191. }
  192. }
  193. av_cold void AAC_RENAME(ff_psdsp_init)(PSDSPContext *s)
  194. {
  195. s->add_squares = ps_add_squares_c;
  196. s->mul_pair_single = ps_mul_pair_single_c;
  197. s->hybrid_analysis = ps_hybrid_analysis_c;
  198. s->hybrid_analysis_ileave = ps_hybrid_analysis_ileave_c;
  199. s->hybrid_synthesis_deint = ps_hybrid_synthesis_deint_c;
  200. s->decorrelate = ps_decorrelate_c;
  201. s->stereo_interpolate[0] = ps_stereo_interpolate_c;
  202. s->stereo_interpolate[1] = ps_stereo_interpolate_ipdopd_c;
  203. #if !USE_FIXED
  204. if (ARCH_ARM)
  205. ff_psdsp_init_arm(s);
  206. if (ARCH_AARCH64)
  207. ff_psdsp_init_aarch64(s);
  208. if (ARCH_MIPS)
  209. ff_psdsp_init_mips(s);
  210. if (ARCH_X86)
  211. ff_psdsp_init_x86(s);
  212. #endif /* !USE_FIXED */
  213. }