00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "swresample_internal.h"
00022 #include "libavutil/audioconvert.h"
00023 #include "libavutil/avassert.h"
00024
00025 #define ONE (1.0)
00026 #define R(x) x
00027 #define SAMPLE float
00028 #define COEFF float
00029 #define INTER float
00030 #define RENAME(x) x ## _float
00031 #include "rematrix_template.c"
00032 #undef SAMPLE
00033 #undef RENAME
00034 #undef R
00035 #undef ONE
00036 #undef COEFF
00037 #undef INTER
00038
00039 #define ONE (1.0)
00040 #define R(x) x
00041 #define SAMPLE double
00042 #define COEFF double
00043 #define INTER double
00044 #define RENAME(x) x ## _double
00045 #include "rematrix_template.c"
00046 #undef SAMPLE
00047 #undef RENAME
00048 #undef R
00049 #undef ONE
00050 #undef COEFF
00051 #undef INTER
00052
00053 #define ONE (-32768)
00054 #define R(x) (((x) + 16384)>>15)
00055 #define SAMPLE int16_t
00056 #define COEFF int
00057 #define INTER int
00058 #define RENAME(x) x ## _s16
00059 #include "rematrix_template.c"
00060
00061
00062 #define FRONT_LEFT 0
00063 #define FRONT_RIGHT 1
00064 #define FRONT_CENTER 2
00065 #define LOW_FREQUENCY 3
00066 #define BACK_LEFT 4
00067 #define BACK_RIGHT 5
00068 #define FRONT_LEFT_OF_CENTER 6
00069 #define FRONT_RIGHT_OF_CENTER 7
00070 #define BACK_CENTER 8
00071 #define SIDE_LEFT 9
00072 #define SIDE_RIGHT 10
00073 #define TOP_CENTER 11
00074 #define TOP_FRONT_LEFT 12
00075 #define TOP_FRONT_CENTER 13
00076 #define TOP_FRONT_RIGHT 14
00077 #define TOP_BACK_LEFT 15
00078 #define TOP_BACK_CENTER 16
00079 #define TOP_BACK_RIGHT 17
00080
00081 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
00082 {
00083 int nb_in, nb_out, in, out;
00084
00085 if (!s || s->in_convert)
00086 return AVERROR(EINVAL);
00087 memset(s->matrix, 0, sizeof(s->matrix));
00088 nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
00089 nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
00090 for (out = 0; out < nb_out; out++) {
00091 for (in = 0; in < nb_in; in++)
00092 s->matrix[out][in] = matrix[in];
00093 matrix += stride;
00094 }
00095 s->rematrix_custom = 1;
00096 return 0;
00097 }
00098
00099 static int even(int64_t layout){
00100 if(!layout) return 1;
00101 if(layout&(layout-1)) return 1;
00102 return 0;
00103 }
00104
00105 static int clean_layout(SwrContext *s, int64_t layout){
00106 if((layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == AV_CH_LAYOUT_STEREO_DOWNMIX)
00107 return AV_CH_LAYOUT_STEREO;
00108
00109 if(layout && layout != AV_CH_FRONT_CENTER && !(layout&(layout-1))) {
00110 char buf[128];
00111 av_get_channel_layout_string(buf, sizeof(buf), -1, layout);
00112 av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
00113 return AV_CH_FRONT_CENTER;
00114 }
00115
00116 return layout;
00117 }
00118
00119 static int sane_layout(int64_t layout){
00120 if(!(layout & AV_CH_LAYOUT_SURROUND))
00121 return 0;
00122 if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)))
00123 return 0;
00124 if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)))
00125 return 0;
00126 if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))
00127 return 0;
00128 if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))
00129 return 0;
00130 if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX)
00131 return 0;
00132
00133 return 1;
00134 }
00135
00136 av_cold static int auto_matrix(SwrContext *s)
00137 {
00138 int i, j, out_i;
00139 double matrix[64][64]={{0}};
00140 int64_t unaccounted, in_ch_layout, out_ch_layout;
00141 double maxcoef=0;
00142 char buf[128];
00143 const int matrix_encoding = s->matrix_encoding;
00144
00145 in_ch_layout = clean_layout(s, s->in_ch_layout);
00146 if(!sane_layout(in_ch_layout)){
00147 av_get_channel_layout_string(buf, sizeof(buf), -1, s->in_ch_layout);
00148 av_log(s, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
00149 return AVERROR(EINVAL);
00150 }
00151
00152 out_ch_layout = clean_layout(s, s->out_ch_layout);
00153 if(!sane_layout(out_ch_layout)){
00154 av_get_channel_layout_string(buf, sizeof(buf), -1, s->out_ch_layout);
00155 av_log(s, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
00156 return AVERROR(EINVAL);
00157 }
00158
00159 memset(s->matrix, 0, sizeof(s->matrix));
00160 for(i=0; i<64; i++){
00161 if(in_ch_layout & out_ch_layout & (1LL<<i))
00162 matrix[i][i]= 1.0;
00163 }
00164
00165 unaccounted= in_ch_layout & ~out_ch_layout;
00166
00167
00168
00169
00170
00171 if(unaccounted & AV_CH_FRONT_CENTER){
00172 if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
00173 if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
00174 matrix[ FRONT_LEFT][FRONT_CENTER]+= s->clev;
00175 matrix[FRONT_RIGHT][FRONT_CENTER]+= s->clev;
00176 } else {
00177 matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2;
00178 matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2;
00179 }
00180 }else
00181 av_assert0(0);
00182 }
00183 if(unaccounted & AV_CH_LAYOUT_STEREO){
00184 if(out_ch_layout & AV_CH_FRONT_CENTER){
00185 matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
00186 matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
00187 if(in_ch_layout & AV_CH_FRONT_CENTER)
00188 matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2);
00189 }else
00190 av_assert0(0);
00191 }
00192
00193 if(unaccounted & AV_CH_BACK_CENTER){
00194 if(out_ch_layout & AV_CH_BACK_LEFT){
00195 matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
00196 matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
00197 }else if(out_ch_layout & AV_CH_SIDE_LEFT){
00198 matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
00199 matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
00200 }else if(out_ch_layout & AV_CH_FRONT_LEFT){
00201 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
00202 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
00203 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
00204 matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev * M_SQRT1_2;
00205 matrix[FRONT_RIGHT][BACK_CENTER] += s->slev * M_SQRT1_2;
00206 } else {
00207 matrix[FRONT_LEFT ][BACK_CENTER] -= s->slev;
00208 matrix[FRONT_RIGHT][BACK_CENTER] += s->slev;
00209 }
00210 } else {
00211 matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2;
00212 matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2;
00213 }
00214 }else if(out_ch_layout & AV_CH_FRONT_CENTER){
00215 matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2;
00216 }else
00217 av_assert0(0);
00218 }
00219 if(unaccounted & AV_CH_BACK_LEFT){
00220 if(out_ch_layout & AV_CH_BACK_CENTER){
00221 matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
00222 matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
00223 }else if(out_ch_layout & AV_CH_SIDE_LEFT){
00224 if(in_ch_layout & AV_CH_SIDE_LEFT){
00225 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
00226 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
00227 }else{
00228 matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
00229 matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
00230 }
00231 }else if(out_ch_layout & AV_CH_FRONT_LEFT){
00232 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
00233 matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * M_SQRT1_2;
00234 matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
00235 matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2;
00236 matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * M_SQRT1_2;
00237 } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
00238 matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * SQRT3_2;
00239 matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
00240 matrix[FRONT_RIGHT][BACK_LEFT ] += s->slev * M_SQRT1_2;
00241 matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev * SQRT3_2;
00242 } else {
00243 matrix[ FRONT_LEFT][ BACK_LEFT] += s->slev;
00244 matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev;
00245 }
00246 }else if(out_ch_layout & AV_CH_FRONT_CENTER){
00247 matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2;
00248 matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2;
00249 }else
00250 av_assert0(0);
00251 }
00252
00253 if(unaccounted & AV_CH_SIDE_LEFT){
00254 if(out_ch_layout & AV_CH_BACK_LEFT){
00255
00256
00257 if (in_ch_layout & AV_CH_BACK_LEFT) {
00258 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
00259 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
00260 } else {
00261 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
00262 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
00263 }
00264 }else if(out_ch_layout & AV_CH_BACK_CENTER){
00265 matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
00266 matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
00267 }else if(out_ch_layout & AV_CH_FRONT_LEFT){
00268 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
00269 matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * M_SQRT1_2;
00270 matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
00271 matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2;
00272 matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * M_SQRT1_2;
00273 } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
00274 matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * SQRT3_2;
00275 matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
00276 matrix[FRONT_RIGHT][SIDE_LEFT ] += s->slev * M_SQRT1_2;
00277 matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev * SQRT3_2;
00278 } else {
00279 matrix[ FRONT_LEFT][ SIDE_LEFT] += s->slev;
00280 matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev;
00281 }
00282 }else if(out_ch_layout & AV_CH_FRONT_CENTER){
00283 matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2;
00284 matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2;
00285 }else
00286 av_assert0(0);
00287 }
00288
00289 if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
00290 if(out_ch_layout & AV_CH_FRONT_LEFT){
00291 matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
00292 matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
00293 }else if(out_ch_layout & AV_CH_FRONT_CENTER){
00294 matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
00295 matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
00296 }else
00297 av_assert0(0);
00298 }
00299
00300 if (unaccounted & AV_CH_LOW_FREQUENCY) {
00301 if (out_ch_layout & AV_CH_FRONT_CENTER) {
00302 matrix[FRONT_CENTER][LOW_FREQUENCY] += s->lfe_mix_level;
00303 } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
00304 matrix[FRONT_LEFT ][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
00305 matrix[FRONT_RIGHT][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
00306 } else
00307 av_assert0(0);
00308 }
00309
00310 for(out_i=i=0; i<64; i++){
00311 double sum=0;
00312 int in_i=0;
00313 for(j=0; j<64; j++){
00314 s->matrix[out_i][in_i]= matrix[i][j];
00315 if(matrix[i][j]){
00316 sum += fabs(matrix[i][j]);
00317 }
00318 if(in_ch_layout & (1ULL<<j))
00319 in_i++;
00320 }
00321 maxcoef= FFMAX(maxcoef, sum);
00322 if(out_ch_layout & (1ULL<<i))
00323 out_i++;
00324 }
00325 if(s->rematrix_volume < 0)
00326 maxcoef = -s->rematrix_volume;
00327
00328 if(( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
00329 || av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
00330 for(i=0; i<SWR_CH_MAX; i++)
00331 for(j=0; j<SWR_CH_MAX; j++){
00332 s->matrix[i][j] /= maxcoef;
00333 }
00334 }
00335
00336 if(s->rematrix_volume > 0){
00337 for(i=0; i<SWR_CH_MAX; i++)
00338 for(j=0; j<SWR_CH_MAX; j++){
00339 s->matrix[i][j] *= s->rematrix_volume;
00340 }
00341 }
00342
00343 for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
00344 for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
00345 av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]);
00346 }
00347 av_log(NULL, AV_LOG_DEBUG, "\n");
00348 }
00349 return 0;
00350 }
00351
00352 av_cold int swri_rematrix_init(SwrContext *s){
00353 int i, j;
00354 int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
00355 int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
00356
00357 s->mix_any_f = NULL;
00358
00359 if (!s->rematrix_custom) {
00360 int r = auto_matrix(s);
00361 if (r)
00362 return r;
00363 }
00364 if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
00365 s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(int));
00366 s->native_one = av_mallocz(sizeof(int));
00367 for (i = 0; i < nb_out; i++)
00368 for (j = 0; j < nb_in; j++)
00369 ((int*)s->native_matrix)[i * nb_in + j] = lrintf(s->matrix[i][j] * 32768);
00370 *((int*)s->native_one) = 32768;
00371 s->mix_1_1_f = (mix_1_1_func_type*)copy_s16;
00372 s->mix_2_1_f = (mix_2_1_func_type*)sum2_s16;
00373 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s16(s);
00374 }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
00375 s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(float));
00376 s->native_one = av_mallocz(sizeof(float));
00377 for (i = 0; i < nb_out; i++)
00378 for (j = 0; j < nb_in; j++)
00379 ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
00380 *((float*)s->native_one) = 1.0;
00381 s->mix_1_1_f = (mix_1_1_func_type*)copy_float;
00382 s->mix_2_1_f = (mix_2_1_func_type*)sum2_float;
00383 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_float(s);
00384 }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
00385 s->native_matrix = av_mallocz(nb_in * nb_out * sizeof(double));
00386 s->native_one = av_mallocz(sizeof(double));
00387 for (i = 0; i < nb_out; i++)
00388 for (j = 0; j < nb_in; j++)
00389 ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
00390 *((double*)s->native_one) = 1.0;
00391 s->mix_1_1_f = (mix_1_1_func_type*)copy_double;
00392 s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
00393 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
00394 }else
00395 av_assert0(0);
00396
00397 for (i = 0; i < SWR_CH_MAX; i++) {
00398 int ch_in=0;
00399 for (j = 0; j < SWR_CH_MAX; j++) {
00400 s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768);
00401 if(s->matrix[i][j])
00402 s->matrix_ch[i][++ch_in]= j;
00403 }
00404 s->matrix_ch[i][0]= ch_in;
00405 }
00406
00407 if(HAVE_YASM && HAVE_MMX) swri_rematrix_init_x86(s);
00408
00409 return 0;
00410 }
00411
00412 av_cold void swri_rematrix_free(SwrContext *s){
00413 av_freep(&s->native_matrix);
00414 av_freep(&s->native_one);
00415 av_freep(&s->native_simd_matrix);
00416 }
00417
00418 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
00419 int out_i, in_i, i, j;
00420 int len1 = 0;
00421 int off = 0;
00422
00423 if(s->mix_any_f) {
00424 s->mix_any_f(out->ch, (const uint8_t **)in->ch, s->native_matrix, len);
00425 return 0;
00426 }
00427
00428 if(s->mix_2_1_simd || s->mix_1_1_simd){
00429 len1= len&~15;
00430 off = len1 * out->bps;
00431 }
00432
00433 av_assert0(out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
00434 av_assert0(in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
00435
00436 for(out_i=0; out_i<out->ch_count; out_i++){
00437 switch(s->matrix_ch[out_i][0]){
00438 case 0:
00439 if(mustcopy)
00440 memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
00441 break;
00442 case 1:
00443 in_i= s->matrix_ch[out_i][1];
00444 if(s->matrix[out_i][in_i]!=1.0){
00445 if(s->mix_1_1_simd && len1)
00446 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);
00447 if(len != len1)
00448 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);
00449 }else if(mustcopy){
00450 memcpy(out->ch[out_i], in->ch[in_i], len*out->bps);
00451 }else{
00452 out->ch[out_i]= in->ch[in_i];
00453 }
00454 break;
00455 case 2: {
00456 int in_i1 = s->matrix_ch[out_i][1];
00457 int in_i2 = s->matrix_ch[out_i][2];
00458 if(s->mix_2_1_simd && len1)
00459 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);
00460 else
00461 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);
00462 if(len != len1)
00463 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);
00464 break;}
00465 default:
00466 if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
00467 for(i=0; i<len; i++){
00468 float v=0;
00469 for(j=0; j<s->matrix_ch[out_i][0]; j++){
00470 in_i= s->matrix_ch[out_i][1+j];
00471 v+= ((float*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
00472 }
00473 ((float*)out->ch[out_i])[i]= v;
00474 }
00475 }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
00476 for(i=0; i<len; i++){
00477 double v=0;
00478 for(j=0; j<s->matrix_ch[out_i][0]; j++){
00479 in_i= s->matrix_ch[out_i][1+j];
00480 v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
00481 }
00482 ((double*)out->ch[out_i])[i]= v;
00483 }
00484 }else{
00485 for(i=0; i<len; i++){
00486 int v=0;
00487 for(j=0; j<s->matrix_ch[out_i][0]; j++){
00488 in_i= s->matrix_ch[out_i][1+j];
00489 v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i];
00490 }
00491 ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15;
00492 }
00493 }
00494 }
00495 }
00496 return 0;
00497 }