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"
30 #include "window_func.h"
32 typedef struct AudioSurroundContext {
35 char *out_channel_layout_str;
36 char *in_channel_layout_str;
79 uint64_t out_channel_layout;
80 uint64_t in_channel_layout;
86 AVFrame *overlap_buffer;
91 RDFTContext **rdft, **irdft;
92 float *window_func_lut;
97 void (*filter)(AVFilterContext *ctx);
98 void (*upmix_stereo)(AVFilterContext *ctx,
105 void (*upmix_2_1)(AVFilterContext *ctx,
114 void (*upmix_3_0)(AVFilterContext *ctx,
122 void (*upmix_5_0)(AVFilterContext *ctx,
123 float c_re, float c_im,
124 float mag_totall, float mag_totalr,
125 float fl_phase, float fr_phase,
126 float bl_phase, float br_phase,
127 float sl_phase, float sr_phase,
131 void (*upmix_5_1)(AVFilterContext *ctx,
132 float c_re, float c_im,
133 float lfe_re, float lfe_im,
134 float mag_totall, float mag_totalr,
135 float fl_phase, float fr_phase,
136 float bl_phase, float br_phase,
137 float sl_phase, float sr_phase,
141 } AudioSurroundContext;
143 static int query_formats(AVFilterContext *ctx)
145 AudioSurroundContext *s = ctx->priv;
146 AVFilterFormats *formats = NULL;
147 AVFilterChannelLayouts *layouts = NULL;
150 ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
153 ret = ff_set_common_formats(ctx, formats);
158 ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
162 ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
167 ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
171 ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
175 formats = ff_all_samplerates();
177 return AVERROR(ENOMEM);
178 return ff_set_common_samplerates(ctx, formats);
181 static int config_input(AVFilterLink *inlink)
183 AVFilterContext *ctx = inlink->dst;
184 AudioSurroundContext *s = ctx->priv;
187 s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
189 return AVERROR(ENOMEM);
191 for (ch = 0; ch < inlink->channels; ch++) {
192 s->rdft[ch] = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
194 return AVERROR(ENOMEM);
196 s->nb_in_channels = inlink->channels;
197 s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
198 if (!s->input_levels)
199 return AVERROR(ENOMEM);
200 for (ch = 0; ch < s->nb_in_channels; ch++)
201 s->input_levels[ch] = s->level_in;
202 ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
204 s->input_levels[ch] *= s->fc_in;
205 ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
207 s->input_levels[ch] *= s->lfe_in;
209 s->input = ff_get_audio_buffer(inlink, s->buf_size * 2);
211 return AVERROR(ENOMEM);
213 s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->buf_size);
215 return AVERROR(ENOMEM);
217 s->lowcut = 1.f * s->lowcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
218 s->highcut = 1.f * s->highcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
223 static int config_output(AVFilterLink *outlink)
225 AVFilterContext *ctx = outlink->src;
226 AudioSurroundContext *s = ctx->priv;
229 s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft));
231 return AVERROR(ENOMEM);
233 for (ch = 0; ch < outlink->channels; ch++) {
234 s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
236 return AVERROR(ENOMEM);
238 s->nb_out_channels = outlink->channels;
239 s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
240 if (!s->output_levels)
241 return AVERROR(ENOMEM);
242 for (ch = 0; ch < s->nb_out_channels; ch++)
243 s->output_levels[ch] = s->level_out;
244 ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER);
246 s->output_levels[ch] *= s->fc_out;
247 ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY);
249 s->output_levels[ch] *= s->lfe_out;
251 s->output = ff_get_audio_buffer(outlink, s->buf_size * 2);
252 s->overlap_buffer = ff_get_audio_buffer(outlink, s->buf_size * 2);
253 if (!s->overlap_buffer || !s->output)
254 return AVERROR(ENOMEM);
259 static void stereo_position(float a, float p, float *x, float *y)
261 *x = av_clipf(a+FFMAX(0, sinf(p-M_PI_2))*FFDIFFSIGN(a,0), -1, 1);
262 *y = av_clipf(cosf(a*M_PI_2+M_PI)*cosf(M_PI_2-p/M_PI)*M_LN10+1, -1, 1);
265 static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut,
266 float *lfe_mag, float *mag_total, int lfe_mode)
268 if (output_lfe && n < highcut) {
269 *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PI*(lowcut-n)/(lowcut-highcut)));
270 *lfe_mag *= *mag_total;
272 *mag_total -= *lfe_mag;
278 static void upmix_1_0(AVFilterContext *ctx,
286 AudioSurroundContext *s = ctx->priv;
289 dst = (float *)s->output->extended_data[0];
291 mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
293 dst[2 * n ] = mag * cosf(c_phase);
294 dst[2 * n + 1] = mag * sinf(c_phase);
297 static void upmix_stereo(AVFilterContext *ctx,
305 AudioSurroundContext *s = ctx->priv;
306 float l_mag, r_mag, *dstl, *dstr;
308 dstl = (float *)s->output->extended_data[0];
309 dstr = (float *)s->output->extended_data[1];
311 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
312 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
314 dstl[2 * n ] = l_mag * cosf(l_phase);
315 dstl[2 * n + 1] = l_mag * sinf(l_phase);
317 dstr[2 * n ] = r_mag * cosf(r_phase);
318 dstr[2 * n + 1] = r_mag * sinf(r_phase);
321 static void upmix_2_1(AVFilterContext *ctx,
329 AudioSurroundContext *s = ctx->priv;
330 float lfe_mag, l_mag, r_mag, *dstl, *dstr, *dstlfe;
332 dstl = (float *)s->output->extended_data[0];
333 dstr = (float *)s->output->extended_data[1];
334 dstlfe = (float *)s->output->extended_data[2];
336 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
338 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
339 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
341 dstl[2 * n ] = l_mag * cosf(l_phase);
342 dstl[2 * n + 1] = l_mag * sinf(l_phase);
344 dstr[2 * n ] = r_mag * cosf(r_phase);
345 dstr[2 * n + 1] = r_mag * sinf(r_phase);
347 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
348 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
351 static void upmix_3_0(AVFilterContext *ctx,
359 AudioSurroundContext *s = ctx->priv;
360 float l_mag, r_mag, c_mag, *dstc, *dstl, *dstr;
362 dstl = (float *)s->output->extended_data[0];
363 dstr = (float *)s->output->extended_data[1];
364 dstc = (float *)s->output->extended_data[2];
366 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
367 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
368 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
370 dstl[2 * n ] = l_mag * cosf(l_phase);
371 dstl[2 * n + 1] = l_mag * sinf(l_phase);
373 dstr[2 * n ] = r_mag * cosf(r_phase);
374 dstr[2 * n + 1] = r_mag * sinf(r_phase);
376 dstc[2 * n ] = c_mag * cosf(c_phase);
377 dstc[2 * n + 1] = c_mag * sinf(c_phase);
380 static void upmix_3_1(AVFilterContext *ctx,
388 AudioSurroundContext *s = ctx->priv;
389 float lfe_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstlfe;
391 dstl = (float *)s->output->extended_data[0];
392 dstr = (float *)s->output->extended_data[1];
393 dstc = (float *)s->output->extended_data[2];
394 dstlfe = (float *)s->output->extended_data[3];
396 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
398 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
399 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
400 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
402 dstl[2 * n ] = l_mag * cosf(l_phase);
403 dstl[2 * n + 1] = l_mag * sinf(l_phase);
405 dstr[2 * n ] = r_mag * cosf(r_phase);
406 dstr[2 * n + 1] = r_mag * sinf(r_phase);
408 dstc[2 * n ] = c_mag * cosf(c_phase);
409 dstc[2 * n + 1] = c_mag * sinf(c_phase);
411 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
412 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
415 static void upmix_3_1_surround(AVFilterContext *ctx,
424 AudioSurroundContext *s = ctx->priv;
425 float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
427 dstl = (float *)s->output->extended_data[0];
428 dstr = (float *)s->output->extended_data[1];
429 dstc = (float *)s->output->extended_data[2];
430 dstlfe = (float *)s->output->extended_data[3];
432 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
434 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
435 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
437 dstl[2 * n ] = l_mag * cosf(l_phase);
438 dstl[2 * n + 1] = l_mag * sinf(l_phase);
440 dstr[2 * n ] = r_mag * cosf(r_phase);
441 dstr[2 * n + 1] = r_mag * sinf(r_phase);
443 dstc[2 * n ] = c_mag * cosf(c_phase);
444 dstc[2 * n + 1] = c_mag * sinf(c_phase);
446 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
447 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
450 static void upmix_4_0(AVFilterContext *ctx,
458 AudioSurroundContext *s = ctx->priv;
459 float b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb;
461 dstl = (float *)s->output->extended_data[0];
462 dstr = (float *)s->output->extended_data[1];
463 dstc = (float *)s->output->extended_data[2];
464 dstb = (float *)s->output->extended_data[3];
466 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
467 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
468 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
469 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
471 dstl[2 * n ] = l_mag * cosf(l_phase);
472 dstl[2 * n + 1] = l_mag * sinf(l_phase);
474 dstr[2 * n ] = r_mag * cosf(r_phase);
475 dstr[2 * n + 1] = r_mag * sinf(r_phase);
477 dstc[2 * n ] = c_mag * cosf(c_phase);
478 dstc[2 * n + 1] = c_mag * sinf(c_phase);
480 dstb[2 * n ] = b_mag * cosf(c_phase);
481 dstb[2 * n + 1] = b_mag * sinf(c_phase);
484 static void upmix_4_1(AVFilterContext *ctx,
492 AudioSurroundContext *s = ctx->priv;
493 float lfe_mag, b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb, *dstlfe;
495 dstl = (float *)s->output->extended_data[0];
496 dstr = (float *)s->output->extended_data[1];
497 dstc = (float *)s->output->extended_data[2];
498 dstlfe = (float *)s->output->extended_data[3];
499 dstb = (float *)s->output->extended_data[4];
501 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
503 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
504 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
506 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
507 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
508 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
509 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
511 dstl[2 * n ] = l_mag * cosf(l_phase);
512 dstl[2 * n + 1] = l_mag * sinf(l_phase);
514 dstr[2 * n ] = r_mag * cosf(r_phase);
515 dstr[2 * n + 1] = r_mag * sinf(r_phase);
517 dstc[2 * n ] = c_mag * cosf(c_phase);
518 dstc[2 * n + 1] = c_mag * sinf(c_phase);
520 dstb[2 * n ] = b_mag * cosf(c_phase);
521 dstb[2 * n + 1] = b_mag * sinf(c_phase);
524 static void upmix_5_0_back(AVFilterContext *ctx,
532 AudioSurroundContext *s = ctx->priv;
533 float l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs;
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 dstls = (float *)s->output->extended_data[3];
539 dstrs = (float *)s->output->extended_data[4];
541 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
542 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
543 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
544 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
545 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
547 dstl[2 * n ] = l_mag * cosf(l_phase);
548 dstl[2 * n + 1] = l_mag * sinf(l_phase);
550 dstr[2 * n ] = r_mag * cosf(r_phase);
551 dstr[2 * n + 1] = r_mag * sinf(r_phase);
553 dstc[2 * n ] = c_mag * cosf(c_phase);
554 dstc[2 * n + 1] = c_mag * sinf(c_phase);
556 dstls[2 * n ] = ls_mag * cosf(l_phase);
557 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
559 dstrs[2 * n ] = rs_mag * cosf(r_phase);
560 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
563 static void upmix_5_1_back(AVFilterContext *ctx,
571 AudioSurroundContext *s = ctx->priv;
572 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
574 dstl = (float *)s->output->extended_data[0];
575 dstr = (float *)s->output->extended_data[1];
576 dstc = (float *)s->output->extended_data[2];
577 dstlfe = (float *)s->output->extended_data[3];
578 dstls = (float *)s->output->extended_data[4];
579 dstrs = (float *)s->output->extended_data[5];
581 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
583 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
584 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
585 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
586 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
587 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
589 dstl[2 * n ] = l_mag * cosf(l_phase);
590 dstl[2 * n + 1] = l_mag * sinf(l_phase);
592 dstr[2 * n ] = r_mag * cosf(r_phase);
593 dstr[2 * n + 1] = r_mag * sinf(r_phase);
595 dstc[2 * n ] = c_mag * cosf(c_phase);
596 dstc[2 * n + 1] = c_mag * sinf(c_phase);
598 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
599 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
601 dstls[2 * n ] = ls_mag * cosf(l_phase);
602 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
604 dstrs[2 * n ] = rs_mag * cosf(r_phase);
605 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
608 static void upmix_6_0(AVFilterContext *ctx,
616 AudioSurroundContext *s = ctx->priv;
617 float l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs;
619 dstl = (float *)s->output->extended_data[0];
620 dstr = (float *)s->output->extended_data[1];
621 dstc = (float *)s->output->extended_data[2];
622 dstb = (float *)s->output->extended_data[3];
623 dstls = (float *)s->output->extended_data[4];
624 dstrs = (float *)s->output->extended_data[5];
626 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
627 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
628 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
629 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
630 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
631 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
633 dstl[2 * n ] = l_mag * cosf(l_phase);
634 dstl[2 * n + 1] = l_mag * sinf(l_phase);
636 dstr[2 * n ] = r_mag * cosf(r_phase);
637 dstr[2 * n + 1] = r_mag * sinf(r_phase);
639 dstc[2 * n ] = c_mag * cosf(c_phase);
640 dstc[2 * n + 1] = c_mag * sinf(c_phase);
642 dstls[2 * n ] = ls_mag * cosf(l_phase);
643 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
645 dstrs[2 * n ] = rs_mag * cosf(r_phase);
646 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
648 dstb[2 * n ] = b_mag * cosf(c_phase);
649 dstb[2 * n + 1] = b_mag * sinf(c_phase);
652 static void upmix_6_1(AVFilterContext *ctx,
660 AudioSurroundContext *s = ctx->priv;
661 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
663 dstl = (float *)s->output->extended_data[0];
664 dstr = (float *)s->output->extended_data[1];
665 dstc = (float *)s->output->extended_data[2];
666 dstlfe = (float *)s->output->extended_data[3];
667 dstb = (float *)s->output->extended_data[4];
668 dstls = (float *)s->output->extended_data[5];
669 dstrs = (float *)s->output->extended_data[6];
671 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
673 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
674 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
675 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
676 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
677 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
678 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
680 dstl[2 * n ] = l_mag * cosf(l_phase);
681 dstl[2 * n + 1] = l_mag * sinf(l_phase);
683 dstr[2 * n ] = r_mag * cosf(r_phase);
684 dstr[2 * n + 1] = r_mag * sinf(r_phase);
686 dstc[2 * n ] = c_mag * cosf(c_phase);
687 dstc[2 * n + 1] = c_mag * sinf(c_phase);
689 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
690 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
692 dstls[2 * n ] = ls_mag * cosf(l_phase);
693 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
695 dstrs[2 * n ] = rs_mag * cosf(r_phase);
696 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
698 dstb[2 * n ] = b_mag * cosf(c_phase);
699 dstb[2 * n + 1] = b_mag * sinf(c_phase);
702 static void upmix_5_1_back_surround(AVFilterContext *ctx,
711 AudioSurroundContext *s = ctx->priv;
712 float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
713 float ls_mag, rs_mag, *dstls, *dstrs;
715 dstl = (float *)s->output->extended_data[0];
716 dstr = (float *)s->output->extended_data[1];
717 dstc = (float *)s->output->extended_data[2];
718 dstlfe = (float *)s->output->extended_data[3];
719 dstls = (float *)s->output->extended_data[4];
720 dstrs = (float *)s->output->extended_data[5];
722 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
724 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
725 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
726 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
727 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
729 dstl[2 * n ] = l_mag * cosf(l_phase);
730 dstl[2 * n + 1] = l_mag * sinf(l_phase);
732 dstr[2 * n ] = r_mag * cosf(r_phase);
733 dstr[2 * n + 1] = r_mag * sinf(r_phase);
735 dstc[2 * n ] = c_mag * cosf(c_phase);
736 dstc[2 * n + 1] = c_mag * sinf(c_phase);
738 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
739 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
741 dstls[2 * n ] = ls_mag * cosf(l_phase);
742 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
744 dstrs[2 * n ] = rs_mag * cosf(r_phase);
745 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
748 static void upmix_5_1_back_2_1(AVFilterContext *ctx,
758 AudioSurroundContext *s = ctx->priv;
759 float c_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
760 float ls_mag, rs_mag, *dstls, *dstrs;
762 dstl = (float *)s->output->extended_data[0];
763 dstr = (float *)s->output->extended_data[1];
764 dstc = (float *)s->output->extended_data[2];
765 dstlfe = (float *)s->output->extended_data[3];
766 dstls = (float *)s->output->extended_data[4];
767 dstrs = (float *)s->output->extended_data[5];
769 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
770 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
771 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
772 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
773 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
775 dstl[2 * n ] = l_mag * cosf(l_phase);
776 dstl[2 * n + 1] = l_mag * sinf(l_phase);
778 dstr[2 * n ] = r_mag * cosf(r_phase);
779 dstr[2 * n + 1] = r_mag * sinf(r_phase);
781 dstc[2 * n ] = c_mag * cosf(c_phase);
782 dstc[2 * n + 1] = c_mag * sinf(c_phase);
784 dstlfe[2 * n ] = lfe_re;
785 dstlfe[2 * n + 1] = lfe_im;
787 dstls[2 * n ] = ls_mag * cosf(l_phase);
788 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
790 dstrs[2 * n ] = rs_mag * cosf(r_phase);
791 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
794 static void upmix_7_0(AVFilterContext *ctx,
802 float l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
803 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb;
804 AudioSurroundContext *s = ctx->priv;
806 dstl = (float *)s->output->extended_data[0];
807 dstr = (float *)s->output->extended_data[1];
808 dstc = (float *)s->output->extended_data[2];
809 dstlb = (float *)s->output->extended_data[3];
810 dstrb = (float *)s->output->extended_data[4];
811 dstls = (float *)s->output->extended_data[5];
812 dstrs = (float *)s->output->extended_data[6];
814 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
815 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
816 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
817 lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
818 rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
819 ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
820 rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
822 dstl[2 * n ] = l_mag * cosf(l_phase);
823 dstl[2 * n + 1] = l_mag * sinf(l_phase);
825 dstr[2 * n ] = r_mag * cosf(r_phase);
826 dstr[2 * n + 1] = r_mag * sinf(r_phase);
828 dstc[2 * n ] = c_mag * cosf(c_phase);
829 dstc[2 * n + 1] = c_mag * sinf(c_phase);
831 dstlb[2 * n ] = lb_mag * cosf(l_phase);
832 dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
834 dstrb[2 * n ] = rb_mag * cosf(r_phase);
835 dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
837 dstls[2 * n ] = ls_mag * cosf(l_phase);
838 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
840 dstrs[2 * n ] = rs_mag * cosf(r_phase);
841 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
844 static void upmix_7_1(AVFilterContext *ctx,
852 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
853 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
854 AudioSurroundContext *s = ctx->priv;
856 dstl = (float *)s->output->extended_data[0];
857 dstr = (float *)s->output->extended_data[1];
858 dstc = (float *)s->output->extended_data[2];
859 dstlfe = (float *)s->output->extended_data[3];
860 dstlb = (float *)s->output->extended_data[4];
861 dstrb = (float *)s->output->extended_data[5];
862 dstls = (float *)s->output->extended_data[6];
863 dstrs = (float *)s->output->extended_data[7];
865 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
867 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
868 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
869 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
870 lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
871 rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
872 ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
873 rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
875 dstl[2 * n ] = l_mag * cosf(l_phase);
876 dstl[2 * n + 1] = l_mag * sinf(l_phase);
878 dstr[2 * n ] = r_mag * cosf(r_phase);
879 dstr[2 * n + 1] = r_mag * sinf(r_phase);
881 dstc[2 * n ] = c_mag * cosf(c_phase);
882 dstc[2 * n + 1] = c_mag * sinf(c_phase);
884 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
885 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
887 dstlb[2 * n ] = lb_mag * cosf(l_phase);
888 dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
890 dstrb[2 * n ] = rb_mag * cosf(r_phase);
891 dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
893 dstls[2 * n ] = ls_mag * cosf(l_phase);
894 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
896 dstrs[2 * n ] = rs_mag * cosf(r_phase);
897 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
900 static void upmix_7_1_5_0_side(AVFilterContext *ctx,
901 float c_re, float c_im,
902 float mag_totall, float mag_totalr,
903 float fl_phase, float fr_phase,
904 float bl_phase, float br_phase,
905 float sl_phase, float sr_phase,
910 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
911 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
912 float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5;
913 AudioSurroundContext *s = ctx->priv;
915 dstl = (float *)s->output->extended_data[0];
916 dstr = (float *)s->output->extended_data[1];
917 dstc = (float *)s->output->extended_data[2];
918 dstlfe = (float *)s->output->extended_data[3];
919 dstlb = (float *)s->output->extended_data[4];
920 dstrb = (float *)s->output->extended_data[5];
921 dstls = (float *)s->output->extended_data[6];
922 dstrs = (float *)s->output->extended_data[7];
924 c_phase = atan2f(c_im, c_re);
926 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
928 fl_mag = powf(.5f * (xl + 1.f), s->fl_x) * powf((yl + 1.f) * .5f, s->fl_y) * mag_totall;
929 fr_mag = powf(.5f * (xr + 1.f), s->fr_x) * powf((yr + 1.f) * .5f, s->fr_y) * mag_totalr;
930 lb_mag = powf(.5f * (-xl + 1.f), s->bl_x) * powf((yl + 1.f) * .5f, s->bl_y) * mag_totall;
931 rb_mag = powf(.5f * (-xr + 1.f), s->br_x) * powf((yr + 1.f) * .5f, s->br_y) * mag_totalr;
932 ls_mag = powf(1.f - fabsf(xl), s->sl_x) * powf((yl + 1.f) * .5f, s->sl_y) * mag_totall;
933 rs_mag = powf(1.f - fabsf(xr), s->sr_x) * powf((yr + 1.f) * .5f, s->sr_y) * mag_totalr;
935 dstl[2 * n ] = fl_mag * cosf(fl_phase);
936 dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
938 dstr[2 * n ] = fr_mag * cosf(fr_phase);
939 dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
942 dstc[2 * n + 1] = c_im;
944 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
945 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
947 dstlb[2 * n ] = lb_mag * cosf(bl_phase);
948 dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
950 dstrb[2 * n ] = rb_mag * cosf(br_phase);
951 dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
953 dstls[2 * n ] = ls_mag * cosf(sl_phase);
954 dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
956 dstrs[2 * n ] = rs_mag * cosf(sr_phase);
957 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
960 static void upmix_7_1_5_1(AVFilterContext *ctx,
961 float c_re, float c_im,
962 float lfe_re, float lfe_im,
963 float mag_totall, float mag_totalr,
964 float fl_phase, float fr_phase,
965 float bl_phase, float br_phase,
966 float sl_phase, float sr_phase,
971 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
972 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
973 AudioSurroundContext *s = ctx->priv;
975 dstl = (float *)s->output->extended_data[0];
976 dstr = (float *)s->output->extended_data[1];
977 dstc = (float *)s->output->extended_data[2];
978 dstlfe = (float *)s->output->extended_data[3];
979 dstlb = (float *)s->output->extended_data[4];
980 dstrb = (float *)s->output->extended_data[5];
981 dstls = (float *)s->output->extended_data[6];
982 dstrs = (float *)s->output->extended_data[7];
984 fl_mag = powf(.5f * (xl + 1.f), s->fl_x) * powf((yl + 1.f) * .5f, s->fl_y) * mag_totall;
985 fr_mag = powf(.5f * (xr + 1.f), s->fr_x) * powf((yr + 1.f) * .5f, s->fr_y) * mag_totalr;
986 lb_mag = powf(.5f * (-xl + 1.f), s->bl_x) * powf((yl + 1.f) * .5f, s->bl_y) * mag_totall;
987 rb_mag = powf(.5f * (-xr + 1.f), s->br_x) * powf((yr + 1.f) * .5f, s->br_y) * mag_totalr;
988 ls_mag = powf(1.f - fabsf(xl), s->sl_x) * powf((yl + 1.f) * .5f, s->sl_y) * mag_totall;
989 rs_mag = powf(1.f - fabsf(xr), s->sl_x) * powf((yr + 1.f) * .5f, s->sr_y) * mag_totalr;
991 dstl[2 * n ] = fl_mag * cosf(fl_phase);
992 dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
994 dstr[2 * n ] = fr_mag * cosf(fr_phase);
995 dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
998 dstc[2 * n + 1] = c_im;
1000 dstlfe[2 * n ] = lfe_re;
1001 dstlfe[2 * n + 1] = lfe_im;
1003 dstlb[2 * n ] = lb_mag * cosf(bl_phase);
1004 dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
1006 dstrb[2 * n ] = rb_mag * cosf(br_phase);
1007 dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
1009 dstls[2 * n ] = ls_mag * cosf(sl_phase);
1010 dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
1012 dstrs[2 * n ] = rs_mag * cosf(sr_phase);
1013 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1016 static void filter_stereo(AVFilterContext *ctx)
1018 AudioSurroundContext *s = ctx->priv;
1022 srcl = (float *)s->input->extended_data[0];
1023 srcr = (float *)s->input->extended_data[1];
1025 for (n = 0; n < s->buf_size; n++) {
1026 float l_re = srcl[2 * n], r_re = srcr[2 * n];
1027 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1028 float c_phase = atan2f(l_im + r_im, l_re + r_re);
1029 float l_mag = hypotf(l_re, l_im);
1030 float r_mag = hypotf(r_re, r_im);
1031 float l_phase = atan2f(l_im, l_re);
1032 float r_phase = atan2f(r_im, r_re);
1033 float phase_dif = fabsf(l_phase - r_phase);
1034 float mag_sum = l_mag + r_mag;
1035 float mag_dif = mag_sum < 0.000001 ? 0.f : (l_mag - r_mag) / mag_sum;
1036 float mag_total = hypotf(l_mag, r_mag);
1039 if (phase_dif > M_PI)
1040 phase_dif = 2 * M_PI - phase_dif;
1042 stereo_position(mag_dif, phase_dif, &x, &y);
1044 s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);
1048 static void filter_surround(AVFilterContext *ctx)
1050 AudioSurroundContext *s = ctx->priv;
1051 float *srcl, *srcr, *srcc;
1054 srcl = (float *)s->input->extended_data[0];
1055 srcr = (float *)s->input->extended_data[1];
1056 srcc = (float *)s->input->extended_data[2];
1058 for (n = 0; n < s->buf_size; n++) {
1059 float l_re = srcl[2 * n], r_re = srcr[2 * n];
1060 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1061 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1062 float c_mag = hypotf(c_re, c_im);
1063 float c_phase = atan2f(c_im, c_re);
1064 float l_mag = hypotf(l_re, l_im);
1065 float r_mag = hypotf(r_re, r_im);
1066 float l_phase = atan2f(l_im, l_re);
1067 float r_phase = atan2f(r_im, r_re);
1068 float phase_dif = fabsf(l_phase - r_phase);
1069 float mag_sum = l_mag + r_mag;
1070 float mag_dif = mag_sum < 0.000001 ? 0.f : (l_mag - r_mag) / mag_sum;
1071 float mag_total = hypotf(l_mag, r_mag);
1074 if (phase_dif > M_PI)
1075 phase_dif = 2 * M_PI - phase_dif;
1077 stereo_position(mag_dif, phase_dif, &x, &y);
1079 s->upmix_3_0(ctx, l_phase, r_phase, c_phase, c_mag, mag_total, x, y, n);
1083 static void filter_2_1(AVFilterContext *ctx)
1085 AudioSurroundContext *s = ctx->priv;
1086 float *srcl, *srcr, *srclfe;
1089 srcl = (float *)s->input->extended_data[0];
1090 srcr = (float *)s->input->extended_data[1];
1091 srclfe = (float *)s->input->extended_data[2];
1093 for (n = 0; n < s->buf_size; n++) {
1094 float l_re = srcl[2 * n], r_re = srcr[2 * n];
1095 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1096 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1097 float c_phase = atan2f(l_im + r_im, l_re + r_re);
1098 float l_mag = hypotf(l_re, l_im);
1099 float r_mag = hypotf(r_re, r_im);
1100 float l_phase = atan2f(l_im, l_re);
1101 float r_phase = atan2f(r_im, r_re);
1102 float phase_dif = fabsf(l_phase - r_phase);
1103 float mag_sum = l_mag + r_mag;
1104 float mag_dif = mag_sum < 0.000001 ? 0.f : (l_mag - r_mag) / mag_sum;
1105 float mag_total = hypotf(l_mag, r_mag);
1108 if (phase_dif > M_PI)
1109 phase_dif = 2 * M_PI - phase_dif;
1111 stereo_position(mag_dif, phase_dif, &x, &y);
1113 s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
1117 static void filter_5_0_side(AVFilterContext *ctx)
1119 AudioSurroundContext *s = ctx->priv;
1120 float *srcl, *srcr, *srcc, *srcsl, *srcsr;
1123 srcl = (float *)s->input->extended_data[0];
1124 srcr = (float *)s->input->extended_data[1];
1125 srcc = (float *)s->input->extended_data[2];
1126 srcsl = (float *)s->input->extended_data[3];
1127 srcsr = (float *)s->input->extended_data[4];
1129 for (n = 0; n < s->buf_size; n++) {
1130 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1131 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1132 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1133 float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
1134 float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
1135 float fl_mag = hypotf(fl_re, fl_im);
1136 float fr_mag = hypotf(fr_re, fr_im);
1137 float fl_phase = atan2f(fl_im, fl_re);
1138 float fr_phase = atan2f(fr_im, fr_re);
1139 float sl_mag = hypotf(sl_re, sl_im);
1140 float sr_mag = hypotf(sr_re, sr_im);
1141 float sl_phase = atan2f(sl_im, sl_re);
1142 float sr_phase = atan2f(sr_im, sr_re);
1143 float phase_difl = fabsf(fl_phase - sl_phase);
1144 float phase_difr = fabsf(fr_phase - sr_phase);
1145 float magl_sum = fl_mag + sl_mag;
1146 float magr_sum = fr_mag + sr_mag;
1147 float mag_difl = magl_sum < 0.000001 ? 0.f : (fl_mag - sl_mag) / magl_sum;
1148 float mag_difr = magr_sum < 0.000001 ? 0.f : (fr_mag - sr_mag) / magr_sum;
1149 float mag_totall = hypotf(fl_mag, sl_mag);
1150 float mag_totalr = hypotf(fr_mag, sr_mag);
1151 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1152 float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1156 if (phase_difl > M_PI)
1157 phase_difl = 2 * M_PI - phase_difl;
1159 if (phase_difr > M_PI)
1160 phase_difr = 2 * M_PI - phase_difr;
1162 stereo_position(mag_difl, phase_difl, &xl, &yl);
1163 stereo_position(mag_difr, phase_difr, &xr, &yr);
1165 s->upmix_5_0(ctx, c_re, c_im,
1166 mag_totall, mag_totalr,
1174 static void filter_5_1_side(AVFilterContext *ctx)
1176 AudioSurroundContext *s = ctx->priv;
1177 float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
1180 srcl = (float *)s->input->extended_data[0];
1181 srcr = (float *)s->input->extended_data[1];
1182 srcc = (float *)s->input->extended_data[2];
1183 srclfe = (float *)s->input->extended_data[3];
1184 srcsl = (float *)s->input->extended_data[4];
1185 srcsr = (float *)s->input->extended_data[5];
1187 for (n = 0; n < s->buf_size; n++) {
1188 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1189 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1190 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1191 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1192 float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
1193 float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
1194 float fl_mag = hypotf(fl_re, fl_im);
1195 float fr_mag = hypotf(fr_re, fr_im);
1196 float fl_phase = atan2f(fl_im, fl_re);
1197 float fr_phase = atan2f(fr_im, fr_re);
1198 float sl_mag = hypotf(sl_re, sl_im);
1199 float sr_mag = hypotf(sr_re, sr_im);
1200 float sl_phase = atan2f(sl_im, sl_re);
1201 float sr_phase = atan2f(sr_im, sr_re);
1202 float phase_difl = fabsf(fl_phase - sl_phase);
1203 float phase_difr = fabsf(fr_phase - sr_phase);
1204 float magl_sum = fl_mag + sl_mag;
1205 float magr_sum = fr_mag + sr_mag;
1206 float mag_difl = magl_sum < 0.000001 ? 0.f : (fl_mag - sl_mag) / magl_sum;
1207 float mag_difr = magr_sum < 0.000001 ? 0.f : (fr_mag - sr_mag) / magr_sum;
1208 float mag_totall = hypotf(fl_mag, sl_mag);
1209 float mag_totalr = hypotf(fr_mag, sr_mag);
1210 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1211 float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1215 if (phase_difl > M_PI)
1216 phase_difl = 2 * M_PI - phase_difl;
1218 if (phase_difr > M_PI)
1219 phase_difr = 2 * M_PI - phase_difr;
1221 stereo_position(mag_difl, phase_difl, &xl, &yl);
1222 stereo_position(mag_difr, phase_difr, &xr, &yr);
1224 s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1225 mag_totall, mag_totalr,
1233 static void filter_5_1_back(AVFilterContext *ctx)
1235 AudioSurroundContext *s = ctx->priv;
1236 float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
1239 srcl = (float *)s->input->extended_data[0];
1240 srcr = (float *)s->input->extended_data[1];
1241 srcc = (float *)s->input->extended_data[2];
1242 srclfe = (float *)s->input->extended_data[3];
1243 srcbl = (float *)s->input->extended_data[4];
1244 srcbr = (float *)s->input->extended_data[5];
1246 for (n = 0; n < s->buf_size; n++) {
1247 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1248 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1249 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1250 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1251 float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
1252 float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
1253 float fl_mag = hypotf(fl_re, fl_im);
1254 float fr_mag = hypotf(fr_re, fr_im);
1255 float fl_phase = atan2f(fl_im, fl_re);
1256 float fr_phase = atan2f(fr_im, fr_re);
1257 float bl_mag = hypotf(bl_re, bl_im);
1258 float br_mag = hypotf(br_re, br_im);
1259 float bl_phase = atan2f(bl_im, bl_re);
1260 float br_phase = atan2f(br_im, br_re);
1261 float phase_difl = fabsf(fl_phase - bl_phase);
1262 float phase_difr = fabsf(fr_phase - br_phase);
1263 float magl_sum = fl_mag + bl_mag;
1264 float magr_sum = fr_mag + br_mag;
1265 float mag_difl = magl_sum < 0.000001 ? 0.f : (fl_mag - bl_mag) / magl_sum;
1266 float mag_difr = magr_sum < 0.000001 ? 0.f : (fr_mag - br_mag) / magr_sum;
1267 float mag_totall = hypotf(fl_mag, bl_mag);
1268 float mag_totalr = hypotf(fr_mag, br_mag);
1269 float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
1270 float sr_phase = atan2f(fr_im + br_im, fr_re + br_re);
1274 if (phase_difl > M_PI)
1275 phase_difl = 2 * M_PI - phase_difl;
1277 if (phase_difr > M_PI)
1278 phase_difr = 2 * M_PI - phase_difr;
1280 stereo_position(mag_difl, phase_difl, &xl, &yl);
1281 stereo_position(mag_difr, phase_difr, &xr, &yr);
1283 s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1284 mag_totall, mag_totalr,
1292 static int init(AVFilterContext *ctx)
1294 AudioSurroundContext *s = ctx->priv;
1298 if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) {
1299 av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
1300 s->out_channel_layout_str);
1301 return AVERROR(EINVAL);
1304 if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) {
1305 av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
1306 s->in_channel_layout_str);
1307 return AVERROR(EINVAL);
1310 if (s->lowcutf >= s->highcutf) {
1311 av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
1312 s->lowcutf, s->highcutf);
1313 return AVERROR(EINVAL);
1316 switch (s->in_channel_layout) {
1317 case AV_CH_LAYOUT_STEREO:
1318 s->filter = filter_stereo;
1319 switch (s->out_channel_layout) {
1320 case AV_CH_LAYOUT_MONO:
1321 s->upmix_stereo = upmix_1_0;
1323 case AV_CH_LAYOUT_STEREO:
1324 s->upmix_stereo = upmix_stereo;
1326 case AV_CH_LAYOUT_2POINT1:
1327 s->upmix_stereo = upmix_2_1;
1329 case AV_CH_LAYOUT_SURROUND:
1330 s->upmix_stereo = upmix_3_0;
1332 case AV_CH_LAYOUT_3POINT1:
1333 s->upmix_stereo = upmix_3_1;
1335 case AV_CH_LAYOUT_4POINT0:
1336 s->upmix_stereo = upmix_4_0;
1338 case AV_CH_LAYOUT_4POINT1:
1339 s->upmix_stereo = upmix_4_1;
1341 case AV_CH_LAYOUT_5POINT0_BACK:
1342 s->upmix_stereo = upmix_5_0_back;
1344 case AV_CH_LAYOUT_5POINT1_BACK:
1345 s->upmix_stereo = upmix_5_1_back;
1347 case AV_CH_LAYOUT_6POINT0:
1348 s->upmix_stereo = upmix_6_0;
1350 case AV_CH_LAYOUT_6POINT1:
1351 s->upmix_stereo = upmix_6_1;
1353 case AV_CH_LAYOUT_7POINT0:
1354 s->upmix_stereo = upmix_7_0;
1356 case AV_CH_LAYOUT_7POINT1:
1357 s->upmix_stereo = upmix_7_1;
1363 case AV_CH_LAYOUT_2POINT1:
1364 s->filter = filter_2_1;
1365 switch (s->out_channel_layout) {
1366 case AV_CH_LAYOUT_5POINT1_BACK:
1367 s->upmix_2_1 = upmix_5_1_back_2_1;
1373 case AV_CH_LAYOUT_SURROUND:
1374 s->filter = filter_surround;
1375 switch (s->out_channel_layout) {
1376 case AV_CH_LAYOUT_3POINT1:
1377 s->upmix_3_0 = upmix_3_1_surround;
1379 case AV_CH_LAYOUT_5POINT1_BACK:
1380 s->upmix_3_0 = upmix_5_1_back_surround;
1386 case AV_CH_LAYOUT_5POINT0:
1387 s->filter = filter_5_0_side;
1388 switch (s->out_channel_layout) {
1389 case AV_CH_LAYOUT_7POINT1:
1390 s->upmix_5_0 = upmix_7_1_5_0_side;
1396 case AV_CH_LAYOUT_5POINT1:
1397 s->filter = filter_5_1_side;
1398 switch (s->out_channel_layout) {
1399 case AV_CH_LAYOUT_7POINT1:
1400 s->upmix_5_1 = upmix_7_1_5_1;
1406 case AV_CH_LAYOUT_5POINT1_BACK:
1407 s->filter = filter_5_1_back;
1408 switch (s->out_channel_layout) {
1409 case AV_CH_LAYOUT_7POINT1:
1410 s->upmix_5_1 = upmix_7_1_5_1;
1418 av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
1419 s->in_channel_layout_str, s->out_channel_layout_str);
1420 return AVERROR(EINVAL);
1423 s->buf_size = 1 << av_log2(s->win_size);
1424 s->pts = AV_NOPTS_VALUE;
1426 s->window_func_lut = av_calloc(s->buf_size, sizeof(*s->window_func_lut));
1427 if (!s->window_func_lut)
1428 return AVERROR(ENOMEM);
1430 generate_window_func(s->window_func_lut, s->buf_size, s->win_func, &overlap);
1431 if (s->overlap == 1)
1432 s->overlap = overlap;
1434 for (i = 0; i < s->buf_size; i++)
1435 s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->buf_size);
1436 s->hop_size = s->buf_size * (1. - s->overlap);
1437 if (s->hop_size <= 0)
1438 return AVERROR(EINVAL);
1440 if (s->all_x >= 0.f)
1441 s->fc_x = s->fl_x = s->fr_x = s->bc_x = s->sl_x = s->sr_x = s->bl_x = s->br_x = s->all_x;
1442 if (s->all_y >= 0.f)
1443 s->fc_y = s->fl_y = s->fr_y = s->bc_y = s->sl_y = s->sr_y = s->bl_y = s->br_y = s->all_y;
1448 static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1450 AudioSurroundContext *s = ctx->priv;
1451 const float level_in = s->input_levels[ch];
1455 memset(s->input->extended_data[ch] + s->buf_size * sizeof(float), 0, s->buf_size * sizeof(float));
1457 dst = (float *)s->input->extended_data[ch];
1458 for (n = 0; n < s->buf_size; n++) {
1459 dst[n] *= s->window_func_lut[n] * level_in;
1462 av_rdft_calc(s->rdft[ch], (float *)s->input->extended_data[ch]);
1467 static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1469 AudioSurroundContext *s = ctx->priv;
1470 const float level_out = s->output_levels[ch];
1475 av_rdft_calc(s->irdft[ch], (float *)s->output->extended_data[ch]);
1477 dst = (float *)s->output->extended_data[ch];
1478 ptr = (float *)s->overlap_buffer->extended_data[ch];
1480 memmove(s->overlap_buffer->extended_data[ch],
1481 s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
1482 s->buf_size * sizeof(float));
1483 memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),
1484 0, s->hop_size * sizeof(float));
1486 for (n = 0; n < s->buf_size; n++) {
1487 ptr[n] += dst[n] * s->window_func_lut[n] * level_out;
1490 ptr = (float *)s->overlap_buffer->extended_data[ch];
1491 dst = (float *)out->extended_data[ch];
1492 memcpy(dst, ptr, s->hop_size * sizeof(float));
1497 static int filter_frame(AVFilterLink *inlink)
1499 AVFilterContext *ctx = inlink->dst;
1500 AVFilterLink *outlink = ctx->outputs[0];
1501 AudioSurroundContext *s = ctx->priv;
1505 ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size);
1509 ctx->internal->execute(ctx, fft_channel, NULL, NULL, inlink->channels);
1513 out = ff_get_audio_buffer(outlink, s->hop_size);
1515 return AVERROR(ENOMEM);
1517 ctx->internal->execute(ctx, ifft_channel, out, NULL, outlink->channels);
1520 if (s->pts != AV_NOPTS_VALUE)
1521 s->pts += av_rescale_q(out->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1522 av_audio_fifo_drain(s->fifo, FFMIN(av_audio_fifo_size(s->fifo), s->hop_size));
1524 return ff_filter_frame(outlink, out);
1527 static int activate(AVFilterContext *ctx)
1529 AVFilterLink *inlink = ctx->inputs[0];
1530 AVFilterLink *outlink = ctx->outputs[0];
1531 AudioSurroundContext *s = ctx->priv;
1533 int ret = 0, status;
1536 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
1538 if (!s->eof && av_audio_fifo_size(s->fifo) < s->buf_size) {
1539 ret = ff_inlink_consume_frame(inlink, &in);
1544 ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
1546 if (ret >= 0 && s->pts == AV_NOPTS_VALUE)
1555 if ((av_audio_fifo_size(s->fifo) >= s->buf_size) ||
1556 (av_audio_fifo_size(s->fifo) > 0 && s->eof)) {
1557 ret = filter_frame(inlink);
1558 if (av_audio_fifo_size(s->fifo) >= s->buf_size)
1559 ff_filter_set_ready(ctx, 100);
1563 if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
1564 if (status == AVERROR_EOF) {
1566 if (av_audio_fifo_size(s->fifo) >= 0) {
1567 ff_filter_set_ready(ctx, 100);
1573 if (s->eof && av_audio_fifo_size(s->fifo) <= 0) {
1574 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
1579 FF_FILTER_FORWARD_WANTED(outlink, inlink);
1581 return FFERROR_NOT_READY;
1584 static av_cold void uninit(AVFilterContext *ctx)
1586 AudioSurroundContext *s = ctx->priv;
1589 av_frame_free(&s->input);
1590 av_frame_free(&s->output);
1591 av_frame_free(&s->overlap_buffer);
1593 for (ch = 0; ch < s->nb_in_channels; ch++) {
1594 av_rdft_end(s->rdft[ch]);
1596 for (ch = 0; ch < s->nb_out_channels; ch++) {
1597 av_rdft_end(s->irdft[ch]);
1599 av_freep(&s->input_levels);
1600 av_freep(&s->output_levels);
1602 av_freep(&s->irdft);
1603 av_audio_fifo_free(s->fifo);
1604 av_freep(&s->window_func_lut);
1607 #define OFFSET(x) offsetof(AudioSurroundContext, x)
1608 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1610 static const AVOption surround_options[] = {
1611 { "chl_out", "set output channel layout", OFFSET(out_channel_layout_str), AV_OPT_TYPE_STRING, {.str="5.1"}, 0, 0, FLAGS },
1612 { "chl_in", "set input channel layout", OFFSET(in_channel_layout_str), AV_OPT_TYPE_STRING, {.str="stereo"},0, 0, FLAGS },
1613 { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1614 { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1615 { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
1616 { "lfe_low", "LFE low cut off", OFFSET(lowcutf), AV_OPT_TYPE_INT, {.i64=128}, 0, 256, FLAGS },
1617 { "lfe_high", "LFE high cut off", OFFSET(highcutf), AV_OPT_TYPE_INT, {.i64=256}, 0, 512, FLAGS },
1618 { "lfe_mode", "set LFE channel mode", OFFSET(lfe_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
1619 { "add", "just add LFE channel", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
1620 { "sub", "substract LFE channel with others", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 1, FLAGS, "lfe_mode" },
1621 { "fc_in", "set front center channel input level", OFFSET(fc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1622 { "fc_out", "set front center channel output level", OFFSET(fc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1623 { "lfe_in", "set lfe channel input level", OFFSET(lfe_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1624 { "lfe_out", "set lfe channel output level", OFFSET(lfe_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1625 { "allx", "set all channel's x spread", OFFSET(all_x), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, FLAGS },
1626 { "ally", "set all channel's y spread", OFFSET(all_y), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, FLAGS },
1627 { "fcx", "set front center channel x spread", OFFSET(fc_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1628 { "flx", "set front left channel x spread", OFFSET(fl_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1629 { "frx", "set front right channel x spread", OFFSET(fr_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1630 { "blx", "set back left channel x spread", OFFSET(bl_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1631 { "brx", "set back right channel x spread", OFFSET(br_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1632 { "slx", "set side left channel x spread", OFFSET(sl_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1633 { "srx", "set side right channel x spread", OFFSET(sr_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1634 { "bcx", "set back center channel x spread", OFFSET(bc_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1635 { "fcy", "set front center channel y spread", OFFSET(fc_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1636 { "fly", "set front left channel y spread", OFFSET(fl_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1637 { "fry", "set front right channel y spread", OFFSET(fr_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1638 { "bly", "set back left channel y spread", OFFSET(bl_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1639 { "bry", "set back right channel y spread", OFFSET(br_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1640 { "sly", "set side left channel y spread", OFFSET(sl_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1641 { "sry", "set side right channel y spread", OFFSET(sr_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1642 { "bcy", "set back center channel y spread", OFFSET(bc_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1643 { "win_size", "set window size", OFFSET(win_size), AV_OPT_TYPE_INT, {.i64 = 4096}, 1024, 65536, FLAGS },
1644 { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
1645 { "rect", "Rectangular", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT}, 0, 0, FLAGS, "win_func" },
1646 { "bartlett", "Bartlett", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
1647 { "hann", "Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
1648 { "hanning", "Hanning", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
1649 { "hamming", "Hamming", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
1650 { "blackman", "Blackman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
1651 { "welch", "Welch", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH}, 0, 0, FLAGS, "win_func" },
1652 { "flattop", "Flat-top", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP}, 0, 0, FLAGS, "win_func" },
1653 { "bharris", "Blackman-Harris", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS}, 0, 0, FLAGS, "win_func" },
1654 { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
1655 { "bhann", "Bartlett-Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN}, 0, 0, FLAGS, "win_func" },
1656 { "sine", "Sine", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE}, 0, 0, FLAGS, "win_func" },
1657 { "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
1658 { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
1659 { "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
1660 { "tukey", "Tukey", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY}, 0, 0, FLAGS, "win_func" },
1661 { "dolph", "Dolph-Chebyshev", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH}, 0, 0, FLAGS, "win_func" },
1662 { "cauchy", "Cauchy", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY}, 0, 0, FLAGS, "win_func" },
1663 { "parzen", "Parzen", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN}, 0, 0, FLAGS, "win_func" },
1664 { "poisson", "Poisson", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON}, 0, 0, FLAGS, "win_func" },
1665 { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, FLAGS, "win_func" },
1666 { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
1670 AVFILTER_DEFINE_CLASS(surround);
1672 static const AVFilterPad inputs[] = {
1675 .type = AVMEDIA_TYPE_AUDIO,
1676 .config_props = config_input,
1681 static const AVFilterPad outputs[] = {
1684 .type = AVMEDIA_TYPE_AUDIO,
1685 .config_props = config_output,
1690 AVFilter ff_af_surround = {
1692 .description = NULL_IF_CONFIG_SMALL("Apply audio surround upmix filter."),
1693 .query_formats = query_formats,
1694 .priv_size = sizeof(AudioSurroundContext),
1695 .priv_class = &surround_class,
1698 .activate = activate,
1701 .flags = AVFILTER_FLAG_SLICE_THREADS,