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.

491 lines
18KB

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