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.

217 lines
7.1KB

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