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