History

swresample/rematrix: split filling the matrix array into its own function

James Almer committed 1 year ago

Commit e52701d1 parent 33679f51 file · +106 −96Browse files

Unified · Split

libswresample/rematrix.c+106−96
@@ -124,85 +124,28 @@ static int sane_layout(AVChannelLayout *ch_layout) { · 123 unmodified lines
124 return 1;124 return 1;
125}125}
126 126
127av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,127static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLayout *out_ch_layout,
128 double center_mix_level, double surround_mix_level,128 double center_mix_level, double surround_mix_level,
129 double lfe_mix_level, double maxval,129 double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param,
130 double rematrix_volume, double *matrix_param,130 ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding)
131 ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
132{131{
133 int i, j, out_i, ret;
134 AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
135 double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};132 double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
136 int64_t unaccounted;133 uint64_t unaccounted = in_ch_layout->u.mask & ~out_ch_layout->u.mask;
137 double maxcoef=0;134 double maxcoef=0;
138 char buf[128];135 int i, j, out_i;
139
140 ret = clean_layout(&in_ch_layout, in_layout, log_context);
141 ret |= clean_layout(&out_ch_layout, out_layout, log_context);
142 if (ret < 0)
143 goto fail;
144
145 if( !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
146 && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
147 ) {
148 av_channel_layout_uninit(&out_ch_layout);
149 out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
150 }
151 if( !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
152 && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
153 ) {
154 av_channel_layout_uninit(&in_ch_layout);
155 in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
156 }
157 if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
158 av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
159 av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
160 av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
161 av_log(log_context, AV_LOG_WARNING,
162 "Full-on remixing from 22.2 has not yet been implemented! "
163 "Processing the input as '%s'\n",
164 buf);
165 }
166
167 if(!av_channel_layout_check(&in_ch_layout)) {
168 av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
169 ret = AVERROR(EINVAL);
170 goto fail;
171 }
172 if(!sane_layout(&in_ch_layout)) {
173 av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
174 av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
175 ret = AVERROR(EINVAL);
176 goto fail;
177 }
178
179 if(!av_channel_layout_check(&out_ch_layout)) {
180 av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
181 ret = AVERROR(EINVAL);
182 goto fail;
183 }
184 if(!sane_layout(&out_ch_layout)) {
185 av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
186 av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
187 ret = AVERROR(EINVAL);
188 goto fail;
189 }
190 136
191 for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){137 for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
192 if( av_channel_layout_index_from_channel(&in_ch_layout, i) >= 0138 if( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0
193 && av_channel_layout_index_from_channel(&out_ch_layout, i) >= 0)139 && av_channel_layout_index_from_channel(out_ch_layout, i) >= 0)
194 matrix[i][i]= 1.0;140 matrix[i][i]= 1.0;
195 }141 }
196 142
197 unaccounted = in_ch_layout.u.mask & ~out_ch_layout.u.mask;
198
199//FIXME implement dolby surround143//FIXME implement dolby surround
200//FIXME implement full ac3144//FIXME implement full ac3
201 145
202
203 if(unaccounted & AV_CH_FRONT_CENTER){146 if(unaccounted & AV_CH_FRONT_CENTER){
204 if (av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) {147 if (av_channel_layout_subset(out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) {
205 if (av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) {148 if (av_channel_layout_subset(in_ch_layout, AV_CH_LAYOUT_STEREO)) {
206 matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;149 matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
207 matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;150 matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
208 } else {151 } else {
@@ -213,23 +156,23 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 4 unmodified lines
213 av_assert0(0);156 av_assert0(0);
214 }157 }
215 if(unaccounted & AV_CH_LAYOUT_STEREO){158 if(unaccounted & AV_CH_LAYOUT_STEREO){
216 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {159 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
217 matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;160 matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
218 matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;161 matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
219 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)162 if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
220 matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);163 matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
221 }else164 }else
222 av_assert0(0);165 av_assert0(0);
223 }166 }
224 167
225 if(unaccounted & AV_CH_BACK_CENTER){168 if(unaccounted & AV_CH_BACK_CENTER){
226 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {169 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
227 matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;170 matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
228 matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;171 matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
229 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {172 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
230 matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;173 matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
231 matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;174 matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
232 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {175 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
233 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||176 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
234 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {177 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
235 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {178 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
@@ -243,24 +186,24 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 7 unmodified lines
243 matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;186 matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
244 matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;187 matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
245 }188 }
246 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {189 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
247 matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;190 matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
248 }else191 }else
249 av_assert0(0);192 av_assert0(0);
250 }193 }
251 if(unaccounted & AV_CH_BACK_LEFT){194 if(unaccounted & AV_CH_BACK_LEFT){
252 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {195 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
253 matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;196 matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
254 matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;197 matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
255 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {198 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
256 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {199 if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
257 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;200 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
258 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;201 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
259 }else{202 }else{
260 matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;203 matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
261 matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;204 matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
262 }205 }
263 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {206 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
264 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {207 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
265 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;208 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
266 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;209 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
@@ -275,7 +218,7 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 8 unmodified lines
275 matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;218 matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
276 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;219 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
277 }220 }
278 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {221 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
279 matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;222 matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
280 matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;223 matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
281 }else224 }else
@@ -283,20 +226,20 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 1 unmodified line
283 }226 }
284 227
285 if(unaccounted & AV_CH_SIDE_LEFT){228 if(unaccounted & AV_CH_SIDE_LEFT){
286 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {229 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
287 /* if back channels do not exist in the input, just copy side230 /* if back channels do not exist in the input, just copy side
288 channels to back channels, otherwise mix side into back */231 channels to back channels, otherwise mix side into back */
289 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {232 if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
290 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;233 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
291 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;234 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
292 } else {235 } else {
293 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;236 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
294 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;237 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
295 }238 }
296 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {239 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
297 matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;240 matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
298 matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;241 matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
299 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {242 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
300 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {243 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
301 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;244 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
302 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;245 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
@@ -311,7 +254,7 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 8 unmodified lines
311 matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;254 matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
312 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;255 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
313 }256 }
314 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {257 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
315 matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;258 matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
316 matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;259 matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
317 }else260 }else
@@ -319,10 +262,10 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 1 unmodified line
319 }262 }
320 263
321 if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){264 if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
322 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {265 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
323 matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;266 matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
324 matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;267 matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
325 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {268 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
326 matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;269 matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
327 matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;270 matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
328 }else271 }else
@@ -330,20 +273,20 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 1 unmodified line
330 }273 }
331 274
332 if (unaccounted & AV_CH_TOP_FRONT_LEFT) {275 if (unaccounted & AV_CH_TOP_FRONT_LEFT) {
333 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0) {276 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0) {
334 matrix[TOP_FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;277 matrix[TOP_FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
335 matrix[TOP_FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;278 matrix[TOP_FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
336 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)279 if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)
337 matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2);280 matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2);
338 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {281 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
339 if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {282 if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
340 matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += M_SQRT1_2;283 matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += M_SQRT1_2;
341 matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += M_SQRT1_2;284 matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += M_SQRT1_2;
342 } else {285 } else {
343 matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0;286 matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0;
344 matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += 1.0;287 matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += 1.0;
345 }288 }
346 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {289 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
347 matrix[FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;290 matrix[FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
348 matrix[FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;291 matrix[FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
349 } else292 } else
@@ -352,29 +295,30 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 2 unmodified lines
352 295
353 /* mix LFE into front left/right or center */296 /* mix LFE into front left/right or center */
354 if (unaccounted & AV_CH_LOW_FREQUENCY) {297 if (unaccounted & AV_CH_LOW_FREQUENCY) {
355 if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {298 if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
356 matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;299 matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
357 } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {300 } else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
358 matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;301 matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
359 matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;302 matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
360 } else303 } else
361 av_assert0(0);304 av_assert0(0);
362 }305 }
363 306
307
364 for(out_i=i=0; i<64; i++){308 for(out_i=i=0; i<64; i++){
365 double sum=0;309 double sum=0;
366 int in_i=0;310 int in_i=0;
367 if (av_channel_layout_index_from_channel(&out_ch_layout, i) < 0)311 if (av_channel_layout_index_from_channel(out_ch_layout, i) < 0)
368 continue;312 continue;
369 for(j=0; j<64; j++){313 for(j=0; j<64; j++){
370 if (av_channel_layout_index_from_channel(&in_ch_layout, j) < 0)314 if (av_channel_layout_index_from_channel(in_ch_layout, j) < 0)
371 continue;315 continue;
372 if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))316 if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
373 matrix_param[stride*out_i + in_i] = matrix[i][j];317 matrix_param[stride*out_i + in_i] = matrix[i][j];
374 else318 else
375 matrix_param[stride*out_i + in_i] = i == j &&319 matrix_param[stride*out_i + in_i] = i == j &&
376 ( av_channel_layout_index_from_channel(&in_ch_layout, i) >= 0320 ( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0
377 && av_channel_layout_index_from_channel(&out_ch_layout, i) >= 0);321 && av_channel_layout_index_from_channel(out_ch_layout, i) >= 0);
378 sum += fabs(matrix_param[stride*out_i + in_i]);322 sum += fabs(matrix_param[stride*out_i + in_i]);
379 in_i++;323 in_i++;
380 }324 }
@@ -391,6 +335,72 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL · 10 unmodified lines
391 matrix_param[stride*i + j] /= maxcoef;335 matrix_param[stride*i + j] /= maxcoef;
392 }336 }
393 }337 }
338}
339
340av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
341 double center_mix_level, double surround_mix_level,
342 double lfe_mix_level, double maxval,
343 double rematrix_volume, double *matrix_param,
344 ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
345{
346 int i, j, ret;
347 AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
348 char buf[128];
349
350 ret = clean_layout(&in_ch_layout, in_layout, log_context);
351 ret |= clean_layout(&out_ch_layout, out_layout, log_context);
352 if (ret < 0)
353 goto fail;
354
355 if( !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
356 && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
357 ) {
358 av_channel_layout_uninit(&out_ch_layout);
359 out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
360 }
361 if( !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
362 && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
363 ) {
364 av_channel_layout_uninit(&in_ch_layout);
365 in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
366 }
367 if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
368 av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
369 av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
370 av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
371 av_log(log_context, AV_LOG_WARNING,
372 "Full-on remixing from 22.2 has not yet been implemented! "
373 "Processing the input as '%s'\n",
374 buf);
375 }
376
377 if(!av_channel_layout_check(&in_ch_layout)) {
378 av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
379 ret = AVERROR(EINVAL);
380 goto fail;
381 }
382 if(!sane_layout(&in_ch_layout)) {
383 av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
384 av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
385 ret = AVERROR(EINVAL);
386 goto fail;
387 }
388
389 if(!av_channel_layout_check(&out_ch_layout)) {
390 av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
391 ret = AVERROR(EINVAL);
392 goto fail;
393 }
394 if(!sane_layout(&out_ch_layout)) {
395 av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
396 av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
397 ret = AVERROR(EINVAL);
398 goto fail;
399 }
400
401 build_matrix(&in_ch_layout, &out_ch_layout, center_mix_level,
402 surround_mix_level, lfe_mix_level, maxval, rematrix_volume,
403 matrix_param, stride, matrix_encoding);
394 404
395 if(rematrix_volume > 0){405 if(rematrix_volume > 0){
396 for(i=0; i<SWR_CH_MAX; i++)406 for(i=0; i<SWR_CH_MAX; i++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t