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.

498 lines
19KB

  1. /*
  2. * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * This file is part of libswresample
  5. *
  6. * libswresample 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. * libswresample 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 libswresample; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "swresample_internal.h"
  21. #include "libavutil/avassert.h"
  22. #include "libavutil/channel_layout.h"
  23. #define TEMPLATE_REMATRIX_FLT
  24. #include "rematrix_template.c"
  25. #undef TEMPLATE_REMATRIX_FLT
  26. #define TEMPLATE_REMATRIX_DBL
  27. #include "rematrix_template.c"
  28. #undef TEMPLATE_REMATRIX_DBL
  29. #define TEMPLATE_REMATRIX_S16
  30. #include "rematrix_template.c"
  31. #undef TEMPLATE_REMATRIX_S16
  32. #define TEMPLATE_REMATRIX_S32
  33. #include "rematrix_template.c"
  34. #undef TEMPLATE_REMATRIX_S32
  35. #define FRONT_LEFT 0
  36. #define FRONT_RIGHT 1
  37. #define FRONT_CENTER 2
  38. #define LOW_FREQUENCY 3
  39. #define BACK_LEFT 4
  40. #define BACK_RIGHT 5
  41. #define FRONT_LEFT_OF_CENTER 6
  42. #define FRONT_RIGHT_OF_CENTER 7
  43. #define BACK_CENTER 8
  44. #define SIDE_LEFT 9
  45. #define SIDE_RIGHT 10
  46. #define TOP_CENTER 11
  47. #define TOP_FRONT_LEFT 12
  48. #define TOP_FRONT_CENTER 13
  49. #define TOP_FRONT_RIGHT 14
  50. #define TOP_BACK_LEFT 15
  51. #define TOP_BACK_CENTER 16
  52. #define TOP_BACK_RIGHT 17
  53. int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
  54. {
  55. int nb_in, nb_out, in, out;
  56. if (!s || s->in_convert) // s needs to be allocated but not initialized
  57. return AVERROR(EINVAL);
  58. memset(s->matrix, 0, sizeof(s->matrix));
  59. nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
  60. nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
  61. for (out = 0; out < nb_out; out++) {
  62. for (in = 0; in < nb_in; in++)
  63. s->matrix[out][in] = matrix[in];
  64. matrix += stride;
  65. }
  66. s->rematrix_custom = 1;
  67. return 0;
  68. }
  69. static int even(int64_t layout){
  70. if(!layout) return 1;
  71. if(layout&(layout-1)) return 1;
  72. return 0;
  73. }
  74. static int clean_layout(SwrContext *s, int64_t layout){
  75. if((layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == AV_CH_LAYOUT_STEREO_DOWNMIX)
  76. return AV_CH_LAYOUT_STEREO;
  77. if(layout && layout != AV_CH_FRONT_CENTER && !(layout&(layout-1))) {
  78. char buf[128];
  79. av_get_channel_layout_string(buf, sizeof(buf), -1, layout);
  80. av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
  81. return AV_CH_FRONT_CENTER;
  82. }
  83. return layout;
  84. }
  85. static int sane_layout(int64_t layout){
  86. if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
  87. return 0;
  88. if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front
  89. return 0;
  90. if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))) // no asymetric side
  91. return 0;
  92. if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))
  93. return 0;
  94. if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))
  95. return 0;
  96. if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX)
  97. return 0;
  98. return 1;
  99. }
  100. av_cold static int auto_matrix(SwrContext *s)
  101. {
  102. int i, j, out_i;
  103. double matrix[64][64]={{0}};
  104. int64_t unaccounted, in_ch_layout, out_ch_layout;
  105. double maxcoef=0;
  106. char buf[128];
  107. const int matrix_encoding = s->matrix_encoding;
  108. float maxval;
  109. in_ch_layout = clean_layout(s, s->in_ch_layout);
  110. if(!sane_layout(in_ch_layout)){
  111. av_get_channel_layout_string(buf, sizeof(buf), -1, s->in_ch_layout);
  112. av_log(s, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
  113. return AVERROR(EINVAL);
  114. }
  115. out_ch_layout = clean_layout(s, s->out_ch_layout);
  116. if(!sane_layout(out_ch_layout)){
  117. av_get_channel_layout_string(buf, sizeof(buf), -1, s->out_ch_layout);
  118. av_log(s, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
  119. return AVERROR(EINVAL);
  120. }
  121. memset(s->matrix, 0, sizeof(s->matrix));
  122. for(i=0; i<64; i++){
  123. if(in_ch_layout & out_ch_layout & (1ULL<<i))
  124. matrix[i][i]= 1.0;
  125. }
  126. unaccounted= in_ch_layout & ~out_ch_layout;
  127. //FIXME implement dolby surround
  128. //FIXME implement full ac3
  129. if(unaccounted & AV_CH_FRONT_CENTER){
  130. if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
  131. if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
  132. matrix[ FRONT_LEFT][FRONT_CENTER]+= s->clev;
  133. matrix[FRONT_RIGHT][FRONT_CENTER]+= s->clev;
  134. } else {
  135. matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2;
  136. matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2;
  137. }
  138. }else
  139. av_assert0(0);
  140. }
  141. if(unaccounted & AV_CH_LAYOUT_STEREO){
  142. if(out_ch_layout & AV_CH_FRONT_CENTER){
  143. matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
  144. matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
  145. if(in_ch_layout & AV_CH_FRONT_CENTER)
  146. matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2);
  147. }else
  148. av_assert0(0);
  149. }
  150. if(unaccounted & AV_CH_BACK_CENTER){
  151. if(out_ch_layout & AV_CH_BACK_LEFT){
  152. matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
  153. matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
  154. }else if(out_ch_layout & AV_CH_SIDE_LEFT){
  155. matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
  156. matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
  157. }else if(out_ch_layout & AV_CH_FRONT_LEFT){
  158. if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
  159. matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
  160. if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
  161. matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev * M_SQRT1_2;
  162. matrix[FRONT_RIGHT][BACK_CENTER] += s->slev * M_SQRT1_2;
  163. } else {
  164. matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev;
  165. matrix[FRONT_RIGHT][BACK_CENTER] += s->slev;
  166. }
  167. } else {
  168. matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2;
  169. matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2;
  170. }
  171. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  172. matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2;
  173. }else
  174. av_assert0(0);
  175. }
  176. if(unaccounted & AV_CH_BACK_LEFT){
  177. if(out_ch_layout & AV_CH_BACK_CENTER){
  178. matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
  179. matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
  180. }else if(out_ch_layout & AV_CH_SIDE_LEFT){
  181. if(in_ch_layout & AV_CH_SIDE_LEFT){
  182. matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
  183. matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
  184. }else{
  185. matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
  186. matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
  187. }
  188. }else if(out_ch_layout & AV_CH_FRONT_LEFT){
  189. if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
  190. matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * M_SQRT1_2;
  191. matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
  192. matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2;
  193. matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * M_SQRT1_2;
  194. } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
  195. matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * SQRT3_2;
  196. matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
  197. matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2;
  198. matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * SQRT3_2;
  199. } else {
  200. matrix[ FRONT_LEFT][ BACK_LEFT] += s->slev;
  201. matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev;
  202. }
  203. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  204. matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2;
  205. matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2;
  206. }else
  207. av_assert0(0);
  208. }
  209. if(unaccounted & AV_CH_SIDE_LEFT){
  210. if(out_ch_layout & AV_CH_BACK_LEFT){
  211. /* if back channels do not exist in the input, just copy side
  212. channels to back channels, otherwise mix side into back */
  213. if (in_ch_layout & AV_CH_BACK_LEFT) {
  214. matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
  215. matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
  216. } else {
  217. matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
  218. matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
  219. }
  220. }else if(out_ch_layout & AV_CH_BACK_CENTER){
  221. matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
  222. matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
  223. }else if(out_ch_layout & AV_CH_FRONT_LEFT){
  224. if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
  225. matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * M_SQRT1_2;
  226. matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
  227. matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2;
  228. matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * M_SQRT1_2;
  229. } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
  230. matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * SQRT3_2;
  231. matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
  232. matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2;
  233. matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * SQRT3_2;
  234. } else {
  235. matrix[ FRONT_LEFT][ SIDE_LEFT] += s->slev;
  236. matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev;
  237. }
  238. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  239. matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2;
  240. matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2;
  241. }else
  242. av_assert0(0);
  243. }
  244. if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
  245. if(out_ch_layout & AV_CH_FRONT_LEFT){
  246. matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
  247. matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
  248. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  249. matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
  250. matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
  251. }else
  252. av_assert0(0);
  253. }
  254. /* mix LFE into front left/right or center */
  255. if (unaccounted & AV_CH_LOW_FREQUENCY) {
  256. if (out_ch_layout & AV_CH_FRONT_CENTER) {
  257. matrix[FRONT_CENTER][LOW_FREQUENCY] += s->lfe_mix_level;
  258. } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
  259. matrix[FRONT_LEFT ][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
  260. matrix[FRONT_RIGHT][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
  261. } else
  262. av_assert0(0);
  263. }
  264. for(out_i=i=0; i<64; i++){
  265. double sum=0;
  266. int in_i=0;
  267. for(j=0; j<64; j++){
  268. s->matrix[out_i][in_i]= matrix[i][j];
  269. if(matrix[i][j]){
  270. sum += fabs(matrix[i][j]);
  271. }
  272. if(in_ch_layout & (1ULL<<j))
  273. in_i++;
  274. }
  275. maxcoef= FFMAX(maxcoef, sum);
  276. if(out_ch_layout & (1ULL<<i))
  277. out_i++;
  278. }
  279. if(s->rematrix_volume < 0)
  280. maxcoef = -s->rematrix_volume;
  281. if (s->rematrix_maxval > 0) {
  282. maxval = s->rematrix_maxval;
  283. } else if ( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
  284. || av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) {
  285. maxval = 1.0;
  286. } else
  287. maxval = INT_MAX;
  288. if(maxcoef > maxval || s->rematrix_volume < 0){
  289. maxcoef /= maxval;
  290. for(i=0; i<SWR_CH_MAX; i++)
  291. for(j=0; j<SWR_CH_MAX; j++){
  292. s->matrix[i][j] /= maxcoef;
  293. }
  294. }
  295. if(s->rematrix_volume > 0){
  296. for(i=0; i<SWR_CH_MAX; i++)
  297. for(j=0; j<SWR_CH_MAX; j++){
  298. s->matrix[i][j] *= s->rematrix_volume;
  299. }
  300. }
  301. for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
  302. for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
  303. av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]);
  304. }
  305. av_log(NULL, AV_LOG_DEBUG, "\n");
  306. }
  307. return 0;
  308. }
  309. av_cold int swri_rematrix_init(SwrContext *s){
  310. int i, j;
  311. int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
  312. int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
  313. s->mix_any_f = NULL;
  314. if (!s->rematrix_custom) {
  315. int r = auto_matrix(s);
  316. if (r)
  317. return r;
  318. }
  319. if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
  320. s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
  321. s->native_one = av_mallocz(sizeof(int));
  322. for (i = 0; i < nb_out; i++)
  323. for (j = 0; j < nb_in; j++)
  324. ((int*)s->native_matrix)[i * nb_in + j] = lrintf(s->matrix[i][j] * 32768);
  325. *((int*)s->native_one) = 32768;
  326. s->mix_1_1_f = (mix_1_1_func_type*)copy_s16;
  327. s->mix_2_1_f = (mix_2_1_func_type*)sum2_s16;
  328. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s16(s);
  329. }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
  330. s->native_matrix = av_calloc(nb_in * nb_out, sizeof(float));
  331. s->native_one = av_mallocz(sizeof(float));
  332. for (i = 0; i < nb_out; i++)
  333. for (j = 0; j < nb_in; j++)
  334. ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
  335. *((float*)s->native_one) = 1.0;
  336. s->mix_1_1_f = (mix_1_1_func_type*)copy_float;
  337. s->mix_2_1_f = (mix_2_1_func_type*)sum2_float;
  338. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_float(s);
  339. }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
  340. s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
  341. s->native_one = av_mallocz(sizeof(double));
  342. for (i = 0; i < nb_out; i++)
  343. for (j = 0; j < nb_in; j++)
  344. ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
  345. *((double*)s->native_one) = 1.0;
  346. s->mix_1_1_f = (mix_1_1_func_type*)copy_double;
  347. s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
  348. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
  349. }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
  350. // Only for dithering currently
  351. // s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
  352. s->native_one = av_mallocz(sizeof(int));
  353. // for (i = 0; i < nb_out; i++)
  354. // for (j = 0; j < nb_in; j++)
  355. // ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
  356. *((int*)s->native_one) = 32768;
  357. s->mix_1_1_f = (mix_1_1_func_type*)copy_s32;
  358. s->mix_2_1_f = (mix_2_1_func_type*)sum2_s32;
  359. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s32(s);
  360. }else
  361. av_assert0(0);
  362. //FIXME quantize for integeres
  363. for (i = 0; i < SWR_CH_MAX; i++) {
  364. int ch_in=0;
  365. for (j = 0; j < SWR_CH_MAX; j++) {
  366. s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768);
  367. if(s->matrix[i][j])
  368. s->matrix_ch[i][++ch_in]= j;
  369. }
  370. s->matrix_ch[i][0]= ch_in;
  371. }
  372. if(HAVE_YASM && HAVE_MMX) swri_rematrix_init_x86(s);
  373. return 0;
  374. }
  375. av_cold void swri_rematrix_free(SwrContext *s){
  376. av_freep(&s->native_matrix);
  377. av_freep(&s->native_one);
  378. av_freep(&s->native_simd_matrix);
  379. av_freep(&s->native_simd_one);
  380. }
  381. int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
  382. int out_i, in_i, i, j;
  383. int len1 = 0;
  384. int off = 0;
  385. if(s->mix_any_f) {
  386. s->mix_any_f(out->ch, (const uint8_t **)in->ch, s->native_matrix, len);
  387. return 0;
  388. }
  389. if(s->mix_2_1_simd || s->mix_1_1_simd){
  390. len1= len&~15;
  391. off = len1 * out->bps;
  392. }
  393. av_assert0(out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
  394. av_assert0(in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
  395. for(out_i=0; out_i<out->ch_count; out_i++){
  396. switch(s->matrix_ch[out_i][0]){
  397. case 0:
  398. if(mustcopy)
  399. memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
  400. break;
  401. case 1:
  402. in_i= s->matrix_ch[out_i][1];
  403. if(s->matrix[out_i][in_i]!=1.0){
  404. if(s->mix_1_1_simd && len1)
  405. s->mix_1_1_simd(out->ch[out_i] , in->ch[in_i] , s->native_simd_matrix, in->ch_count*out_i + in_i, len1);
  406. if(len != len1)
  407. s->mix_1_1_f (out->ch[out_i]+off, in->ch[in_i]+off, s->native_matrix, in->ch_count*out_i + in_i, len-len1);
  408. }else if(mustcopy){
  409. memcpy(out->ch[out_i], in->ch[in_i], len*out->bps);
  410. }else{
  411. out->ch[out_i]= in->ch[in_i];
  412. }
  413. break;
  414. case 2: {
  415. int in_i1 = s->matrix_ch[out_i][1];
  416. int in_i2 = s->matrix_ch[out_i][2];
  417. if(s->mix_2_1_simd && len1)
  418. s->mix_2_1_simd(out->ch[out_i] , in->ch[in_i1] , in->ch[in_i2] , s->native_simd_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len1);
  419. else
  420. s->mix_2_1_f (out->ch[out_i] , in->ch[in_i1] , in->ch[in_i2] , s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len1);
  421. if(len != len1)
  422. s->mix_2_1_f (out->ch[out_i]+off, in->ch[in_i1]+off, in->ch[in_i2]+off, s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len-len1);
  423. break;}
  424. default:
  425. if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
  426. for(i=0; i<len; i++){
  427. float v=0;
  428. for(j=0; j<s->matrix_ch[out_i][0]; j++){
  429. in_i= s->matrix_ch[out_i][1+j];
  430. v+= ((float*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
  431. }
  432. ((float*)out->ch[out_i])[i]= v;
  433. }
  434. }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
  435. for(i=0; i<len; i++){
  436. double v=0;
  437. for(j=0; j<s->matrix_ch[out_i][0]; j++){
  438. in_i= s->matrix_ch[out_i][1+j];
  439. v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
  440. }
  441. ((double*)out->ch[out_i])[i]= v;
  442. }
  443. }else{
  444. for(i=0; i<len; i++){
  445. int v=0;
  446. for(j=0; j<s->matrix_ch[out_i][0]; j++){
  447. in_i= s->matrix_ch[out_i][1+j];
  448. v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i];
  449. }
  450. ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15;
  451. }
  452. }
  453. }
  454. }
  455. return 0;
  456. }