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.

489 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. in_ch_layout = clean_layout(s, s->in_ch_layout);
  109. if(!sane_layout(in_ch_layout)){
  110. av_get_channel_layout_string(buf, sizeof(buf), -1, s->in_ch_layout);
  111. av_log(s, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
  112. return AVERROR(EINVAL);
  113. }
  114. out_ch_layout = clean_layout(s, s->out_ch_layout);
  115. if(!sane_layout(out_ch_layout)){
  116. av_get_channel_layout_string(buf, sizeof(buf), -1, s->out_ch_layout);
  117. av_log(s, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
  118. return AVERROR(EINVAL);
  119. }
  120. memset(s->matrix, 0, sizeof(s->matrix));
  121. for(i=0; i<64; i++){
  122. if(in_ch_layout & out_ch_layout & (1ULL<<i))
  123. matrix[i][i]= 1.0;
  124. }
  125. unaccounted= in_ch_layout & ~out_ch_layout;
  126. //FIXME implement dolby surround
  127. //FIXME implement full ac3
  128. if(unaccounted & AV_CH_FRONT_CENTER){
  129. if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
  130. if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
  131. matrix[ FRONT_LEFT][FRONT_CENTER]+= s->clev;
  132. matrix[FRONT_RIGHT][FRONT_CENTER]+= s->clev;
  133. } else {
  134. matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2;
  135. matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2;
  136. }
  137. }else
  138. av_assert0(0);
  139. }
  140. if(unaccounted & AV_CH_LAYOUT_STEREO){
  141. if(out_ch_layout & AV_CH_FRONT_CENTER){
  142. matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
  143. matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
  144. if(in_ch_layout & AV_CH_FRONT_CENTER)
  145. matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2);
  146. }else
  147. av_assert0(0);
  148. }
  149. if(unaccounted & AV_CH_BACK_CENTER){
  150. if(out_ch_layout & AV_CH_BACK_LEFT){
  151. matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
  152. matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
  153. }else if(out_ch_layout & AV_CH_SIDE_LEFT){
  154. matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
  155. matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
  156. }else if(out_ch_layout & AV_CH_FRONT_LEFT){
  157. if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
  158. matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
  159. if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
  160. matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev * M_SQRT1_2;
  161. matrix[FRONT_RIGHT][BACK_CENTER] += s->slev * M_SQRT1_2;
  162. } else {
  163. matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev;
  164. matrix[FRONT_RIGHT][BACK_CENTER] += s->slev;
  165. }
  166. } else {
  167. matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2;
  168. matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2;
  169. }
  170. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  171. matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2;
  172. }else
  173. av_assert0(0);
  174. }
  175. if(unaccounted & AV_CH_BACK_LEFT){
  176. if(out_ch_layout & AV_CH_BACK_CENTER){
  177. matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
  178. matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
  179. }else if(out_ch_layout & AV_CH_SIDE_LEFT){
  180. if(in_ch_layout & AV_CH_SIDE_LEFT){
  181. matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
  182. matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
  183. }else{
  184. matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
  185. matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
  186. }
  187. }else if(out_ch_layout & AV_CH_FRONT_LEFT){
  188. if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
  189. matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * M_SQRT1_2;
  190. matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
  191. matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2;
  192. matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * M_SQRT1_2;
  193. } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
  194. matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * SQRT3_2;
  195. matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
  196. matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2;
  197. matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * SQRT3_2;
  198. } else {
  199. matrix[ FRONT_LEFT][ BACK_LEFT] += s->slev;
  200. matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev;
  201. }
  202. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  203. matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2;
  204. matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2;
  205. }else
  206. av_assert0(0);
  207. }
  208. if(unaccounted & AV_CH_SIDE_LEFT){
  209. if(out_ch_layout & AV_CH_BACK_LEFT){
  210. /* if back channels do not exist in the input, just copy side
  211. channels to back channels, otherwise mix side into back */
  212. if (in_ch_layout & AV_CH_BACK_LEFT) {
  213. matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
  214. matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
  215. } else {
  216. matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
  217. matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
  218. }
  219. }else if(out_ch_layout & AV_CH_BACK_CENTER){
  220. matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
  221. matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
  222. }else if(out_ch_layout & AV_CH_FRONT_LEFT){
  223. if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
  224. matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * M_SQRT1_2;
  225. matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
  226. matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2;
  227. matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * M_SQRT1_2;
  228. } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
  229. matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * SQRT3_2;
  230. matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
  231. matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2;
  232. matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * SQRT3_2;
  233. } else {
  234. matrix[ FRONT_LEFT][ SIDE_LEFT] += s->slev;
  235. matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev;
  236. }
  237. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  238. matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2;
  239. matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2;
  240. }else
  241. av_assert0(0);
  242. }
  243. if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
  244. if(out_ch_layout & AV_CH_FRONT_LEFT){
  245. matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
  246. matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
  247. }else if(out_ch_layout & AV_CH_FRONT_CENTER){
  248. matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
  249. matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
  250. }else
  251. av_assert0(0);
  252. }
  253. /* mix LFE into front left/right or center */
  254. if (unaccounted & AV_CH_LOW_FREQUENCY) {
  255. if (out_ch_layout & AV_CH_FRONT_CENTER) {
  256. matrix[FRONT_CENTER][LOW_FREQUENCY] += s->lfe_mix_level;
  257. } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
  258. matrix[FRONT_LEFT ][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
  259. matrix[FRONT_RIGHT][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
  260. } else
  261. av_assert0(0);
  262. }
  263. for(out_i=i=0; i<64; i++){
  264. double sum=0;
  265. int in_i=0;
  266. for(j=0; j<64; j++){
  267. s->matrix[out_i][in_i]= matrix[i][j];
  268. if(matrix[i][j]){
  269. sum += fabs(matrix[i][j]);
  270. }
  271. if(in_ch_layout & (1ULL<<j))
  272. in_i++;
  273. }
  274. maxcoef= FFMAX(maxcoef, sum);
  275. if(out_ch_layout & (1ULL<<i))
  276. out_i++;
  277. }
  278. if(s->rematrix_volume < 0)
  279. maxcoef = -s->rematrix_volume;
  280. if(( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
  281. || av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
  282. for(i=0; i<SWR_CH_MAX; i++)
  283. for(j=0; j<SWR_CH_MAX; j++){
  284. s->matrix[i][j] /= maxcoef;
  285. }
  286. }
  287. if(s->rematrix_volume > 0){
  288. for(i=0; i<SWR_CH_MAX; i++)
  289. for(j=0; j<SWR_CH_MAX; j++){
  290. s->matrix[i][j] *= s->rematrix_volume;
  291. }
  292. }
  293. for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
  294. for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
  295. av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]);
  296. }
  297. av_log(NULL, AV_LOG_DEBUG, "\n");
  298. }
  299. return 0;
  300. }
  301. av_cold int swri_rematrix_init(SwrContext *s){
  302. int i, j;
  303. int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
  304. int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
  305. s->mix_any_f = NULL;
  306. if (!s->rematrix_custom) {
  307. int r = auto_matrix(s);
  308. if (r)
  309. return r;
  310. }
  311. if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
  312. s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
  313. s->native_one = av_mallocz(sizeof(int));
  314. for (i = 0; i < nb_out; i++)
  315. for (j = 0; j < nb_in; j++)
  316. ((int*)s->native_matrix)[i * nb_in + j] = lrintf(s->matrix[i][j] * 32768);
  317. *((int*)s->native_one) = 32768;
  318. s->mix_1_1_f = (mix_1_1_func_type*)copy_s16;
  319. s->mix_2_1_f = (mix_2_1_func_type*)sum2_s16;
  320. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s16(s);
  321. }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
  322. s->native_matrix = av_calloc(nb_in * nb_out, sizeof(float));
  323. s->native_one = av_mallocz(sizeof(float));
  324. for (i = 0; i < nb_out; i++)
  325. for (j = 0; j < nb_in; j++)
  326. ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
  327. *((float*)s->native_one) = 1.0;
  328. s->mix_1_1_f = (mix_1_1_func_type*)copy_float;
  329. s->mix_2_1_f = (mix_2_1_func_type*)sum2_float;
  330. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_float(s);
  331. }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
  332. s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
  333. s->native_one = av_mallocz(sizeof(double));
  334. for (i = 0; i < nb_out; i++)
  335. for (j = 0; j < nb_in; j++)
  336. ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
  337. *((double*)s->native_one) = 1.0;
  338. s->mix_1_1_f = (mix_1_1_func_type*)copy_double;
  339. s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
  340. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
  341. }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
  342. // Only for dithering currently
  343. // s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
  344. s->native_one = av_mallocz(sizeof(int));
  345. // for (i = 0; i < nb_out; i++)
  346. // for (j = 0; j < nb_in; j++)
  347. // ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
  348. *((int*)s->native_one) = 32768;
  349. s->mix_1_1_f = (mix_1_1_func_type*)copy_s32;
  350. s->mix_2_1_f = (mix_2_1_func_type*)sum2_s32;
  351. s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s32(s);
  352. }else
  353. av_assert0(0);
  354. //FIXME quantize for integeres
  355. for (i = 0; i < SWR_CH_MAX; i++) {
  356. int ch_in=0;
  357. for (j = 0; j < SWR_CH_MAX; j++) {
  358. s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768);
  359. if(s->matrix[i][j])
  360. s->matrix_ch[i][++ch_in]= j;
  361. }
  362. s->matrix_ch[i][0]= ch_in;
  363. }
  364. if(HAVE_YASM && HAVE_MMX) swri_rematrix_init_x86(s);
  365. return 0;
  366. }
  367. av_cold void swri_rematrix_free(SwrContext *s){
  368. av_freep(&s->native_matrix);
  369. av_freep(&s->native_one);
  370. av_freep(&s->native_simd_matrix);
  371. av_freep(&s->native_simd_one);
  372. }
  373. int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
  374. int out_i, in_i, i, j;
  375. int len1 = 0;
  376. int off = 0;
  377. if(s->mix_any_f) {
  378. s->mix_any_f(out->ch, (const uint8_t **)in->ch, s->native_matrix, len);
  379. return 0;
  380. }
  381. if(s->mix_2_1_simd || s->mix_1_1_simd){
  382. len1= len&~15;
  383. off = len1 * out->bps;
  384. }
  385. av_assert0(out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
  386. av_assert0(in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
  387. for(out_i=0; out_i<out->ch_count; out_i++){
  388. switch(s->matrix_ch[out_i][0]){
  389. case 0:
  390. if(mustcopy)
  391. memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
  392. break;
  393. case 1:
  394. in_i= s->matrix_ch[out_i][1];
  395. if(s->matrix[out_i][in_i]!=1.0){
  396. if(s->mix_1_1_simd && len1)
  397. 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);
  398. if(len != len1)
  399. 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);
  400. }else if(mustcopy){
  401. memcpy(out->ch[out_i], in->ch[in_i], len*out->bps);
  402. }else{
  403. out->ch[out_i]= in->ch[in_i];
  404. }
  405. break;
  406. case 2: {
  407. int in_i1 = s->matrix_ch[out_i][1];
  408. int in_i2 = s->matrix_ch[out_i][2];
  409. if(s->mix_2_1_simd && len1)
  410. 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);
  411. else
  412. 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);
  413. if(len != len1)
  414. 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);
  415. break;}
  416. default:
  417. if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
  418. for(i=0; i<len; i++){
  419. float v=0;
  420. for(j=0; j<s->matrix_ch[out_i][0]; j++){
  421. in_i= s->matrix_ch[out_i][1+j];
  422. v+= ((float*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
  423. }
  424. ((float*)out->ch[out_i])[i]= v;
  425. }
  426. }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
  427. for(i=0; i<len; i++){
  428. double v=0;
  429. for(j=0; j<s->matrix_ch[out_i][0]; j++){
  430. in_i= s->matrix_ch[out_i][1+j];
  431. v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
  432. }
  433. ((double*)out->ch[out_i])[i]= v;
  434. }
  435. }else{
  436. for(i=0; i<len; i++){
  437. int v=0;
  438. for(j=0; j<s->matrix_ch[out_i][0]; j++){
  439. in_i= s->matrix_ch[out_i][1+j];
  440. v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i];
  441. }
  442. ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15;
  443. }
  444. }
  445. }
  446. }
  447. return 0;
  448. }