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