FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswresample/rematrix.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 238 426 55.9%
Functions: 9 10 90.0%
Branches: 163 314 51.9%

Line Branch Exec Source
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 #define TEMPLATE_CLIP
36 #include "rematrix_template.c"
37 #undef TEMPLATE_CLIP
38 #undef TEMPLATE_REMATRIX_S16
39
40 #define TEMPLATE_REMATRIX_S32
41 #include "rematrix_template.c"
42 #undef TEMPLATE_REMATRIX_S32
43
44 #define FRONT_LEFT 0
45 #define FRONT_RIGHT 1
46 #define FRONT_CENTER 2
47 #define LOW_FREQUENCY 3
48 #define BACK_LEFT 4
49 #define BACK_RIGHT 5
50 #define FRONT_LEFT_OF_CENTER 6
51 #define FRONT_RIGHT_OF_CENTER 7
52 #define BACK_CENTER 8
53 #define SIDE_LEFT 9
54 #define SIDE_RIGHT 10
55 #define TOP_CENTER 11
56 #define TOP_FRONT_LEFT 12
57 #define TOP_FRONT_CENTER 13
58 #define TOP_FRONT_RIGHT 14
59 #define TOP_BACK_LEFT 15
60 #define TOP_BACK_CENTER 16
61 #define TOP_BACK_RIGHT 17
62 #define NUM_NAMED_CHANNELS 18
63
64 8 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
65 {
66 int nb_in, nb_out, in, out;
67 int user_in_chlayout_nb_channels, user_out_chlayout_nb_channels;
68
69
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if (!s || s->in_convert) // s needs to be allocated but not initialized
70 return AVERROR(EINVAL);
71 8 memset(s->matrix, 0, sizeof(s->matrix));
72 8 memset(s->matrix_flt, 0, sizeof(s->matrix_flt));
73
74 #if FF_API_OLD_CHANNEL_LAYOUT
75 FF_DISABLE_DEPRECATION_WARNINGS
76 8 user_in_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_in_ch_layout);
77 FF_ENABLE_DEPRECATION_WARNINGS
78
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!user_in_chlayout_nb_channels)
79 #endif
80 8 user_in_chlayout_nb_channels = s->user_in_chlayout.nb_channels;
81 8 nb_in =
82 #if FF_API_OLD_CHANNEL_LAYOUT
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 (s->user_in_ch_count > 0) ? s->user_in_ch_count :
84 #endif
85 user_in_chlayout_nb_channels;
86 #if FF_API_OLD_CHANNEL_LAYOUT
87 FF_DISABLE_DEPRECATION_WARNINGS
88 8 user_out_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_out_ch_layout);
89 FF_ENABLE_DEPRECATION_WARNINGS
90
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!user_out_chlayout_nb_channels)
91 #endif
92 8 user_out_chlayout_nb_channels = s->user_out_chlayout.nb_channels;
93 8 nb_out =
94 #if FF_API_OLD_CHANNEL_LAYOUT
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 (s->user_out_ch_count > 0) ? s->user_out_ch_count :
96 #endif
97 user_out_chlayout_nb_channels;
98
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 8 times.
35 for (out = 0; out < nb_out; out++) {
99
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 27 times.
150 for (in = 0; in < nb_in; in++)
100 123 s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in];
101 27 matrix += stride;
102 }
103 8 s->rematrix_custom = 1;
104 8 return 0;
105 }
106
107 180 static int even(int64_t layout){
108
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 16 times.
180 if(!layout) return 1;
109
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(layout&(layout-1)) return 1;
110 return 0;
111 }
112
113 36 static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)
114 {
115 36 int ret = 0;
116
117
4/4
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 11 times.
36 if (av_channel_layout_index_from_channel(in, AV_CHAN_FRONT_CENTER) < 0 && in->nb_channels == 1) {
118 char buf[128];
119 7 av_channel_layout_describe(in, buf, sizeof(buf));
120 7 av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
121 7 *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
122 } else
123 29 ret = av_channel_layout_copy(out, in);
124
125 36 return ret;
126 }
127
128 36 static int sane_layout(AVChannelLayout *ch_layout) {
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
130 return 0;
131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
132 return 0;
133
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)))) // no asymetric front
134 return 0;
135
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 if(!even(av_channel_layout_subset(ch_layout, (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)))) // no asymetric side
136 return 0;
137
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 if(!even(av_channel_layout_subset(ch_layout, (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))))
138 return 0;
139
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))))
140 return 0;
141
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 if(!even(av_channel_layout_subset(ch_layout, (AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT))))
142 return 0;
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if(ch_layout->nb_channels >= SWR_CH_MAX)
144 return 0;
145
146 36 return 1;
147 }
148
149 #if FF_API_OLD_CHANNEL_LAYOUT
150 av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param,
151 double center_mix_level, double surround_mix_level,
152 double lfe_mix_level, double maxval,
153 double rematrix_volume, double *matrix_param,
154 int stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
155 {
156 AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
157 int ret;
158
159 ret = av_channel_layout_from_mask(&in_ch_layout, in_ch_layout_param);
160 ret |= av_channel_layout_from_mask(&out_ch_layout, out_ch_layout_param);
161 if (ret < 0)
162 return ret;
163
164 return swr_build_matrix2(&in_ch_layout, &out_ch_layout, center_mix_level, surround_mix_level,
165 lfe_mix_level, maxval, rematrix_volume, matrix_param,
166 stride, matrix_encoding, log_context);
167 }
168 #endif
169
170 18 av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
171 double center_mix_level, double surround_mix_level,
172 double lfe_mix_level, double maxval,
173 double rematrix_volume, double *matrix_param,
174 ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
175 {
176 int i, j, out_i, ret;
177 18 AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
178 18 double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
179 int64_t unaccounted;
180 18 double maxcoef=0;
181 char buf[128];
182
183 18 ret = clean_layout(&in_ch_layout, in_layout, log_context);
184 18 ret |= clean_layout(&out_ch_layout, out_layout, log_context);
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (ret < 0)
186 goto fail;
187
188
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if( !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
189 && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
190 ) {
191 av_channel_layout_uninit(&out_ch_layout);
192 out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
193 }
194
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if( !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
195 && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
196 ) {
197 av_channel_layout_uninit(&in_ch_layout);
198 in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
199 }
200
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
201 av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
202 av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
203 av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
204 av_log(log_context, AV_LOG_WARNING,
205 "Full-on remixing from 22.2 has not yet been implemented! "
206 "Processing the input as '%s'\n",
207 buf);
208 }
209
210
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(!av_channel_layout_check(&in_ch_layout)) {
211 av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
212 ret = AVERROR(EINVAL);
213 goto fail;
214 }
215
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(!sane_layout(&in_ch_layout)) {
216 av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
217 av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
218 ret = AVERROR(EINVAL);
219 goto fail;
220 }
221
222
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(!av_channel_layout_check(&out_ch_layout)) {
223 av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
224 ret = AVERROR(EINVAL);
225 goto fail;
226 }
227
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(!sane_layout(&out_ch_layout)) {
228 av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
229 av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
230 ret = AVERROR(EINVAL);
231 goto fail;
232 }
233
234
2/2
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 18 times.
342 for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
235
2/2
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 292 times.
324 if( av_channel_layout_index_from_channel(&in_ch_layout, i) >= 0
236
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 21 times.
32 && av_channel_layout_index_from_channel(&out_ch_layout, i) >= 0)
237 11 matrix[i][i]= 1.0;
238 }
239
240 18 unaccounted = in_ch_layout.u.mask & ~out_ch_layout.u.mask;
241
242 //FIXME implement dolby surround
243 //FIXME implement full ac3
244
245
246
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14 times.
18 if(unaccounted & AV_CH_FRONT_CENTER){
247
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) {
248
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
4 if (av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) {
249 1 matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
250 1 matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
251 } else {
252 3 matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2;
253 3 matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2;
254 }
255 }else
256 av_assert0(0);
257 }
258
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 if(unaccounted & AV_CH_LAYOUT_STEREO){
259
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
260 6 matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
261 6 matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
262
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
263 matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
264 }else
265 av_assert0(0);
266 }
267
268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(unaccounted & AV_CH_BACK_CENTER){
269 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
270 matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
271 matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
272 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
273 matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
274 matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
275 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
276 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
277 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
278 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
279 matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level * M_SQRT1_2;
280 matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
281 } else {
282 matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level;
283 matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level;
284 }
285 } else {
286 matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
287 matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
288 }
289 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
290 matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
291 }else
292 av_assert0(0);
293 }
294
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
18 if(unaccounted & AV_CH_BACK_LEFT){
295
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
296 matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
297 matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
298
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
299 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
300 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
301 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
302 }else{
303 matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
304 matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
305 }
306
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
308 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
309 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
310 matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
311 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * M_SQRT1_2;
312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
313 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * SQRT3_2;
314 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
315 matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
316 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * SQRT3_2;
317 } else {
318 1 matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
319 1 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
320 }
321 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
322 matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
323 matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
324 }else
325 av_assert0(0);
326 }
327
328
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
18 if(unaccounted & AV_CH_SIDE_LEFT){
329
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
330 /* if back channels do not exist in the input, just copy side
331 channels to back channels, otherwise mix side into back */
332 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
333 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
334 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
335 } else {
336 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
337 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
338 }
339
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
340 matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
341 matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
342
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
344 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
345 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
346 matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
347 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * M_SQRT1_2;
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
349 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * SQRT3_2;
350 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
351 matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
352 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * SQRT3_2;
353 } else {
354 1 matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
355 1 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
356 }
357 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
358 matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
359 matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
360 }else
361 av_assert0(0);
362 }
363
364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
365 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
366 matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
367 matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
368 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
369 matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
370 matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
371 }else
372 av_assert0(0);
373 }
374
375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (unaccounted & AV_CH_TOP_FRONT_LEFT) {
376 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0) {
377 matrix[TOP_FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
378 matrix[TOP_FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
379 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)
380 matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2);
381 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
382 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
383 matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += M_SQRT1_2;
384 matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += M_SQRT1_2;
385 } else {
386 matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0;
387 matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += 1.0;
388 }
389 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
390 matrix[FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
391 matrix[FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
392 } else
393 av_assert0(0);
394 }
395
396 /* mix LFE into front left/right or center */
397
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
18 if (unaccounted & AV_CH_LOW_FREQUENCY) {
398
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
399 matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
400
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
401 1 matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
402 1 matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
403 } else
404 av_assert0(0);
405 }
406
407
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(out_i=i=0; i<64; i++){
408 1152 double sum=0;
409 1152 int in_i=0;
410
2/2
✓ Branch 1 taken 1125 times.
✓ Branch 2 taken 27 times.
1152 if (av_channel_layout_index_from_channel(&out_ch_layout, i) < 0)
411 1125 continue;
412
2/2
✓ Branch 0 taken 1728 times.
✓ Branch 1 taken 27 times.
1755 for(j=0; j<64; j++){
413
2/2
✓ Branch 1 taken 1675 times.
✓ Branch 2 taken 53 times.
1728 if (av_channel_layout_index_from_channel(&in_ch_layout, j) < 0)
414 1675 continue;
415
2/4
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
✗ Branch 3 not taken.
53 if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
416 53 matrix_param[stride*out_i + in_i] = matrix[i][j];
417 else
418 matrix_param[stride*out_i + in_i] = i == j &&
419 ( av_channel_layout_index_from_channel(&in_ch_layout, i) >= 0
420 && av_channel_layout_index_from_channel(&out_ch_layout, i) >= 0);
421 53 sum += fabs(matrix_param[stride*out_i + in_i]);
422 53 in_i++;
423 }
424
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 23 times.
27 maxcoef= FFMAX(maxcoef, sum);
425 27 out_i++;
426 }
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(rematrix_volume < 0)
428 maxcoef = -rematrix_volume;
429
430
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
18 if(maxcoef > maxval || rematrix_volume < 0){
431 7 maxcoef /= maxval;
432
2/2
✓ Branch 0 taken 448 times.
✓ Branch 1 taken 7 times.
455 for(i=0; i<SWR_CH_MAX; i++)
433
2/2
✓ Branch 0 taken 28672 times.
✓ Branch 1 taken 448 times.
29120 for(j=0; j<SWR_CH_MAX; j++){
434 28672 matrix_param[stride*i + j] /= maxcoef;
435 }
436 }
437
438
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(rematrix_volume > 0){
439
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(i=0; i<SWR_CH_MAX; i++)
440
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 1152 times.
74880 for(j=0; j<SWR_CH_MAX; j++){
441 73728 matrix_param[stride*i + j] *= rematrix_volume;
442 }
443 }
444
445 18 av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n");
446
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 18 times.
45 for (i = 0; i < out_ch_layout.nb_channels; i++){
447 27 av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&out_ch_layout, i));
448 27 av_log(log_context, AV_LOG_DEBUG, "%s: ", buf);
449
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 27 times.
80 for (j = 0; j < in_ch_layout.nb_channels; j++){
450 53 av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&in_ch_layout, j));
451 53 av_log(log_context, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]);
452 }
453 27 av_log(log_context, AV_LOG_DEBUG, "\n");
454 }
455
456 18 ret = 0;
457 18 fail:
458 18 av_channel_layout_uninit(&in_ch_layout);
459 18 av_channel_layout_uninit(&out_ch_layout);
460
461 18 return ret;
462 }
463
464 18 av_cold static int auto_matrix(SwrContext *s)
465 {
466 double maxval;
467 int ret;
468
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (s->rematrix_maxval > 0) {
470 maxval = s->rematrix_maxval;
471
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 17 times.
18 } else if ( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
472
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 || av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) {
473 17 maxval = 1.0;
474 } else
475 1 maxval = INT_MAX;
476
477 18 memset(s->matrix, 0, sizeof(s->matrix));
478 18 ret = swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout,
479 18 s->clev, s->slev, s->lfe_mix_level,
480 18 maxval, s->rematrix_volume, (double*)s->matrix,
481 18 s->matrix[1] - s->matrix[0], s->matrix_encoding, s);
482
483
3/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 11 times.
18 if (ret >= 0 && s->int_sample_fmt == AV_SAMPLE_FMT_FLTP) {
484 int i, j;
485
2/2
✓ Branch 0 taken 448 times.
✓ Branch 1 taken 7 times.
455 for (i = 0; i < FF_ARRAY_ELEMS(s->matrix[0]); i++)
486
2/2
✓ Branch 0 taken 28672 times.
✓ Branch 1 taken 448 times.
29120 for (j = 0; j < FF_ARRAY_ELEMS(s->matrix[0]); j++)
487 28672 s->matrix_flt[i][j] = s->matrix[i][j];
488 }
489
490 18 return ret;
491 }
492
493 26 av_cold int swri_rematrix_init(SwrContext *s){
494 int i, j;
495 26 int nb_in = s->used_ch_layout.nb_channels;
496 26 int nb_out = s->out.ch_count;
497
498 26 s->mix_any_f = NULL;
499
500
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
26 if (!s->rematrix_custom) {
501 18 int r = auto_matrix(s);
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (r)
503 return r;
504 }
505
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 7 times.
26 if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
506 19 int maxsum = 0;
507 19 s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
508 19 s->native_one = av_mallocz(sizeof(int));
509
2/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
19 if (!s->native_matrix || !s->native_one)
510 return AVERROR(ENOMEM);
511
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 19 times.
60 for (i = 0; i < nb_out; i++) {
512 41 double rem = 0;
513 41 int sum = 0;
514
515
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 41 times.
193 for (j = 0; j < nb_in; j++) {
516 152 double target = s->matrix[i][j] * 32768 + rem;
517 152 ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
518 152 rem += target - ((int*)s->native_matrix)[i * nb_in + j];
519 152 sum += FFABS(((int*)s->native_matrix)[i * nb_in + j]);
520 }
521 41 maxsum = FFMAX(maxsum, sum);
522 }
523 19 *((int*)s->native_one) = 32768;
524
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 8 times.
19 if (maxsum <= 32768) {
525 11 s->mix_1_1_f = (mix_1_1_func_type*)copy_s16;
526 11 s->mix_2_1_f = (mix_2_1_func_type*)sum2_s16;
527 11 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s16(s);
528 } else {
529 8 s->mix_1_1_f = (mix_1_1_func_type*)copy_clip_s16;
530 8 s->mix_2_1_f = (mix_2_1_func_type*)sum2_clip_s16;
531 8 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_clip_s16(s);
532 }
533
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
534 7 s->native_matrix = av_calloc(nb_in * nb_out, sizeof(float));
535 7 s->native_one = av_mallocz(sizeof(float));
536
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
7 if (!s->native_matrix || !s->native_one)
537 return AVERROR(ENOMEM);
538
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 7 times.
20 for (i = 0; i < nb_out; i++)
539
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 13 times.
37 for (j = 0; j < nb_in; j++)
540 24 ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
541 7 *((float*)s->native_one) = 1.0;
542 7 s->mix_1_1_f = (mix_1_1_func_type*)copy_float;
543 7 s->mix_2_1_f = (mix_2_1_func_type*)sum2_float;
544 7 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_float(s);
545 }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
546 s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
547 s->native_one = av_mallocz(sizeof(double));
548 if (!s->native_matrix || !s->native_one)
549 return AVERROR(ENOMEM);
550 for (i = 0; i < nb_out; i++)
551 for (j = 0; j < nb_in; j++)
552 ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
553 *((double*)s->native_one) = 1.0;
554 s->mix_1_1_f = (mix_1_1_func_type*)copy_double;
555 s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
556 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
557 }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
558 s->native_one = av_mallocz(sizeof(int));
559 if (!s->native_one)
560 return AVERROR(ENOMEM);
561 s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
562 if (!s->native_matrix) {
563 av_freep(&s->native_one);
564 return AVERROR(ENOMEM);
565 }
566 for (i = 0; i < nb_out; i++) {
567 double rem = 0;
568
569 for (j = 0; j < nb_in; j++) {
570 double target = s->matrix[i][j] * 32768 + rem;
571 ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
572 rem += target - ((int*)s->native_matrix)[i * nb_in + j];
573 }
574 }
575 *((int*)s->native_one) = 32768;
576 s->mix_1_1_f = (mix_1_1_func_type*)copy_s32;
577 s->mix_2_1_f = (mix_2_1_func_type*)sum2_s32;
578 s->mix_any_f = (mix_any_func_type*)get_mix_any_func_s32(s);
579 }else
580 av_assert0(0);
581 //FIXME quantize for integeres
582
2/2
✓ Branch 0 taken 1664 times.
✓ Branch 1 taken 26 times.
1690 for (i = 0; i < SWR_CH_MAX; i++) {
583 1664 int ch_in=0;
584
2/2
✓ Branch 0 taken 106496 times.
✓ Branch 1 taken 1664 times.
108160 for (j = 0; j < SWR_CH_MAX; j++) {
585 106496 s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768);
586
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 106415 times.
106496 if(s->matrix[i][j])
587 81 s->matrix_ch[i][++ch_in]= j;
588 }
589 1664 s->matrix_ch[i][0]= ch_in;
590 }
591
592 #if ARCH_X86 && HAVE_X86ASM && HAVE_MMX
593 26 return swri_rematrix_init_x86(s);
594 #endif
595
596 return 0;
597 }
598
599 3586 av_cold void swri_rematrix_free(SwrContext *s){
600 3586 av_freep(&s->native_matrix);
601 3586 av_freep(&s->native_one);
602 3586 av_freep(&s->native_simd_matrix);
603 3586 av_freep(&s->native_simd_one);
604 3586 }
605
606 1929 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
607 int out_i, in_i, i, j;
608 1929 int len1 = 0;
609 1929 int off = 0;
610
611
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1925 times.
1929 if(s->mix_any_f) {
612 4 s->mix_any_f(out->ch, (const uint8_t **)in->ch, s->native_matrix, len);
613 4 return 0;
614 }
615
616
3/4
✓ Branch 0 taken 1878 times.
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1878 times.
1925 if(s->mix_2_1_simd || s->mix_1_1_simd){
617 47 len1= len&~15;
618 47 off = len1 * out->bps;
619 }
620
621
3/4
✓ Branch 0 taken 1905 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1905 times.
1925 av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels);
622
3/4
✓ Branch 0 taken 1905 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1905 times.
1925 av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels);
623
624
2/2
✓ Branch 0 taken 3057 times.
✓ Branch 1 taken 1925 times.
4982 for(out_i=0; out_i<out->ch_count; out_i++){
625
3/4
✓ Branch 0 taken 532 times.
✓ Branch 1 taken 1510 times.
✓ Branch 2 taken 1015 times.
✗ Branch 3 not taken.
3057 switch(s->matrix_ch[out_i][0]){
626 532 case 0:
627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 532 times.
532 if(mustcopy)
628 memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
629 532 break;
630 1510 case 1:
631 1510 in_i= s->matrix_ch[out_i][1];
632
2/2
✓ Branch 0 taken 274 times.
✓ Branch 1 taken 1236 times.
1510 if(s->matrix[out_i][in_i]!=1.0){
633
3/4
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 94 times.
✗ Branch 3 not taken.
274 if(s->mix_1_1_simd && len1)
634 94 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);
635
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 94 times.
274 if(len != len1)
636 180 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);
637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1236 times.
1236 }else if(mustcopy){
638 memcpy(out->ch[out_i], in->ch[in_i], len*out->bps);
639 }else{
640 1236 out->ch[out_i]= in->ch[in_i];
641 }
642 1510 break;
643 1015 case 2: {
644 1015 int in_i1 = s->matrix_ch[out_i][1];
645 1015 int in_i2 = s->matrix_ch[out_i][2];
646
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1015 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1015 if(s->mix_2_1_simd && len1)
647 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);
648 else
649 1015 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);
650
2/2
✓ Branch 0 taken 1013 times.
✓ Branch 1 taken 2 times.
1015 if(len != len1)
651 1013 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);
652 1015 break;}
653 default:
654 if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
655 for(i=0; i<len; i++){
656 float v=0;
657 for(j=0; j<s->matrix_ch[out_i][0]; j++){
658 in_i= s->matrix_ch[out_i][1+j];
659 v+= ((float*)in->ch[in_i])[i] * s->matrix_flt[out_i][in_i];
660 }
661 ((float*)out->ch[out_i])[i]= v;
662 }
663 }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
664 for(i=0; i<len; i++){
665 double v=0;
666 for(j=0; j<s->matrix_ch[out_i][0]; j++){
667 in_i= s->matrix_ch[out_i][1+j];
668 v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
669 }
670 ((double*)out->ch[out_i])[i]= v;
671 }
672 }else{
673 for(i=0; i<len; i++){
674 int v=0;
675 for(j=0; j<s->matrix_ch[out_i][0]; j++){
676 in_i= s->matrix_ch[out_i][1+j];
677 v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i];
678 }
679 ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15;
680 }
681 }
682 }
683 }
684 1925 return 0;
685 }
686