2 * Copyright (c) 2017 Paul B Mahol
4 * This file is part of FFmpeg.
6 * FFmpeg 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.
11 * FFmpeg 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/audio_fifo.h"
22 #include "libavutil/channel_layout.h"
23 #include "libavutil/opt.h"
24 #include "libavcodec/avfft.h"
29 typedef struct AudioSurroundContext {
32 char *out_channel_layout_str;
33 char *in_channel_layout_str;
51 uint64_t out_channel_layout;
52 uint64_t in_channel_layout;
58 AVFrame *overlap_buffer;
63 RDFTContext **rdft, **irdft;
64 float *window_func_lut;
68 void (*filter)(AVFilterContext *ctx);
69 void (*upmix_stereo)(AVFilterContext *ctx,
76 void (*upmix_2_1)(AVFilterContext *ctx,
85 void (*upmix_3_0)(AVFilterContext *ctx,
93 void (*upmix_5_1)(AVFilterContext *ctx,
94 float c_re, float c_im,
95 float lfe_re, float lfe_im,
96 float mag_totall, float mag_totalr,
97 float fl_phase, float fr_phase,
98 float bl_phase, float br_phase,
99 float sl_phase, float sr_phase,
103 } AudioSurroundContext;
105 static int query_formats(AVFilterContext *ctx)
107 AudioSurroundContext *s = ctx->priv;
108 AVFilterFormats *formats = NULL;
109 AVFilterChannelLayouts *layouts = NULL;
112 ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
115 ret = ff_set_common_formats(ctx, formats);
120 ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
124 ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
129 ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
133 ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
137 formats = ff_all_samplerates();
139 return AVERROR(ENOMEM);
140 return ff_set_common_samplerates(ctx, formats);
143 static int config_input(AVFilterLink *inlink)
145 AVFilterContext *ctx = inlink->dst;
146 AudioSurroundContext *s = ctx->priv;
149 s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
151 return AVERROR(ENOMEM);
153 for (ch = 0; ch < inlink->channels; ch++) {
154 s->rdft[ch] = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
156 return AVERROR(ENOMEM);
158 s->nb_in_channels = inlink->channels;
159 s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
160 if (!s->input_levels)
161 return AVERROR(ENOMEM);
162 for (ch = 0; ch < s->nb_in_channels; ch++)
163 s->input_levels[ch] = s->level_in;
164 ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
166 s->input_levels[ch] *= s->fc_in;
167 ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
169 s->input_levels[ch] *= s->lfe_in;
171 s->input = ff_get_audio_buffer(inlink, s->buf_size * 2);
173 return AVERROR(ENOMEM);
175 s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->buf_size);
177 return AVERROR(ENOMEM);
179 s->lowcut = 1.f * s->lowcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
180 s->highcut = 1.f * s->highcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
185 static int config_output(AVFilterLink *outlink)
187 AVFilterContext *ctx = outlink->src;
188 AudioSurroundContext *s = ctx->priv;
191 s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft));
193 return AVERROR(ENOMEM);
195 for (ch = 0; ch < outlink->channels; ch++) {
196 s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
198 return AVERROR(ENOMEM);
200 s->nb_out_channels = outlink->channels;
201 s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
202 if (!s->output_levels)
203 return AVERROR(ENOMEM);
204 for (ch = 0; ch < s->nb_out_channels; ch++)
205 s->output_levels[ch] = s->level_out;
206 ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER);
208 s->output_levels[ch] *= s->fc_out;
209 ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY);
211 s->output_levels[ch] *= s->lfe_out;
213 s->output = ff_get_audio_buffer(outlink, s->buf_size * 2);
214 s->overlap_buffer = ff_get_audio_buffer(outlink, s->buf_size * 2);
215 if (!s->overlap_buffer || !s->output)
216 return AVERROR(ENOMEM);
221 static void stereo_position(float a, float p, float *x, float *y)
223 *x = av_clipf(a+FFMAX(0, sinf(p-M_PI_2))*FFDIFFSIGN(a,0), -1, 1);
224 *y = av_clipf(cosf(a*M_PI_2+M_PI)*cosf(M_PI_2-p/M_PI)*M_LN10+1, -1, 1);
227 static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut,
228 float *lfe_mag, float *mag_total)
230 if (output_lfe && n < highcut) {
231 *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PI*(lowcut-n)/(lowcut-highcut)));
232 *lfe_mag *= *mag_total;
233 *mag_total -= *lfe_mag;
239 static void upmix_1_0(AVFilterContext *ctx,
247 AudioSurroundContext *s = ctx->priv;
250 dst = (float *)s->output->extended_data[0];
252 mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
254 dst[2 * n ] = mag * cosf(c_phase);
255 dst[2 * n + 1] = mag * sinf(c_phase);
258 static void upmix_stereo(AVFilterContext *ctx,
266 AudioSurroundContext *s = ctx->priv;
267 float l_mag, r_mag, *dstl, *dstr;
269 dstl = (float *)s->output->extended_data[0];
270 dstr = (float *)s->output->extended_data[1];
272 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
273 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
275 dstl[2 * n ] = l_mag * cosf(l_phase);
276 dstl[2 * n + 1] = l_mag * sinf(l_phase);
278 dstr[2 * n ] = r_mag * cosf(r_phase);
279 dstr[2 * n + 1] = r_mag * sinf(r_phase);
282 static void upmix_2_1(AVFilterContext *ctx,
290 AudioSurroundContext *s = ctx->priv;
291 float lfe_mag, l_mag, r_mag, *dstl, *dstr, *dstlfe;
293 dstl = (float *)s->output->extended_data[0];
294 dstr = (float *)s->output->extended_data[1];
295 dstlfe = (float *)s->output->extended_data[2];
297 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
299 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
300 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
302 dstl[2 * n ] = l_mag * cosf(l_phase);
303 dstl[2 * n + 1] = l_mag * sinf(l_phase);
305 dstr[2 * n ] = r_mag * cosf(r_phase);
306 dstr[2 * n + 1] = r_mag * sinf(r_phase);
308 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
309 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
312 static void upmix_3_0(AVFilterContext *ctx,
320 AudioSurroundContext *s = ctx->priv;
321 float l_mag, r_mag, c_mag, *dstc, *dstl, *dstr;
323 dstl = (float *)s->output->extended_data[0];
324 dstr = (float *)s->output->extended_data[1];
325 dstc = (float *)s->output->extended_data[2];
327 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
328 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
329 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
331 dstl[2 * n ] = l_mag * cosf(l_phase);
332 dstl[2 * n + 1] = l_mag * sinf(l_phase);
334 dstr[2 * n ] = r_mag * cosf(r_phase);
335 dstr[2 * n + 1] = r_mag * sinf(r_phase);
337 dstc[2 * n ] = c_mag * cosf(c_phase);
338 dstc[2 * n + 1] = c_mag * sinf(c_phase);
341 static void upmix_3_1(AVFilterContext *ctx,
349 AudioSurroundContext *s = ctx->priv;
350 float lfe_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstlfe;
352 dstl = (float *)s->output->extended_data[0];
353 dstr = (float *)s->output->extended_data[1];
354 dstc = (float *)s->output->extended_data[2];
355 dstlfe = (float *)s->output->extended_data[3];
357 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
359 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
360 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
361 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
363 dstl[2 * n ] = l_mag * cosf(l_phase);
364 dstl[2 * n + 1] = l_mag * sinf(l_phase);
366 dstr[2 * n ] = r_mag * cosf(r_phase);
367 dstr[2 * n + 1] = r_mag * sinf(r_phase);
369 dstc[2 * n ] = c_mag * cosf(c_phase);
370 dstc[2 * n + 1] = c_mag * sinf(c_phase);
372 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
373 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
376 static void upmix_3_1_surround(AVFilterContext *ctx,
385 AudioSurroundContext *s = ctx->priv;
386 float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
388 dstl = (float *)s->output->extended_data[0];
389 dstr = (float *)s->output->extended_data[1];
390 dstc = (float *)s->output->extended_data[2];
391 dstlfe = (float *)s->output->extended_data[3];
393 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag);
395 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
396 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
398 dstl[2 * n ] = l_mag * cosf(l_phase);
399 dstl[2 * n + 1] = l_mag * sinf(l_phase);
401 dstr[2 * n ] = r_mag * cosf(r_phase);
402 dstr[2 * n + 1] = r_mag * sinf(r_phase);
404 dstc[2 * n ] = c_mag * cosf(c_phase);
405 dstc[2 * n + 1] = c_mag * sinf(c_phase);
407 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
408 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
411 static void upmix_4_0(AVFilterContext *ctx,
419 float b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb;
420 AudioSurroundContext *s = ctx->priv;
422 dstl = (float *)s->output->extended_data[0];
423 dstr = (float *)s->output->extended_data[1];
424 dstc = (float *)s->output->extended_data[2];
425 dstb = (float *)s->output->extended_data[3];
427 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
428 b_mag = sqrtf(1.f - fabsf(x)) * ((1.f - y) * .5f) * mag_total;
429 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
430 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
432 dstl[2 * n ] = l_mag * cosf(l_phase);
433 dstl[2 * n + 1] = l_mag * sinf(l_phase);
435 dstr[2 * n ] = r_mag * cosf(r_phase);
436 dstr[2 * n + 1] = r_mag * sinf(r_phase);
438 dstc[2 * n ] = c_mag * cosf(c_phase);
439 dstc[2 * n + 1] = c_mag * sinf(c_phase);
441 dstb[2 * n ] = b_mag * cosf(c_phase);
442 dstb[2 * n + 1] = b_mag * sinf(c_phase);
445 static void upmix_4_1(AVFilterContext *ctx,
453 float lfe_mag, b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb, *dstlfe;
454 AudioSurroundContext *s = ctx->priv;
456 dstl = (float *)s->output->extended_data[0];
457 dstr = (float *)s->output->extended_data[1];
458 dstc = (float *)s->output->extended_data[2];
459 dstlfe = (float *)s->output->extended_data[3];
460 dstb = (float *)s->output->extended_data[4];
462 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
464 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
465 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
467 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
468 b_mag = sqrtf(1.f - fabsf(x)) * ((1.f - y) * .5f) * mag_total;
469 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
470 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
472 dstl[2 * n ] = l_mag * cosf(l_phase);
473 dstl[2 * n + 1] = l_mag * sinf(l_phase);
475 dstr[2 * n ] = r_mag * cosf(r_phase);
476 dstr[2 * n + 1] = r_mag * sinf(r_phase);
478 dstc[2 * n ] = c_mag * cosf(c_phase);
479 dstc[2 * n + 1] = c_mag * sinf(c_phase);
481 dstb[2 * n ] = b_mag * cosf(c_phase);
482 dstb[2 * n + 1] = b_mag * sinf(c_phase);
485 static void upmix_5_0_back(AVFilterContext *ctx,
493 float l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs;
494 AudioSurroundContext *s = ctx->priv;
496 dstl = (float *)s->output->extended_data[0];
497 dstr = (float *)s->output->extended_data[1];
498 dstc = (float *)s->output->extended_data[2];
499 dstls = (float *)s->output->extended_data[3];
500 dstrs = (float *)s->output->extended_data[4];
502 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
503 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
504 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
505 ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
506 rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
508 dstl[2 * n ] = l_mag * cosf(l_phase);
509 dstl[2 * n + 1] = l_mag * sinf(l_phase);
511 dstr[2 * n ] = r_mag * cosf(r_phase);
512 dstr[2 * n + 1] = r_mag * sinf(r_phase);
514 dstc[2 * n ] = c_mag * cosf(c_phase);
515 dstc[2 * n + 1] = c_mag * sinf(c_phase);
517 dstls[2 * n ] = ls_mag * cosf(l_phase);
518 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
520 dstrs[2 * n ] = rs_mag * cosf(r_phase);
521 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
524 static void upmix_5_1_back(AVFilterContext *ctx,
532 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
533 AudioSurroundContext *s = ctx->priv;
535 dstl = (float *)s->output->extended_data[0];
536 dstr = (float *)s->output->extended_data[1];
537 dstc = (float *)s->output->extended_data[2];
538 dstlfe = (float *)s->output->extended_data[3];
539 dstls = (float *)s->output->extended_data[4];
540 dstrs = (float *)s->output->extended_data[5];
542 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
544 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
545 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
546 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
547 ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
548 rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
550 dstl[2 * n ] = l_mag * cosf(l_phase);
551 dstl[2 * n + 1] = l_mag * sinf(l_phase);
553 dstr[2 * n ] = r_mag * cosf(r_phase);
554 dstr[2 * n + 1] = r_mag * sinf(r_phase);
556 dstc[2 * n ] = c_mag * cosf(c_phase);
557 dstc[2 * n + 1] = c_mag * sinf(c_phase);
559 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
560 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
562 dstls[2 * n ] = ls_mag * cosf(l_phase);
563 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
565 dstrs[2 * n ] = rs_mag * cosf(r_phase);
566 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
569 static void upmix_5_1_back_surround(AVFilterContext *ctx,
578 AudioSurroundContext *s = ctx->priv;
579 float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
580 float ls_mag, rs_mag, *dstls, *dstrs;
582 dstl = (float *)s->output->extended_data[0];
583 dstr = (float *)s->output->extended_data[1];
584 dstc = (float *)s->output->extended_data[2];
585 dstlfe = (float *)s->output->extended_data[3];
586 dstls = (float *)s->output->extended_data[4];
587 dstrs = (float *)s->output->extended_data[5];
589 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag);
591 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
592 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
593 ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
594 rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
596 dstl[2 * n ] = l_mag * cosf(l_phase);
597 dstl[2 * n + 1] = l_mag * sinf(l_phase);
599 dstr[2 * n ] = r_mag * cosf(r_phase);
600 dstr[2 * n + 1] = r_mag * sinf(r_phase);
602 dstc[2 * n ] = c_mag * cosf(c_phase);
603 dstc[2 * n + 1] = c_mag * sinf(c_phase);
605 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
606 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
608 dstls[2 * n ] = ls_mag * cosf(l_phase);
609 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
611 dstrs[2 * n ] = rs_mag * cosf(r_phase);
612 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
615 static void upmix_5_1_back_2_1(AVFilterContext *ctx,
625 AudioSurroundContext *s = ctx->priv;
626 float c_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
627 float ls_mag, rs_mag, *dstls, *dstrs;
629 dstl = (float *)s->output->extended_data[0];
630 dstr = (float *)s->output->extended_data[1];
631 dstc = (float *)s->output->extended_data[2];
632 dstlfe = (float *)s->output->extended_data[3];
633 dstls = (float *)s->output->extended_data[4];
634 dstrs = (float *)s->output->extended_data[5];
636 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
637 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
638 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
639 ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
640 rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
642 dstl[2 * n ] = l_mag * cosf(l_phase);
643 dstl[2 * n + 1] = l_mag * sinf(l_phase);
645 dstr[2 * n ] = r_mag * cosf(r_phase);
646 dstr[2 * n + 1] = r_mag * sinf(r_phase);
648 dstc[2 * n ] = c_mag * cosf(c_phase);
649 dstc[2 * n + 1] = c_mag * sinf(c_phase);
651 dstlfe[2 * n ] = lfe_re;
652 dstlfe[2 * n + 1] = lfe_im;
654 dstls[2 * n ] = ls_mag * cosf(l_phase);
655 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
657 dstrs[2 * n ] = rs_mag * cosf(r_phase);
658 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
661 static void upmix_7_0(AVFilterContext *ctx,
669 float l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
670 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb;
671 AudioSurroundContext *s = ctx->priv;
673 dstl = (float *)s->output->extended_data[0];
674 dstr = (float *)s->output->extended_data[1];
675 dstc = (float *)s->output->extended_data[2];
676 dstlb = (float *)s->output->extended_data[3];
677 dstrb = (float *)s->output->extended_data[4];
678 dstls = (float *)s->output->extended_data[5];
679 dstrs = (float *)s->output->extended_data[6];
681 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
682 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
683 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
684 lb_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
685 rb_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
686 ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - fabsf(y)) * mag_total;
687 rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - fabsf(y)) * mag_total;
689 dstl[2 * n ] = l_mag * cosf(l_phase);
690 dstl[2 * n + 1] = l_mag * sinf(l_phase);
692 dstr[2 * n ] = r_mag * cosf(r_phase);
693 dstr[2 * n + 1] = r_mag * sinf(r_phase);
695 dstc[2 * n ] = c_mag * cosf(c_phase);
696 dstc[2 * n + 1] = c_mag * sinf(c_phase);
698 dstlb[2 * n ] = lb_mag * cosf(l_phase);
699 dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
701 dstrb[2 * n ] = rb_mag * cosf(r_phase);
702 dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
704 dstls[2 * n ] = ls_mag * cosf(l_phase);
705 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
707 dstrs[2 * n ] = rs_mag * cosf(r_phase);
708 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
711 static void upmix_7_1(AVFilterContext *ctx,
719 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
720 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
721 AudioSurroundContext *s = ctx->priv;
723 dstl = (float *)s->output->extended_data[0];
724 dstr = (float *)s->output->extended_data[1];
725 dstc = (float *)s->output->extended_data[2];
726 dstlfe = (float *)s->output->extended_data[3];
727 dstlb = (float *)s->output->extended_data[4];
728 dstrb = (float *)s->output->extended_data[5];
729 dstls = (float *)s->output->extended_data[6];
730 dstrs = (float *)s->output->extended_data[7];
732 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
734 c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
735 l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
736 r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
737 lb_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
738 rb_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
739 ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - fabsf(y)) * mag_total;
740 rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - fabsf(y)) * mag_total;
742 dstl[2 * n ] = l_mag * cosf(l_phase);
743 dstl[2 * n + 1] = l_mag * sinf(l_phase);
745 dstr[2 * n ] = r_mag * cosf(r_phase);
746 dstr[2 * n + 1] = r_mag * sinf(r_phase);
748 dstc[2 * n ] = c_mag * cosf(c_phase);
749 dstc[2 * n + 1] = c_mag * sinf(c_phase);
751 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
752 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
754 dstlb[2 * n ] = lb_mag * cosf(l_phase);
755 dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
757 dstrb[2 * n ] = rb_mag * cosf(r_phase);
758 dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
760 dstls[2 * n ] = ls_mag * cosf(l_phase);
761 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
763 dstrs[2 * n ] = rs_mag * cosf(r_phase);
764 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
767 static void upmix_7_1_5_1(AVFilterContext *ctx,
768 float c_re, float c_im,
769 float lfe_re, float lfe_im,
770 float mag_totall, float mag_totalr,
771 float fl_phase, float fr_phase,
772 float bl_phase, float br_phase,
773 float sl_phase, float sr_phase,
778 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
779 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
780 AudioSurroundContext *s = ctx->priv;
782 dstl = (float *)s->output->extended_data[0];
783 dstr = (float *)s->output->extended_data[1];
784 dstc = (float *)s->output->extended_data[2];
785 dstlfe = (float *)s->output->extended_data[3];
786 dstlb = (float *)s->output->extended_data[4];
787 dstrb = (float *)s->output->extended_data[5];
788 dstls = (float *)s->output->extended_data[6];
789 dstrs = (float *)s->output->extended_data[7];
791 fl_mag = sqrtf(.5f * (xl + 1.f)) * ((yl + 1.f) * .5f) * mag_totall;
792 fr_mag = sqrtf(.5f * (xr + 1.f)) * ((yr + 1.f) * .5f) * mag_totalr;
793 lb_mag = sqrtf(.5f * (-xl + 1.f)) * ((yl + 1.f) * .5f) * mag_totall;
794 rb_mag = sqrtf(.5f * (-xr + 1.f)) * ((yr + 1.f) * .5f) * mag_totalr;
795 ls_mag = sqrtf(1.f - fabsf(xl)) * ((yl + 1.f) * .5f) * mag_totall;
796 rs_mag = sqrtf(1.f - fabsf(xr)) * ((yr + 1.f) * .5f) * mag_totalr;
798 dstl[2 * n ] = fl_mag * cosf(fl_phase);
799 dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
801 dstr[2 * n ] = fr_mag * cosf(fr_phase);
802 dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
805 dstc[2 * n + 1] = c_im;
807 dstlfe[2 * n ] = lfe_re;
808 dstlfe[2 * n + 1] = lfe_im;
810 dstlb[2 * n ] = lb_mag * cosf(bl_phase);
811 dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
813 dstrb[2 * n ] = rb_mag * cosf(br_phase);
814 dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
816 dstls[2 * n ] = ls_mag * cosf(sl_phase);
817 dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
819 dstrs[2 * n ] = rs_mag * cosf(sr_phase);
820 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
823 static void filter_stereo(AVFilterContext *ctx)
825 AudioSurroundContext *s = ctx->priv;
829 srcl = (float *)s->input->extended_data[0];
830 srcr = (float *)s->input->extended_data[1];
832 for (n = 0; n < s->buf_size; n++) {
833 float l_re = srcl[2 * n], r_re = srcr[2 * n];
834 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
835 float c_phase = atan2f(l_im + r_im, l_re + r_re);
836 float l_mag = hypotf(l_re, l_im);
837 float r_mag = hypotf(r_re, r_im);
838 float l_phase = atan2f(l_im, l_re);
839 float r_phase = atan2f(r_im, r_re);
840 float phase_dif = fabsf(l_phase - r_phase);
841 float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
842 float mag_total = hypotf(l_mag, r_mag);
845 if (phase_dif > M_PI)
846 phase_dif = 2 * M_PI - phase_dif;
848 stereo_position(mag_dif, phase_dif, &x, &y);
850 s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);
854 static void filter_surround(AVFilterContext *ctx)
856 AudioSurroundContext *s = ctx->priv;
857 float *srcl, *srcr, *srcc;
860 srcl = (float *)s->input->extended_data[0];
861 srcr = (float *)s->input->extended_data[1];
862 srcc = (float *)s->input->extended_data[2];
864 for (n = 0; n < s->buf_size; n++) {
865 float l_re = srcl[2 * n], r_re = srcr[2 * n];
866 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
867 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
868 float c_mag = hypotf(c_re, c_im);
869 float c_phase = atan2f(c_im, c_re);
870 float l_mag = hypotf(l_re, l_im);
871 float r_mag = hypotf(r_re, r_im);
872 float l_phase = atan2f(l_im, l_re);
873 float r_phase = atan2f(r_im, r_re);
874 float phase_dif = fabsf(l_phase - r_phase);
875 float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
876 float mag_total = hypotf(l_mag, r_mag);
879 if (phase_dif > M_PI)
880 phase_dif = 2 * M_PI - phase_dif;
882 stereo_position(mag_dif, phase_dif, &x, &y);
884 s->upmix_3_0(ctx, l_phase, r_phase, c_phase, c_mag, mag_total, x, y, n);
888 static void filter_2_1(AVFilterContext *ctx)
890 AudioSurroundContext *s = ctx->priv;
891 float *srcl, *srcr, *srclfe;
894 srcl = (float *)s->input->extended_data[0];
895 srcr = (float *)s->input->extended_data[1];
896 srclfe = (float *)s->input->extended_data[2];
898 for (n = 0; n < s->buf_size; n++) {
899 float l_re = srcl[2 * n], r_re = srcr[2 * n];
900 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
901 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
902 float c_phase = atan2f(l_im + r_im, l_re + r_re);
903 float l_mag = hypotf(l_re, l_im);
904 float r_mag = hypotf(r_re, r_im);
905 float l_phase = atan2f(l_im, l_re);
906 float r_phase = atan2f(r_im, r_re);
907 float phase_dif = fabsf(l_phase - r_phase);
908 float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
909 float mag_total = hypotf(l_mag, r_mag);
912 if (phase_dif > M_PI)
913 phase_dif = 2 * M_PI - phase_dif;
915 stereo_position(mag_dif, phase_dif, &x, &y);
917 s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
921 static void filter_5_1_back(AVFilterContext *ctx)
923 AudioSurroundContext *s = ctx->priv;
924 float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
927 srcl = (float *)s->input->extended_data[0];
928 srcr = (float *)s->input->extended_data[1];
929 srcc = (float *)s->input->extended_data[2];
930 srclfe = (float *)s->input->extended_data[3];
931 srcbl = (float *)s->input->extended_data[4];
932 srcbr = (float *)s->input->extended_data[5];
934 for (n = 0; n < s->buf_size; n++) {
935 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
936 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
937 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
938 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
939 float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
940 float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
941 float fl_mag = hypotf(fl_re, fl_im);
942 float fr_mag = hypotf(fr_re, fr_im);
943 float fl_phase = atan2f(fl_im, fl_re);
944 float fr_phase = atan2f(fr_im, fr_re);
945 float bl_mag = hypotf(bl_re, bl_im);
946 float br_mag = hypotf(br_re, br_im);
947 float bl_phase = atan2f(bl_im, bl_re);
948 float br_phase = atan2f(br_im, br_re);
949 float phase_difl = fabsf(fl_phase - bl_phase);
950 float phase_difr = fabsf(fr_phase - br_phase);
951 float mag_difl = (fl_mag - bl_mag) / (fl_mag + bl_mag);
952 float mag_difr = (fr_mag - br_mag) / (fr_mag + br_mag);
953 float mag_totall = hypotf(fl_mag, bl_mag);
954 float mag_totalr = hypotf(fr_mag, br_mag);
955 float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
956 float sr_phase = atan2f(fr_im + br_im, fr_re + br_re);
960 if (phase_difl > M_PI)
961 phase_difl = 2 * M_PI - phase_difl;
963 if (phase_difr > M_PI)
964 phase_difr = 2 * M_PI - phase_difr;
966 stereo_position(mag_difl, phase_difl, &xl, &yl);
967 stereo_position(mag_difr, phase_difr, &xr, &yr);
969 s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
970 mag_totall, mag_totalr,
978 static int init(AVFilterContext *ctx)
980 AudioSurroundContext *s = ctx->priv;
984 if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) {
985 av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
986 s->out_channel_layout_str);
987 return AVERROR(EINVAL);
990 if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) {
991 av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
992 s->in_channel_layout_str);
993 return AVERROR(EINVAL);
996 if (s->lowcutf >= s->highcutf) {
997 av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
998 s->lowcutf, s->highcutf);
999 return AVERROR(EINVAL);
1002 switch (s->in_channel_layout) {
1003 case AV_CH_LAYOUT_STEREO:
1004 s->filter = filter_stereo;
1005 switch (s->out_channel_layout) {
1006 case AV_CH_LAYOUT_MONO:
1007 s->upmix_stereo = upmix_1_0;
1009 case AV_CH_LAYOUT_STEREO:
1010 s->upmix_stereo = upmix_stereo;
1012 case AV_CH_LAYOUT_2POINT1:
1013 s->upmix_stereo = upmix_2_1;
1015 case AV_CH_LAYOUT_SURROUND:
1016 s->upmix_stereo = upmix_3_0;
1018 case AV_CH_LAYOUT_3POINT1:
1019 s->upmix_stereo = upmix_3_1;
1021 case AV_CH_LAYOUT_4POINT0:
1022 s->upmix_stereo = upmix_4_0;
1024 case AV_CH_LAYOUT_4POINT1:
1025 s->upmix_stereo = upmix_4_1;
1027 case AV_CH_LAYOUT_5POINT0_BACK:
1028 s->upmix_stereo = upmix_5_0_back;
1030 case AV_CH_LAYOUT_5POINT1_BACK:
1031 s->upmix_stereo = upmix_5_1_back;
1033 case AV_CH_LAYOUT_7POINT0:
1034 s->upmix_stereo = upmix_7_0;
1036 case AV_CH_LAYOUT_7POINT1:
1037 s->upmix_stereo = upmix_7_1;
1043 case AV_CH_LAYOUT_2POINT1:
1044 s->filter = filter_2_1;
1045 switch (s->out_channel_layout) {
1046 case AV_CH_LAYOUT_5POINT1_BACK:
1047 s->upmix_2_1 = upmix_5_1_back_2_1;
1053 case AV_CH_LAYOUT_SURROUND:
1054 s->filter = filter_surround;
1055 switch (s->out_channel_layout) {
1056 case AV_CH_LAYOUT_3POINT1:
1057 s->upmix_3_0 = upmix_3_1_surround;
1059 case AV_CH_LAYOUT_5POINT1_BACK:
1060 s->upmix_3_0 = upmix_5_1_back_surround;
1066 case AV_CH_LAYOUT_5POINT1_BACK:
1067 s->filter = filter_5_1_back;
1068 switch (s->out_channel_layout) {
1069 case AV_CH_LAYOUT_7POINT1:
1070 s->upmix_5_1 = upmix_7_1_5_1;
1078 av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
1079 s->in_channel_layout_str, s->out_channel_layout_str);
1080 return AVERROR(EINVAL);
1084 s->pts = AV_NOPTS_VALUE;
1086 s->window_func_lut = av_calloc(s->buf_size, sizeof(*s->window_func_lut));
1087 if (!s->window_func_lut)
1088 return AVERROR(ENOMEM);
1090 for (i = 0; i < s->buf_size; i++)
1091 s->window_func_lut[i] = sqrtf(0.5 * (1 - cosf(2 * M_PI * i / s->buf_size)) / s->buf_size);
1093 s->hop_size = s->buf_size * (1. - overlap);
1098 static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1100 AudioSurroundContext *s = ctx->priv;
1101 const float level_in = s->input_levels[ch];
1105 memset(s->input->extended_data[ch] + s->buf_size * sizeof(float), 0, s->buf_size * sizeof(float));
1107 dst = (float *)s->input->extended_data[ch];
1108 for (n = 0; n < s->buf_size; n++) {
1109 dst[n] *= s->window_func_lut[n] * level_in;
1112 av_rdft_calc(s->rdft[ch], (float *)s->input->extended_data[ch]);
1117 static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1119 AudioSurroundContext *s = ctx->priv;
1120 const float level_out = s->output_levels[ch];
1125 av_rdft_calc(s->irdft[ch], (float *)s->output->extended_data[ch]);
1127 dst = (float *)s->output->extended_data[ch];
1128 ptr = (float *)s->overlap_buffer->extended_data[ch];
1130 memmove(s->overlap_buffer->extended_data[ch],
1131 s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
1132 s->buf_size * sizeof(float));
1133 memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),
1134 0, s->hop_size * sizeof(float));
1136 for (n = 0; n < s->buf_size; n++) {
1137 ptr[n] += dst[n] * s->window_func_lut[n] * level_out;
1140 ptr = (float *)s->overlap_buffer->extended_data[ch];
1141 dst = (float *)out->extended_data[ch];
1142 memcpy(dst, ptr, s->hop_size * sizeof(float));
1147 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
1149 AVFilterContext *ctx = inlink->dst;
1150 AVFilterLink *outlink = ctx->outputs[0];
1151 AudioSurroundContext *s = ctx->priv;
1153 av_audio_fifo_write(s->fifo, (void **)in->extended_data,
1156 if (s->pts == AV_NOPTS_VALUE)
1161 while (av_audio_fifo_size(s->fifo) >= s->buf_size) {
1165 ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size);
1169 ctx->internal->execute(ctx, fft_channel, NULL, NULL, inlink->channels);
1173 out = ff_get_audio_buffer(outlink, s->hop_size);
1175 return AVERROR(ENOMEM);
1177 ctx->internal->execute(ctx, ifft_channel, out, NULL, outlink->channels);
1180 if (s->pts != AV_NOPTS_VALUE)
1181 s->pts += av_rescale_q(out->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1182 av_audio_fifo_drain(s->fifo, s->hop_size);
1183 ret = ff_filter_frame(outlink, out);
1191 static av_cold void uninit(AVFilterContext *ctx)
1193 AudioSurroundContext *s = ctx->priv;
1196 av_frame_free(&s->input);
1197 av_frame_free(&s->output);
1198 av_frame_free(&s->overlap_buffer);
1200 for (ch = 0; ch < s->nb_in_channels; ch++) {
1201 av_rdft_end(s->rdft[ch]);
1203 for (ch = 0; ch < s->nb_out_channels; ch++) {
1204 av_rdft_end(s->irdft[ch]);
1206 av_freep(&s->input_levels);
1207 av_freep(&s->output_levels);
1209 av_freep(&s->irdft);
1210 av_audio_fifo_free(s->fifo);
1211 av_freep(&s->window_func_lut);
1214 #define OFFSET(x) offsetof(AudioSurroundContext, x)
1215 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1217 static const AVOption surround_options[] = {
1218 { "chl_out", "set output channel layout", OFFSET(out_channel_layout_str), AV_OPT_TYPE_STRING, {.str="5.1"}, 0, 0, FLAGS },
1219 { "chl_in", "set input channel layout", OFFSET(in_channel_layout_str), AV_OPT_TYPE_STRING, {.str="stereo"},0, 0, FLAGS },
1220 { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1221 { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1222 { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
1223 { "lfe_low", "LFE low cut off", OFFSET(lowcutf), AV_OPT_TYPE_INT, {.i64=128}, 0, 256, FLAGS },
1224 { "lfe_high", "LFE high cut off", OFFSET(highcutf), AV_OPT_TYPE_INT, {.i64=256}, 0, 512, FLAGS },
1225 { "fc_in", "set front center channel input level", OFFSET(fc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1226 { "fc_out", "set front center channel output level", OFFSET(fc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1227 { "lfe_in", "set lfe channel input level", OFFSET(lfe_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1228 { "lfe_out", "set lfe channel output level", OFFSET(lfe_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1232 AVFILTER_DEFINE_CLASS(surround);
1234 static const AVFilterPad inputs[] = {
1237 .type = AVMEDIA_TYPE_AUDIO,
1238 .filter_frame = filter_frame,
1239 .config_props = config_input,
1244 static const AVFilterPad outputs[] = {
1247 .type = AVMEDIA_TYPE_AUDIO,
1248 .config_props = config_output,
1253 AVFilter ff_af_surround = {
1255 .description = NULL_IF_CONFIG_SMALL("Apply audio surround upmix filter."),
1256 .query_formats = query_formats,
1257 .priv_size = sizeof(AudioSurroundContext),
1258 .priv_class = &surround_class,
1263 .flags = AVFILTER_FLAG_SLICE_THREADS,