FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/af_surround.c
Date: 2024-09-07 18:49:03
Exec Total Coverage
Lines: 0 885 0.0%
Functions: 0 35 0.0%
Branches: 0 296 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2017 Paul B Mahol
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "libavutil/avassert.h"
22 #include "libavutil/channel_layout.h"
23 #include "libavutil/mem.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/tx.h"
26 #include "avfilter.h"
27 #include "audio.h"
28 #include "filters.h"
29 #include "formats.h"
30 #include "window_func.h"
31
32 enum SurroundChannel {
33 SC_FL, SC_FR, SC_FC, SC_LF, SC_BL, SC_BR, SC_BC, SC_SL, SC_SR,
34 SC_NB,
35 };
36
37 static const int ch_map[SC_NB] = {
38 [SC_FL] = AV_CHAN_FRONT_LEFT,
39 [SC_FR] = AV_CHAN_FRONT_RIGHT,
40 [SC_FC] = AV_CHAN_FRONT_CENTER,
41 [SC_LF] = AV_CHAN_LOW_FREQUENCY,
42 [SC_BL] = AV_CHAN_BACK_LEFT,
43 [SC_BR] = AV_CHAN_BACK_RIGHT,
44 [SC_BC] = AV_CHAN_BACK_CENTER,
45 [SC_SL] = AV_CHAN_SIDE_LEFT,
46 [SC_SR] = AV_CHAN_SIDE_RIGHT,
47 };
48
49 static const int sc_map[16] = {
50 [AV_CHAN_FRONT_LEFT ] = SC_FL,
51 [AV_CHAN_FRONT_RIGHT ] = SC_FR,
52 [AV_CHAN_FRONT_CENTER ] = SC_FC,
53 [AV_CHAN_LOW_FREQUENCY] = SC_LF,
54 [AV_CHAN_BACK_LEFT ] = SC_BL,
55 [AV_CHAN_BACK_RIGHT ] = SC_BR,
56 [AV_CHAN_BACK_CENTER ] = SC_BC,
57 [AV_CHAN_SIDE_LEFT ] = SC_SL,
58 [AV_CHAN_SIDE_RIGHT ] = SC_SR,
59 };
60
61 typedef struct AudioSurroundContext {
62 const AVClass *class;
63
64 AVChannelLayout out_ch_layout;
65 AVChannelLayout in_ch_layout;
66
67 float level_in;
68 float level_out;
69 float f_i[SC_NB];
70 float f_o[SC_NB];
71 int lfe_mode;
72 float smooth;
73 float angle;
74 float focus;
75 int win_size;
76 int win_func;
77 float win_gain;
78 float overlap;
79
80 float all_x;
81 float all_y;
82
83 float f_x[SC_NB];
84 float f_y[SC_NB];
85
86 float *input_levels;
87 float *output_levels;
88 int output_lfe;
89 int create_lfe;
90 int lowcutf;
91 int highcutf;
92
93 float lowcut;
94 float highcut;
95
96 int nb_in_channels;
97 int nb_out_channels;
98
99 AVFrame *factors;
100 AVFrame *sfactors;
101 AVFrame *input_in;
102 AVFrame *input;
103 AVFrame *output;
104 AVFrame *output_mag;
105 AVFrame *output_ph;
106 AVFrame *output_out;
107 AVFrame *overlap_buffer;
108 AVFrame *window;
109
110 float *x_pos;
111 float *y_pos;
112 float *l_phase;
113 float *r_phase;
114 float *c_phase;
115 float *c_mag;
116 float *lfe_mag;
117 float *lfe_phase;
118 float *mag_total;
119
120 int rdft_size;
121 int hop_size;
122 AVTXContext **rdft, **irdft;
123 av_tx_fn tx_fn, itx_fn;
124 float *window_func_lut;
125
126 void (*filter)(AVFilterContext *ctx);
127 void (*upmix)(AVFilterContext *ctx, int ch);
128 void (*upmix_5_0)(AVFilterContext *ctx,
129 float c_re, float c_im,
130 float mag_totall, float mag_totalr,
131 float fl_phase, float fr_phase,
132 float bl_phase, float br_phase,
133 float sl_phase, float sr_phase,
134 float xl, float yl,
135 float xr, float yr,
136 int n);
137 void (*upmix_5_1)(AVFilterContext *ctx,
138 float c_re, float c_im,
139 float lfe_re, float lfe_im,
140 float mag_totall, float mag_totalr,
141 float fl_phase, float fr_phase,
142 float bl_phase, float br_phase,
143 float sl_phase, float sr_phase,
144 float xl, float yl,
145 float xr, float yr,
146 int n);
147 } AudioSurroundContext;
148
149 static int query_formats(AVFilterContext *ctx)
150 {
151 AudioSurroundContext *s = ctx->priv;
152 AVFilterFormats *formats = NULL;
153 AVFilterChannelLayouts *layouts = NULL;
154 int ret;
155
156 ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
157 if (ret)
158 return ret;
159 ret = ff_set_common_formats(ctx, formats);
160 if (ret)
161 return ret;
162
163 layouts = NULL;
164 ret = ff_add_channel_layout(&layouts, &s->out_ch_layout);
165 if (ret)
166 return ret;
167
168 ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts);
169 if (ret)
170 return ret;
171
172 layouts = NULL;
173 ret = ff_add_channel_layout(&layouts, &s->in_ch_layout);
174 if (ret)
175 return ret;
176
177 ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts);
178 if (ret)
179 return ret;
180
181 return ff_set_common_all_samplerates(ctx);
182 }
183
184 static void set_input_levels(AVFilterContext *ctx)
185 {
186 AudioSurroundContext *s = ctx->priv;
187
188 for (int ch = 0; ch < s->nb_in_channels && s->level_in >= 0.f; ch++)
189 s->input_levels[ch] = s->level_in;
190 s->level_in = -1.f;
191
192 for (int n = 0; n < SC_NB; n++) {
193 const int ch = av_channel_layout_index_from_channel(&s->in_ch_layout, ch_map[n]);
194 if (ch >= 0)
195 s->input_levels[ch] = s->f_i[n];
196 }
197 }
198
199 static void set_output_levels(AVFilterContext *ctx)
200 {
201 AudioSurroundContext *s = ctx->priv;
202
203 for (int ch = 0; ch < s->nb_out_channels && s->level_out >= 0.f; ch++)
204 s->output_levels[ch] = s->level_out;
205 s->level_out = -1.f;
206
207 for (int n = 0; n < SC_NB; n++) {
208 const int ch = av_channel_layout_index_from_channel(&s->out_ch_layout, ch_map[n]);
209 if (ch >= 0)
210 s->output_levels[ch] = s->f_o[n];
211 }
212 }
213
214 static int config_input(AVFilterLink *inlink)
215 {
216 AVFilterContext *ctx = inlink->dst;
217 AudioSurroundContext *s = ctx->priv;
218 int ret;
219
220 s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft));
221 if (!s->rdft)
222 return AVERROR(ENOMEM);
223 s->nb_in_channels = inlink->ch_layout.nb_channels;
224
225 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
226 float scale = 1.f;
227
228 ret = av_tx_init(&s->rdft[ch], &s->tx_fn, AV_TX_FLOAT_RDFT,
229 0, s->win_size, &scale, 0);
230 if (ret < 0)
231 return ret;
232 }
233
234 s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
235 if (!s->input_levels)
236 return AVERROR(ENOMEM);
237
238 set_input_levels(ctx);
239
240 s->window = ff_get_audio_buffer(inlink, s->win_size * 2);
241 if (!s->window)
242 return AVERROR(ENOMEM);
243
244 s->input_in = ff_get_audio_buffer(inlink, s->win_size * 2);
245 if (!s->input_in)
246 return AVERROR(ENOMEM);
247
248 s->input = ff_get_audio_buffer(inlink, s->win_size + 2);
249 if (!s->input)
250 return AVERROR(ENOMEM);
251
252 s->lowcut = 1.f * s->lowcutf / (inlink->sample_rate * 0.5) * (s->win_size / 2);
253 s->highcut = 1.f * s->highcutf / (inlink->sample_rate * 0.5) * (s->win_size / 2);
254
255 return 0;
256 }
257
258 static int config_output(AVFilterLink *outlink)
259 {
260 AVFilterContext *ctx = outlink->src;
261 AudioSurroundContext *s = ctx->priv;
262 int ret;
263
264 s->irdft = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->irdft));
265 if (!s->irdft)
266 return AVERROR(ENOMEM);
267 s->nb_out_channels = outlink->ch_layout.nb_channels;
268
269 for (int ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
270 float iscale = 1.f;
271
272 ret = av_tx_init(&s->irdft[ch], &s->itx_fn, AV_TX_FLOAT_RDFT,
273 1, s->win_size, &iscale, 0);
274 if (ret < 0)
275 return ret;
276 }
277
278 s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
279 if (!s->output_levels)
280 return AVERROR(ENOMEM);
281
282 set_output_levels(ctx);
283
284 s->factors = ff_get_audio_buffer(outlink, s->win_size + 2);
285 s->sfactors = ff_get_audio_buffer(outlink, s->win_size + 2);
286 s->output_ph = ff_get_audio_buffer(outlink, s->win_size + 2);
287 s->output_mag = ff_get_audio_buffer(outlink, s->win_size + 2);
288 s->output_out = ff_get_audio_buffer(outlink, s->win_size + 2);
289 s->output = ff_get_audio_buffer(outlink, s->win_size + 2);
290 s->overlap_buffer = ff_get_audio_buffer(outlink, s->win_size * 2);
291 if (!s->overlap_buffer || !s->output || !s->output_out || !s->output_mag ||
292 !s->output_ph || !s->factors || !s->sfactors)
293 return AVERROR(ENOMEM);
294
295 s->rdft_size = s->win_size / 2 + 1;
296
297 s->x_pos = av_calloc(s->rdft_size, sizeof(*s->x_pos));
298 s->y_pos = av_calloc(s->rdft_size, sizeof(*s->y_pos));
299 s->l_phase = av_calloc(s->rdft_size, sizeof(*s->l_phase));
300 s->r_phase = av_calloc(s->rdft_size, sizeof(*s->r_phase));
301 s->c_mag = av_calloc(s->rdft_size, sizeof(*s->c_mag));
302 s->c_phase = av_calloc(s->rdft_size, sizeof(*s->c_phase));
303 s->mag_total = av_calloc(s->rdft_size, sizeof(*s->mag_total));
304 s->lfe_mag = av_calloc(s->rdft_size, sizeof(*s->lfe_mag));
305 s->lfe_phase = av_calloc(s->rdft_size, sizeof(*s->lfe_phase));
306 if (!s->x_pos || !s->y_pos || !s->l_phase || !s->r_phase || !s->lfe_phase ||
307 !s->c_phase || !s->mag_total || !s->lfe_mag || !s->c_mag)
308 return AVERROR(ENOMEM);
309
310 return 0;
311 }
312
313 static float sqrf(float x)
314 {
315 return x * x;
316 }
317
318 static float r_distance(float a)
319 {
320 return fminf(sqrtf(1.f + sqrf(tanf(a))), sqrtf(1.f + sqrf(1.f / tanf(a))));
321 }
322
323 #define MIN_MAG_SUM 0.00000001f
324
325 static void angle_transform(float *x, float *y, float angle)
326 {
327 float reference, r, a;
328
329 if (angle == 90.f)
330 return;
331
332 reference = angle * M_PIf / 180.f;
333 r = hypotf(*x, *y);
334 a = atan2f(*x, *y);
335
336 r /= r_distance(a);
337
338 if (fabsf(a) <= M_PI_4f)
339 a *= reference / M_PI_2f;
340 else
341 a = M_PIf + (-2.f * M_PIf + reference) * (M_PIf - fabsf(a)) * FFDIFFSIGN(a, 0.f) / (3.f * M_PI_2f);
342
343 r *= r_distance(a);
344
345 *x = av_clipf(sinf(a) * r, -1.f, 1.f);
346 *y = av_clipf(cosf(a) * r, -1.f, 1.f);
347 }
348
349 static void focus_transform(float *x, float *y, float focus)
350 {
351 float a, r, ra;
352
353 if (focus == 0.f)
354 return;
355
356 a = atan2f(*x, *y);
357 ra = r_distance(a);
358 r = av_clipf(hypotf(*x, *y) / ra, 0.f, 1.f);
359 r = focus > 0.f ? 1.f - powf(1.f - r, 1.f + focus * 20.f) : powf(r, 1.f - focus * 20.f);
360 r *= ra;
361 *x = av_clipf(sinf(a) * r, -1.f, 1.f);
362 *y = av_clipf(cosf(a) * r, -1.f, 1.f);
363 }
364
365 static void stereo_position(float a, float p, float *x, float *y)
366 {
367 av_assert2(a >= -1.f && a <= 1.f);
368 av_assert2(p >= 0.f && p <= M_PIf);
369 *x = av_clipf(a+a*fmaxf(0.f, p*p-M_PI_2f), -1.f, 1.f);
370 *y = av_clipf(cosf(a*M_PI_2f+M_PIf)*cosf(M_PI_2f-p/M_PIf)*M_LN10f+1.f, -1.f, 1.f);
371 }
372
373 static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut,
374 float *lfe_mag, float c_mag, float *mag_total, int lfe_mode)
375 {
376 if (output_lfe && n < highcut) {
377 *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PIf*(lowcut-n)/(lowcut-highcut)));
378 *lfe_mag *= c_mag;
379 if (lfe_mode)
380 *mag_total -= *lfe_mag;
381 } else {
382 *lfe_mag = 0.f;
383 }
384 }
385
386 #define TRANSFORM \
387 dst[2 * n ] = mag * cosf(ph); \
388 dst[2 * n + 1] = mag * sinf(ph);
389
390 static void calculate_factors(AVFilterContext *ctx, int ch, int chan)
391 {
392 AudioSurroundContext *s = ctx->priv;
393 float *factor = (float *)s->factors->extended_data[ch];
394 const float f_x = s->f_x[sc_map[chan >= 0 ? chan : 0]];
395 const float f_y = s->f_y[sc_map[chan >= 0 ? chan : 0]];
396 const int rdft_size = s->rdft_size;
397 const float *x = s->x_pos;
398 const float *y = s->y_pos;
399
400 switch (chan) {
401 case AV_CHAN_FRONT_CENTER:
402 for (int n = 0; n < rdft_size; n++)
403 factor[n] = powf(1.f - fabsf(x[n]), f_x) * powf((y[n] + 1.f) * .5f, f_y);
404 break;
405 case AV_CHAN_FRONT_LEFT:
406 for (int n = 0; n < rdft_size; n++)
407 factor[n] = powf(.5f * ( x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y);
408 break;
409 case AV_CHAN_FRONT_RIGHT:
410 for (int n = 0; n < rdft_size; n++)
411 factor[n] = powf(.5f * (-x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y);
412 break;
413 case AV_CHAN_LOW_FREQUENCY:
414 for (int n = 0; n < rdft_size; n++)
415 factor[n] = powf(1.f - fabsf(x[n]), f_x) * powf((1.f - fabsf(y[n])), f_y);
416 break;
417 case AV_CHAN_BACK_CENTER:
418 for (int n = 0; n < rdft_size; n++)
419 factor[n] = powf(1.f - fabsf(x[n]), f_x) * powf((1.f - y[n]) * .5f, f_y);
420 break;
421 case AV_CHAN_BACK_LEFT:
422 for (int n = 0; n < rdft_size; n++)
423 factor[n] = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y);
424 break;
425 case AV_CHAN_BACK_RIGHT:
426 for (int n = 0; n < rdft_size; n++)
427 factor[n] = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y);
428 break;
429 case AV_CHAN_SIDE_LEFT:
430 for (int n = 0; n < rdft_size; n++)
431 factor[n] = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y);
432 break;
433 case AV_CHAN_SIDE_RIGHT:
434 for (int n = 0; n < rdft_size; n++)
435 factor[n] = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y);
436 break;
437 default:
438 for (int n = 0; n < rdft_size; n++)
439 factor[n] = 1.f;
440 break;
441 }
442 }
443
444 static void do_transform(AVFilterContext *ctx, int ch)
445 {
446 AudioSurroundContext *s = ctx->priv;
447 float *sfactor = (float *)s->sfactors->extended_data[ch];
448 float *factor = (float *)s->factors->extended_data[ch];
449 float *omag = (float *)s->output_mag->extended_data[ch];
450 float *oph = (float *)s->output_ph->extended_data[ch];
451 float *dst = (float *)s->output->extended_data[ch];
452 const int rdft_size = s->rdft_size;
453 const float smooth = s->smooth;
454
455 if (smooth > 0.f) {
456 for (int n = 0; n < rdft_size; n++)
457 sfactor[n] = smooth * factor[n] + (1.f - smooth) * sfactor[n];
458
459 factor = sfactor;
460 }
461
462 for (int n = 0; n < rdft_size; n++)
463 omag[n] *= factor[n];
464
465 for (int n = 0; n < rdft_size; n++) {
466 const float mag = omag[n];
467 const float ph = oph[n];
468
469 TRANSFORM
470 }
471 }
472
473 static void stereo_copy(AVFilterContext *ctx, int ch, int chan)
474 {
475 AudioSurroundContext *s = ctx->priv;
476 float *omag = (float *)s->output_mag->extended_data[ch];
477 float *oph = (float *)s->output_ph->extended_data[ch];
478 const float *mag_total = s->mag_total;
479 const int rdft_size = s->rdft_size;
480 const float *c_phase = s->c_phase;
481 const float *l_phase = s->l_phase;
482 const float *r_phase = s->r_phase;
483 const float *lfe_mag = s->lfe_mag;
484 const float *c_mag = s->c_mag;
485
486 switch (chan) {
487 case AV_CHAN_FRONT_CENTER:
488 memcpy(omag, c_mag, rdft_size * sizeof(*omag));
489 break;
490 case AV_CHAN_LOW_FREQUENCY:
491 memcpy(omag, lfe_mag, rdft_size * sizeof(*omag));
492 break;
493 case AV_CHAN_FRONT_LEFT:
494 case AV_CHAN_FRONT_RIGHT:
495 case AV_CHAN_BACK_CENTER:
496 case AV_CHAN_BACK_LEFT:
497 case AV_CHAN_BACK_RIGHT:
498 case AV_CHAN_SIDE_LEFT:
499 case AV_CHAN_SIDE_RIGHT:
500 memcpy(omag, mag_total, rdft_size * sizeof(*omag));
501 break;
502 default:
503 break;
504 }
505
506 switch (chan) {
507 case AV_CHAN_FRONT_CENTER:
508 case AV_CHAN_LOW_FREQUENCY:
509 case AV_CHAN_BACK_CENTER:
510 memcpy(oph, c_phase, rdft_size * sizeof(*oph));
511 break;
512 case AV_CHAN_FRONT_LEFT:
513 case AV_CHAN_BACK_LEFT:
514 case AV_CHAN_SIDE_LEFT:
515 memcpy(oph, l_phase, rdft_size * sizeof(*oph));
516 break;
517 case AV_CHAN_FRONT_RIGHT:
518 case AV_CHAN_BACK_RIGHT:
519 case AV_CHAN_SIDE_RIGHT:
520 memcpy(oph, r_phase, rdft_size * sizeof(*oph));
521 break;
522 default:
523 break;
524 }
525 }
526
527 static void stereo_upmix(AVFilterContext *ctx, int ch)
528 {
529 AudioSurroundContext *s = ctx->priv;
530 const int chan = av_channel_layout_channel_from_index(&s->out_ch_layout, ch);
531
532 calculate_factors(ctx, ch, chan);
533
534 stereo_copy(ctx, ch, chan);
535
536 do_transform(ctx, ch);
537 }
538
539 static void l2_1_upmix(AVFilterContext *ctx, int ch)
540 {
541 AudioSurroundContext *s = ctx->priv;
542 const int chan = av_channel_layout_channel_from_index(&s->out_ch_layout, ch);
543 float *omag = (float *)s->output_mag->extended_data[ch];
544 float *oph = (float *)s->output_ph->extended_data[ch];
545 const float *mag_total = s->mag_total;
546 const float *lfe_phase = s->lfe_phase;
547 const int rdft_size = s->rdft_size;
548 const float *c_phase = s->c_phase;
549 const float *l_phase = s->l_phase;
550 const float *r_phase = s->r_phase;
551 const float *lfe_mag = s->lfe_mag;
552 const float *c_mag = s->c_mag;
553
554 switch (chan) {
555 case AV_CHAN_LOW_FREQUENCY:
556 calculate_factors(ctx, ch, -1);
557 break;
558 default:
559 calculate_factors(ctx, ch, chan);
560 break;
561 }
562
563 switch (chan) {
564 case AV_CHAN_FRONT_CENTER:
565 memcpy(omag, c_mag, rdft_size * sizeof(*omag));
566 break;
567 case AV_CHAN_LOW_FREQUENCY:
568 memcpy(omag, lfe_mag, rdft_size * sizeof(*omag));
569 break;
570 case AV_CHAN_FRONT_LEFT:
571 case AV_CHAN_FRONT_RIGHT:
572 case AV_CHAN_BACK_CENTER:
573 case AV_CHAN_BACK_LEFT:
574 case AV_CHAN_BACK_RIGHT:
575 case AV_CHAN_SIDE_LEFT:
576 case AV_CHAN_SIDE_RIGHT:
577 memcpy(omag, mag_total, rdft_size * sizeof(*omag));
578 break;
579 default:
580 break;
581 }
582
583 switch (chan) {
584 case AV_CHAN_LOW_FREQUENCY:
585 memcpy(oph, lfe_phase, rdft_size * sizeof(*oph));
586 break;
587 case AV_CHAN_FRONT_CENTER:
588 case AV_CHAN_BACK_CENTER:
589 memcpy(oph, c_phase, rdft_size * sizeof(*oph));
590 break;
591 case AV_CHAN_FRONT_LEFT:
592 case AV_CHAN_BACK_LEFT:
593 case AV_CHAN_SIDE_LEFT:
594 memcpy(oph, l_phase, rdft_size * sizeof(*oph));
595 break;
596 case AV_CHAN_FRONT_RIGHT:
597 case AV_CHAN_BACK_RIGHT:
598 case AV_CHAN_SIDE_RIGHT:
599 memcpy(oph, r_phase, rdft_size * sizeof(*oph));
600 break;
601 default:
602 break;
603 }
604
605 do_transform(ctx, ch);
606 }
607
608 static void surround_upmix(AVFilterContext *ctx, int ch)
609 {
610 AudioSurroundContext *s = ctx->priv;
611 const int chan = av_channel_layout_channel_from_index(&s->out_ch_layout, ch);
612
613 switch (chan) {
614 case AV_CHAN_FRONT_CENTER:
615 calculate_factors(ctx, ch, -1);
616 break;
617 default:
618 calculate_factors(ctx, ch, chan);
619 break;
620 }
621
622 stereo_copy(ctx, ch, chan);
623
624 do_transform(ctx, ch);
625 }
626
627 static void upmix_7_1_5_0_side(AVFilterContext *ctx,
628 float c_re, float c_im,
629 float mag_totall, float mag_totalr,
630 float fl_phase, float fr_phase,
631 float bl_phase, float br_phase,
632 float sl_phase, float sr_phase,
633 float xl, float yl,
634 float xr, float yr,
635 int n)
636 {
637 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
638 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
639 float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5f;
640 AudioSurroundContext *s = ctx->priv;
641
642 dstl = (float *)s->output->extended_data[0];
643 dstr = (float *)s->output->extended_data[1];
644 dstc = (float *)s->output->extended_data[2];
645 dstlfe = (float *)s->output->extended_data[3];
646 dstlb = (float *)s->output->extended_data[4];
647 dstrb = (float *)s->output->extended_data[5];
648 dstls = (float *)s->output->extended_data[6];
649 dstrs = (float *)s->output->extended_data[7];
650
651 c_phase = atan2f(c_im, c_re);
652
653 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, hypotf(c_re, c_im), &mag_total, s->lfe_mode);
654
655 fl_mag = powf(.5f * (xl + 1.f), s->f_x[SC_FL]) * powf((yl + 1.f) * .5f, s->f_y[SC_FL]) * mag_totall;
656 fr_mag = powf(.5f * (xr + 1.f), s->f_x[SC_FR]) * powf((yr + 1.f) * .5f, s->f_y[SC_FR]) * mag_totalr;
657 lb_mag = powf(.5f * (-xl + 1.f), s->f_x[SC_BL]) * powf((yl + 1.f) * .5f, s->f_y[SC_BL]) * mag_totall;
658 rb_mag = powf(.5f * (-xr + 1.f), s->f_x[SC_BR]) * powf((yr + 1.f) * .5f, s->f_y[SC_BR]) * mag_totalr;
659 ls_mag = powf(1.f - fabsf(xl), s->f_x[SC_SL]) * powf((yl + 1.f) * .5f, s->f_y[SC_SL]) * mag_totall;
660 rs_mag = powf(1.f - fabsf(xr), s->f_x[SC_SR]) * powf((yr + 1.f) * .5f, s->f_y[SC_SR]) * mag_totalr;
661
662 dstl[2 * n ] = fl_mag * cosf(fl_phase);
663 dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
664
665 dstr[2 * n ] = fr_mag * cosf(fr_phase);
666 dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
667
668 dstc[2 * n ] = c_re;
669 dstc[2 * n + 1] = c_im;
670
671 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
672 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
673
674 dstlb[2 * n ] = lb_mag * cosf(bl_phase);
675 dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
676
677 dstrb[2 * n ] = rb_mag * cosf(br_phase);
678 dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
679
680 dstls[2 * n ] = ls_mag * cosf(sl_phase);
681 dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
682
683 dstrs[2 * n ] = rs_mag * cosf(sr_phase);
684 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
685 }
686
687 static void upmix_7_1_5_1(AVFilterContext *ctx,
688 float c_re, float c_im,
689 float lfe_re, float lfe_im,
690 float mag_totall, float mag_totalr,
691 float fl_phase, float fr_phase,
692 float bl_phase, float br_phase,
693 float sl_phase, float sr_phase,
694 float xl, float yl,
695 float xr, float yr,
696 int n)
697 {
698 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
699 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
700 AudioSurroundContext *s = ctx->priv;
701
702 dstl = (float *)s->output->extended_data[0];
703 dstr = (float *)s->output->extended_data[1];
704 dstc = (float *)s->output->extended_data[2];
705 dstlfe = (float *)s->output->extended_data[3];
706 dstlb = (float *)s->output->extended_data[4];
707 dstrb = (float *)s->output->extended_data[5];
708 dstls = (float *)s->output->extended_data[6];
709 dstrs = (float *)s->output->extended_data[7];
710
711 fl_mag = powf(.5f * (xl + 1.f), s->f_x[SC_FL]) * powf((yl + 1.f) * .5f, s->f_y[SC_FL]) * mag_totall;
712 fr_mag = powf(.5f * (xr + 1.f), s->f_x[SC_FR]) * powf((yr + 1.f) * .5f, s->f_y[SC_FR]) * mag_totalr;
713 lb_mag = powf(.5f * (-xl + 1.f), s->f_x[SC_BL]) * powf((yl + 1.f) * .5f, s->f_y[SC_BL]) * mag_totall;
714 rb_mag = powf(.5f * (-xr + 1.f), s->f_x[SC_BR]) * powf((yr + 1.f) * .5f, s->f_y[SC_BR]) * mag_totalr;
715 ls_mag = powf(1.f - fabsf(xl), s->f_x[SC_SL]) * powf((yl + 1.f) * .5f, s->f_y[SC_SL]) * mag_totall;
716 rs_mag = powf(1.f - fabsf(xr), s->f_x[SC_SR]) * powf((yr + 1.f) * .5f, s->f_y[SC_SR]) * mag_totalr;
717
718 dstl[2 * n ] = fl_mag * cosf(fl_phase);
719 dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
720
721 dstr[2 * n ] = fr_mag * cosf(fr_phase);
722 dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
723
724 dstc[2 * n ] = c_re;
725 dstc[2 * n + 1] = c_im;
726
727 dstlfe[2 * n ] = lfe_re;
728 dstlfe[2 * n + 1] = lfe_im;
729
730 dstlb[2 * n ] = lb_mag * cosf(bl_phase);
731 dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
732
733 dstrb[2 * n ] = rb_mag * cosf(br_phase);
734 dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
735
736 dstls[2 * n ] = ls_mag * cosf(sl_phase);
737 dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
738
739 dstrs[2 * n ] = rs_mag * cosf(sr_phase);
740 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
741 }
742
743 static void filter_stereo(AVFilterContext *ctx)
744 {
745 AudioSurroundContext *s = ctx->priv;
746 const float *srcl = (const float *)s->input->extended_data[0];
747 const float *srcr = (const float *)s->input->extended_data[1];
748 const int output_lfe = s->output_lfe && s->create_lfe;
749 const int rdft_size = s->rdft_size;
750 const int lfe_mode = s->lfe_mode;
751 const float highcut = s->highcut;
752 const float lowcut = s->lowcut;
753 const float angle = s->angle;
754 const float focus = s->focus;
755 float *magtotal = s->mag_total;
756 float *lfemag = s->lfe_mag;
757 float *lphase = s->l_phase;
758 float *rphase = s->r_phase;
759 float *cphase = s->c_phase;
760 float *cmag = s->c_mag;
761 float *xpos = s->x_pos;
762 float *ypos = s->y_pos;
763
764 for (int n = 0; n < rdft_size; n++) {
765 float l_re = srcl[2 * n], r_re = srcr[2 * n];
766 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
767 float c_phase = atan2f(l_im + r_im, l_re + r_re);
768 float l_mag = hypotf(l_re, l_im);
769 float r_mag = hypotf(r_re, r_im);
770 float mag_total = hypotf(l_mag, r_mag);
771 float l_phase = atan2f(l_im, l_re);
772 float r_phase = atan2f(r_im, r_re);
773 float phase_dif = fabsf(l_phase - r_phase);
774 float mag_sum = l_mag + r_mag;
775 float c_mag = mag_sum * 0.5f;
776 float mag_dif, x, y;
777
778 mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum;
779 mag_dif = (l_mag - r_mag) / mag_sum;
780 if (phase_dif > M_PIf)
781 phase_dif = 2.f * M_PIf - phase_dif;
782
783 stereo_position(mag_dif, phase_dif, &x, &y);
784 angle_transform(&x, &y, angle);
785 focus_transform(&x, &y, focus);
786 get_lfe(output_lfe, n, lowcut, highcut, &lfemag[n], c_mag, &mag_total, lfe_mode);
787
788 xpos[n] = x;
789 ypos[n] = y;
790 lphase[n] = l_phase;
791 rphase[n] = r_phase;
792 cmag[n] = c_mag;
793 cphase[n] = c_phase;
794 magtotal[n] = mag_total;
795 }
796 }
797
798 static void filter_2_1(AVFilterContext *ctx)
799 {
800 AudioSurroundContext *s = ctx->priv;
801 const float *srcl = (const float *)s->input->extended_data[0];
802 const float *srcr = (const float *)s->input->extended_data[1];
803 const float *srclfe = (const float *)s->input->extended_data[2];
804 const int rdft_size = s->rdft_size;
805 const float angle = s->angle;
806 const float focus = s->focus;
807 float *magtotal = s->mag_total;
808 float *lfephase = s->lfe_phase;
809 float *lfemag = s->lfe_mag;
810 float *lphase = s->l_phase;
811 float *rphase = s->r_phase;
812 float *cphase = s->c_phase;
813 float *cmag = s->c_mag;
814 float *xpos = s->x_pos;
815 float *ypos = s->y_pos;
816
817 for (int n = 0; n < rdft_size; n++) {
818 float l_re = srcl[2 * n], r_re = srcr[2 * n];
819 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
820 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
821 float c_phase = atan2f(l_im + r_im, l_re + r_re);
822 float l_mag = hypotf(l_re, l_im);
823 float r_mag = hypotf(r_re, r_im);
824 float lfe_mag = hypotf(lfe_re, lfe_im);
825 float lfe_phase = atan2f(lfe_im, lfe_re);
826 float mag_total = hypotf(l_mag, r_mag);
827 float l_phase = atan2f(l_im, l_re);
828 float r_phase = atan2f(r_im, r_re);
829 float phase_dif = fabsf(l_phase - r_phase);
830 float mag_sum = l_mag + r_mag;
831 float c_mag = mag_sum * 0.5f;
832 float mag_dif, x, y;
833
834 mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum;
835 mag_dif = (l_mag - r_mag) / mag_sum;
836 if (phase_dif > M_PIf)
837 phase_dif = 2.f * M_PIf - phase_dif;
838
839 stereo_position(mag_dif, phase_dif, &x, &y);
840 angle_transform(&x, &y, angle);
841 focus_transform(&x, &y, focus);
842
843 xpos[n] = x;
844 ypos[n] = y;
845 lphase[n] = l_phase;
846 rphase[n] = r_phase;
847 cmag[n] = c_mag;
848 cphase[n] = c_phase;
849 lfemag[n] = lfe_mag;
850 lfephase[n] = lfe_phase;
851 magtotal[n] = mag_total;
852 }
853 }
854
855 static void filter_surround(AVFilterContext *ctx)
856 {
857 AudioSurroundContext *s = ctx->priv;
858 const float *srcl = (const float *)s->input->extended_data[0];
859 const float *srcr = (const float *)s->input->extended_data[1];
860 const float *srcc = (const float *)s->input->extended_data[2];
861 const int output_lfe = s->output_lfe && s->create_lfe;
862 const int rdft_size = s->rdft_size;
863 const int lfe_mode = s->lfe_mode;
864 const float highcut = s->highcut;
865 const float lowcut = s->lowcut;
866 const float angle = s->angle;
867 const float focus = s->focus;
868 float *magtotal = s->mag_total;
869 float *lfemag = s->lfe_mag;
870 float *lphase = s->l_phase;
871 float *rphase = s->r_phase;
872 float *cphase = s->c_phase;
873 float *cmag = s->c_mag;
874 float *xpos = s->x_pos;
875 float *ypos = s->y_pos;
876
877 for (int n = 0; n < rdft_size; n++) {
878 float l_re = srcl[2 * n], r_re = srcr[2 * n];
879 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
880 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
881 float c_phase = atan2f(c_im, c_re);
882 float c_mag = hypotf(c_re, c_im);
883 float l_mag = hypotf(l_re, l_im);
884 float r_mag = hypotf(r_re, r_im);
885 float mag_total = hypotf(l_mag, r_mag);
886 float l_phase = atan2f(l_im, l_re);
887 float r_phase = atan2f(r_im, r_re);
888 float phase_dif = fabsf(l_phase - r_phase);
889 float mag_sum = l_mag + r_mag;
890 float mag_dif, x, y;
891
892 mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum;
893 mag_dif = (l_mag - r_mag) / mag_sum;
894 if (phase_dif > M_PIf)
895 phase_dif = 2.f * M_PIf - phase_dif;
896
897 stereo_position(mag_dif, phase_dif, &x, &y);
898 angle_transform(&x, &y, angle);
899 focus_transform(&x, &y, focus);
900 get_lfe(output_lfe, n, lowcut, highcut, &lfemag[n], c_mag, &mag_total, lfe_mode);
901
902 xpos[n] = x;
903 ypos[n] = y;
904 lphase[n] = l_phase;
905 rphase[n] = r_phase;
906 cmag[n] = c_mag;
907 cphase[n] = c_phase;
908 magtotal[n] = mag_total;
909 }
910 }
911
912 static void filter_5_0_side(AVFilterContext *ctx)
913 {
914 AudioSurroundContext *s = ctx->priv;
915 const int rdft_size = s->rdft_size;
916 float *srcl, *srcr, *srcc, *srcsl, *srcsr;
917 int n;
918
919 srcl = (float *)s->input->extended_data[0];
920 srcr = (float *)s->input->extended_data[1];
921 srcc = (float *)s->input->extended_data[2];
922 srcsl = (float *)s->input->extended_data[3];
923 srcsr = (float *)s->input->extended_data[4];
924
925 for (n = 0; n < rdft_size; n++) {
926 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
927 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
928 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
929 float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
930 float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
931 float fl_mag = hypotf(fl_re, fl_im);
932 float fr_mag = hypotf(fr_re, fr_im);
933 float fl_phase = atan2f(fl_im, fl_re);
934 float fr_phase = atan2f(fr_im, fr_re);
935 float sl_mag = hypotf(sl_re, sl_im);
936 float sr_mag = hypotf(sr_re, sr_im);
937 float sl_phase = atan2f(sl_im, sl_re);
938 float sr_phase = atan2f(sr_im, sr_re);
939 float phase_difl = fabsf(fl_phase - sl_phase);
940 float phase_difr = fabsf(fr_phase - sr_phase);
941 float magl_sum = fl_mag + sl_mag;
942 float magr_sum = fr_mag + sr_mag;
943 float mag_difl = magl_sum < MIN_MAG_SUM ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
944 float mag_difr = magr_sum < MIN_MAG_SUM ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
945 float mag_totall = hypotf(fl_mag, sl_mag);
946 float mag_totalr = hypotf(fr_mag, sr_mag);
947 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
948 float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
949 float xl, yl;
950 float xr, yr;
951
952 if (phase_difl > M_PIf)
953 phase_difl = 2.f * M_PIf - phase_difl;
954
955 if (phase_difr > M_PIf)
956 phase_difr = 2.f * M_PIf - phase_difr;
957
958 stereo_position(mag_difl, phase_difl, &xl, &yl);
959 stereo_position(mag_difr, phase_difr, &xr, &yr);
960
961 s->upmix_5_0(ctx, c_re, c_im,
962 mag_totall, mag_totalr,
963 fl_phase, fr_phase,
964 bl_phase, br_phase,
965 sl_phase, sr_phase,
966 xl, yl, xr, yr, n);
967 }
968 }
969
970 static void filter_5_1_side(AVFilterContext *ctx)
971 {
972 AudioSurroundContext *s = ctx->priv;
973 const int rdft_size = s->rdft_size;
974 float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
975 int n;
976
977 srcl = (float *)s->input->extended_data[0];
978 srcr = (float *)s->input->extended_data[1];
979 srcc = (float *)s->input->extended_data[2];
980 srclfe = (float *)s->input->extended_data[3];
981 srcsl = (float *)s->input->extended_data[4];
982 srcsr = (float *)s->input->extended_data[5];
983
984 for (n = 0; n < rdft_size; n++) {
985 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
986 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
987 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
988 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
989 float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
990 float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
991 float fl_mag = hypotf(fl_re, fl_im);
992 float fr_mag = hypotf(fr_re, fr_im);
993 float fl_phase = atan2f(fl_im, fl_re);
994 float fr_phase = atan2f(fr_im, fr_re);
995 float sl_mag = hypotf(sl_re, sl_im);
996 float sr_mag = hypotf(sr_re, sr_im);
997 float sl_phase = atan2f(sl_im, sl_re);
998 float sr_phase = atan2f(sr_im, sr_re);
999 float phase_difl = fabsf(fl_phase - sl_phase);
1000 float phase_difr = fabsf(fr_phase - sr_phase);
1001 float magl_sum = fl_mag + sl_mag;
1002 float magr_sum = fr_mag + sr_mag;
1003 float mag_difl = magl_sum < MIN_MAG_SUM ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1004 float mag_difr = magr_sum < MIN_MAG_SUM ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1005 float mag_totall = hypotf(fl_mag, sl_mag);
1006 float mag_totalr = hypotf(fr_mag, sr_mag);
1007 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1008 float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1009 float xl, yl;
1010 float xr, yr;
1011
1012 if (phase_difl > M_PIf)
1013 phase_difl = 2.f * M_PIf - phase_difl;
1014
1015 if (phase_difr > M_PIf)
1016 phase_difr = 2.f * M_PIf - phase_difr;
1017
1018 stereo_position(mag_difl, phase_difl, &xl, &yl);
1019 stereo_position(mag_difr, phase_difr, &xr, &yr);
1020
1021 s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1022 mag_totall, mag_totalr,
1023 fl_phase, fr_phase,
1024 bl_phase, br_phase,
1025 sl_phase, sr_phase,
1026 xl, yl, xr, yr, n);
1027 }
1028 }
1029
1030 static void filter_5_1_back(AVFilterContext *ctx)
1031 {
1032 AudioSurroundContext *s = ctx->priv;
1033 const int rdft_size = s->rdft_size;
1034 float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
1035 int n;
1036
1037 srcl = (float *)s->input->extended_data[0];
1038 srcr = (float *)s->input->extended_data[1];
1039 srcc = (float *)s->input->extended_data[2];
1040 srclfe = (float *)s->input->extended_data[3];
1041 srcbl = (float *)s->input->extended_data[4];
1042 srcbr = (float *)s->input->extended_data[5];
1043
1044 for (n = 0; n < rdft_size; n++) {
1045 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1046 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1047 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1048 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1049 float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
1050 float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
1051 float fl_mag = hypotf(fl_re, fl_im);
1052 float fr_mag = hypotf(fr_re, fr_im);
1053 float fl_phase = atan2f(fl_im, fl_re);
1054 float fr_phase = atan2f(fr_im, fr_re);
1055 float bl_mag = hypotf(bl_re, bl_im);
1056 float br_mag = hypotf(br_re, br_im);
1057 float bl_phase = atan2f(bl_im, bl_re);
1058 float br_phase = atan2f(br_im, br_re);
1059 float phase_difl = fabsf(fl_phase - bl_phase);
1060 float phase_difr = fabsf(fr_phase - br_phase);
1061 float magl_sum = fl_mag + bl_mag;
1062 float magr_sum = fr_mag + br_mag;
1063 float mag_difl = magl_sum < MIN_MAG_SUM ? FFDIFFSIGN(fl_mag, bl_mag) : (fl_mag - bl_mag) / magl_sum;
1064 float mag_difr = magr_sum < MIN_MAG_SUM ? FFDIFFSIGN(fr_mag, br_mag) : (fr_mag - br_mag) / magr_sum;
1065 float mag_totall = hypotf(fl_mag, bl_mag);
1066 float mag_totalr = hypotf(fr_mag, br_mag);
1067 float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
1068 float sr_phase = atan2f(fr_im + br_im, fr_re + br_re);
1069 float xl, yl;
1070 float xr, yr;
1071
1072 if (phase_difl > M_PIf)
1073 phase_difl = 2.f * M_PIf - phase_difl;
1074
1075 if (phase_difr > M_PIf)
1076 phase_difr = 2.f * M_PIf - phase_difr;
1077
1078 stereo_position(mag_difl, phase_difl, &xl, &yl);
1079 stereo_position(mag_difr, phase_difr, &xr, &yr);
1080
1081 s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1082 mag_totall, mag_totalr,
1083 fl_phase, fr_phase,
1084 bl_phase, br_phase,
1085 sl_phase, sr_phase,
1086 xl, yl, xr, yr, n);
1087 }
1088 }
1089
1090 static void allchannels_spread(AVFilterContext *ctx)
1091 {
1092 AudioSurroundContext *s = ctx->priv;
1093
1094 if (s->all_x >= 0.f)
1095 for (int n = 0; n < SC_NB; n++)
1096 s->f_x[n] = s->all_x;
1097 s->all_x = -1.f;
1098 if (s->all_y >= 0.f)
1099 for (int n = 0; n < SC_NB; n++)
1100 s->f_y[n] = s->all_y;
1101 s->all_y = -1.f;
1102 }
1103
1104 static av_cold int init(AVFilterContext *ctx)
1105 {
1106 AudioSurroundContext *s = ctx->priv;
1107 int64_t in_channel_layout, out_channel_layout;
1108 char in_name[128], out_name[128];
1109 float overlap;
1110
1111 if (s->lowcutf >= s->highcutf) {
1112 av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
1113 s->lowcutf, s->highcutf);
1114 return AVERROR(EINVAL);
1115 }
1116
1117 in_channel_layout = s->in_ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1118 s->in_ch_layout.u.mask : 0;
1119 out_channel_layout = s->out_ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1120 s->out_ch_layout.u.mask : 0;
1121
1122 s->create_lfe = av_channel_layout_index_from_channel(&s->out_ch_layout,
1123 AV_CHAN_LOW_FREQUENCY) >= 0;
1124
1125 switch (out_channel_layout) {
1126 case AV_CH_LAYOUT_MONO:
1127 case AV_CH_LAYOUT_STEREO:
1128 case AV_CH_LAYOUT_2POINT1:
1129 case AV_CH_LAYOUT_2_1:
1130 case AV_CH_LAYOUT_2_2:
1131 case AV_CH_LAYOUT_SURROUND:
1132 case AV_CH_LAYOUT_3POINT1:
1133 case AV_CH_LAYOUT_QUAD:
1134 case AV_CH_LAYOUT_4POINT0:
1135 case AV_CH_LAYOUT_4POINT1:
1136 case AV_CH_LAYOUT_5POINT0:
1137 case AV_CH_LAYOUT_5POINT1:
1138 case AV_CH_LAYOUT_5POINT0_BACK:
1139 case AV_CH_LAYOUT_5POINT1_BACK:
1140 case AV_CH_LAYOUT_6POINT0:
1141 case AV_CH_LAYOUT_6POINT1:
1142 case AV_CH_LAYOUT_7POINT0:
1143 case AV_CH_LAYOUT_7POINT1:
1144 case AV_CH_LAYOUT_OCTAGONAL:
1145 break;
1146 default:
1147 goto fail;
1148 }
1149
1150 switch (in_channel_layout) {
1151 case AV_CH_LAYOUT_STEREO:
1152 s->filter = filter_stereo;
1153 s->upmix = stereo_upmix;
1154 break;
1155 case AV_CH_LAYOUT_2POINT1:
1156 s->filter = filter_2_1;
1157 s->upmix = l2_1_upmix;
1158 break;
1159 case AV_CH_LAYOUT_SURROUND:
1160 s->filter = filter_surround;
1161 s->upmix = surround_upmix;
1162 break;
1163 case AV_CH_LAYOUT_5POINT0:
1164 s->filter = filter_5_0_side;
1165 switch (out_channel_layout) {
1166 case AV_CH_LAYOUT_7POINT1:
1167 s->upmix_5_0 = upmix_7_1_5_0_side;
1168 break;
1169 default:
1170 goto fail;
1171 }
1172 break;
1173 case AV_CH_LAYOUT_5POINT1:
1174 s->filter = filter_5_1_side;
1175 switch (out_channel_layout) {
1176 case AV_CH_LAYOUT_7POINT1:
1177 s->upmix_5_1 = upmix_7_1_5_1;
1178 break;
1179 default:
1180 goto fail;
1181 }
1182 break;
1183 case AV_CH_LAYOUT_5POINT1_BACK:
1184 s->filter = filter_5_1_back;
1185 switch (out_channel_layout) {
1186 case AV_CH_LAYOUT_7POINT1:
1187 s->upmix_5_1 = upmix_7_1_5_1;
1188 break;
1189 default:
1190 goto fail;
1191 }
1192 break;
1193 default:
1194 fail:
1195 av_channel_layout_describe(&s->out_ch_layout, out_name, sizeof(out_name));
1196 av_channel_layout_describe(&s->in_ch_layout, in_name, sizeof(in_name));
1197 av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
1198 in_name, out_name);
1199 return AVERROR(EINVAL);
1200 }
1201
1202 s->window_func_lut = av_calloc(s->win_size, sizeof(*s->window_func_lut));
1203 if (!s->window_func_lut)
1204 return AVERROR(ENOMEM);
1205
1206 generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
1207 if (s->overlap == 1)
1208 s->overlap = overlap;
1209
1210 for (int i = 0; i < s->win_size; i++)
1211 s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->win_size);
1212 s->hop_size = FFMAX(1, s->win_size * (1. - s->overlap));
1213
1214 {
1215 float max = 0.f, *temp_lut = av_calloc(s->win_size, sizeof(*temp_lut));
1216 if (!temp_lut)
1217 return AVERROR(ENOMEM);
1218
1219 for (int j = 0; j < s->win_size; j += s->hop_size) {
1220 for (int i = 0; i < s->win_size; i++)
1221 temp_lut[(i + j) % s->win_size] += s->window_func_lut[i];
1222 }
1223
1224 for (int i = 0; i < s->win_size; i++)
1225 max = fmaxf(temp_lut[i], max);
1226 av_freep(&temp_lut);
1227
1228 s->win_gain = 1.f / (max * sqrtf(s->win_size));
1229 }
1230
1231 allchannels_spread(ctx);
1232
1233 return 0;
1234 }
1235
1236 static int fft_channel(AVFilterContext *ctx, AVFrame *in, int ch)
1237 {
1238 AudioSurroundContext *s = ctx->priv;
1239 float *src = (float *)s->input_in->extended_data[ch];
1240 float *win = (float *)s->window->extended_data[ch];
1241 const float *window_func_lut = s->window_func_lut;
1242 const int offset = s->win_size - s->hop_size;
1243 const float level_in = s->input_levels[ch];
1244 const int win_size = s->win_size;
1245
1246 memmove(src, &src[s->hop_size], offset * sizeof(float));
1247 memcpy(&src[offset], in->extended_data[ch], in->nb_samples * sizeof(float));
1248 memset(&src[offset + in->nb_samples], 0, (s->hop_size - in->nb_samples) * sizeof(float));
1249
1250 for (int n = 0; n < win_size; n++)
1251 win[n] = src[n] * window_func_lut[n] * level_in;
1252
1253 s->tx_fn(s->rdft[ch], (float *)s->input->extended_data[ch], win, sizeof(float));
1254
1255 return 0;
1256 }
1257
1258 static int fft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1259 {
1260 AVFrame *in = arg;
1261 const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
1262 const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
1263
1264 for (int ch = start; ch < end; ch++)
1265 fft_channel(ctx, in, ch);
1266
1267 return 0;
1268 }
1269
1270 static int ifft_channel(AVFilterContext *ctx, AVFrame *out, int ch)
1271 {
1272 AudioSurroundContext *s = ctx->priv;
1273 const float level_out = s->output_levels[ch] * s->win_gain;
1274 const float *window_func_lut = s->window_func_lut;
1275 const int win_size = s->win_size;
1276 float *dst, *ptr;
1277
1278 dst = (float *)s->output_out->extended_data[ch];
1279 ptr = (float *)s->overlap_buffer->extended_data[ch];
1280 s->itx_fn(s->irdft[ch], dst, (float *)s->output->extended_data[ch], sizeof(AVComplexFloat));
1281
1282 memmove(s->overlap_buffer->extended_data[ch],
1283 s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
1284 s->win_size * sizeof(float));
1285 memset(s->overlap_buffer->extended_data[ch] + s->win_size * sizeof(float),
1286 0, s->hop_size * sizeof(float));
1287
1288 for (int n = 0; n < win_size; n++)
1289 ptr[n] += dst[n] * window_func_lut[n] * level_out;
1290
1291 ptr = (float *)s->overlap_buffer->extended_data[ch];
1292 dst = (float *)out->extended_data[ch];
1293 memcpy(dst, ptr, s->hop_size * sizeof(float));
1294
1295 return 0;
1296 }
1297
1298 static int ifft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1299 {
1300 AudioSurroundContext *s = ctx->priv;
1301 AVFrame *out = arg;
1302 const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
1303 const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
1304
1305 for (int ch = start; ch < end; ch++) {
1306 if (s->upmix)
1307 s->upmix(ctx, ch);
1308 ifft_channel(ctx, out, ch);
1309 }
1310
1311 return 0;
1312 }
1313
1314 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
1315 {
1316 AVFilterContext *ctx = inlink->dst;
1317 AVFilterLink *outlink = ctx->outputs[0];
1318 AudioSurroundContext *s = ctx->priv;
1319 AVFrame *out;
1320
1321 ff_filter_execute(ctx, fft_channels, in, NULL,
1322 FFMIN(inlink->ch_layout.nb_channels,
1323 ff_filter_get_nb_threads(ctx)));
1324
1325 s->filter(ctx);
1326
1327 out = ff_get_audio_buffer(outlink, s->hop_size);
1328 if (!out)
1329 return AVERROR(ENOMEM);
1330
1331 ff_filter_execute(ctx, ifft_channels, out, NULL,
1332 FFMIN(outlink->ch_layout.nb_channels,
1333 ff_filter_get_nb_threads(ctx)));
1334
1335 av_frame_copy_props(out, in);
1336 out->nb_samples = in->nb_samples;
1337
1338 av_frame_free(&in);
1339 return ff_filter_frame(outlink, out);
1340 }
1341
1342 static int activate(AVFilterContext *ctx)
1343 {
1344 AVFilterLink *inlink = ctx->inputs[0];
1345 AVFilterLink *outlink = ctx->outputs[0];
1346 AudioSurroundContext *s = ctx->priv;
1347 AVFrame *in = NULL;
1348 int ret = 0, status;
1349 int64_t pts;
1350
1351 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
1352
1353 ret = ff_inlink_consume_samples(inlink, s->hop_size, s->hop_size, &in);
1354 if (ret < 0)
1355 return ret;
1356
1357 if (ret > 0)
1358 ret = filter_frame(inlink, in);
1359 if (ret < 0)
1360 return ret;
1361
1362 if (ff_inlink_queued_samples(inlink) >= s->hop_size) {
1363 ff_filter_set_ready(ctx, 10);
1364 return 0;
1365 }
1366
1367 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
1368 ff_outlink_set_status(outlink, status, pts);
1369 return 0;
1370 }
1371
1372 FF_FILTER_FORWARD_WANTED(outlink, inlink);
1373
1374 return FFERROR_NOT_READY;
1375 }
1376
1377 static av_cold void uninit(AVFilterContext *ctx)
1378 {
1379 AudioSurroundContext *s = ctx->priv;
1380
1381 av_frame_free(&s->factors);
1382 av_frame_free(&s->sfactors);
1383 av_frame_free(&s->window);
1384 av_frame_free(&s->input_in);
1385 av_frame_free(&s->input);
1386 av_frame_free(&s->output);
1387 av_frame_free(&s->output_ph);
1388 av_frame_free(&s->output_mag);
1389 av_frame_free(&s->output_out);
1390 av_frame_free(&s->overlap_buffer);
1391
1392 for (int ch = 0; ch < s->nb_in_channels; ch++)
1393 av_tx_uninit(&s->rdft[ch]);
1394 for (int ch = 0; ch < s->nb_out_channels; ch++)
1395 av_tx_uninit(&s->irdft[ch]);
1396 av_freep(&s->input_levels);
1397 av_freep(&s->output_levels);
1398 av_freep(&s->rdft);
1399 av_freep(&s->irdft);
1400 av_freep(&s->window_func_lut);
1401
1402 av_freep(&s->x_pos);
1403 av_freep(&s->y_pos);
1404 av_freep(&s->l_phase);
1405 av_freep(&s->r_phase);
1406 av_freep(&s->c_mag);
1407 av_freep(&s->c_phase);
1408 av_freep(&s->mag_total);
1409 av_freep(&s->lfe_mag);
1410 av_freep(&s->lfe_phase);
1411 }
1412
1413 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
1414 char *res, int res_len, int flags)
1415 {
1416 AudioSurroundContext *s = ctx->priv;
1417 int ret;
1418
1419 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1420 if (ret < 0)
1421 return ret;
1422
1423 s->hop_size = FFMAX(1, s->win_size * (1. - s->overlap));
1424
1425 allchannels_spread(ctx);
1426 set_input_levels(ctx);
1427 set_output_levels(ctx);
1428
1429 return 0;
1430 }
1431
1432 #define OFFSET(x) offsetof(AudioSurroundContext, x)
1433 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1434 #define TFLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1435
1436 static const AVOption surround_options[] = {
1437 { "chl_out", "set output channel layout", OFFSET(out_ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="5.1"}, 0, 0, FLAGS },
1438 { "chl_in", "set input channel layout", OFFSET(in_ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="stereo"},0, 0, FLAGS },
1439 { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1440 { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1441 { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, TFLAGS },
1442 { "lfe_low", "LFE low cut off", OFFSET(lowcutf), AV_OPT_TYPE_INT, {.i64=128}, 0, 256, FLAGS },
1443 { "lfe_high", "LFE high cut off", OFFSET(highcutf), AV_OPT_TYPE_INT, {.i64=256}, 0, 512, FLAGS },
1444 { "lfe_mode", "set LFE channel mode", OFFSET(lfe_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, TFLAGS, .unit = "lfe_mode" },
1445 { "add", "just add LFE channel", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 1, TFLAGS, .unit = "lfe_mode" },
1446 { "sub", "subtract LFE channel with others", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 1, TFLAGS, .unit = "lfe_mode" },
1447 { "smooth", "set temporal smoothness strength", OFFSET(smooth), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, TFLAGS },
1448 { "angle", "set soundfield transform angle", OFFSET(angle), AV_OPT_TYPE_FLOAT, {.dbl=90}, 0, 360, TFLAGS },
1449 { "focus", "set soundfield transform focus", OFFSET(focus), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, TFLAGS },
1450 { "fc_in", "set front center channel input level", OFFSET(f_i[SC_FC]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1451 { "fc_out", "set front center channel output level", OFFSET(f_o[SC_FC]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1452 { "fl_in", "set front left channel input level", OFFSET(f_i[SC_FL]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1453 { "fl_out", "set front left channel output level", OFFSET(f_o[SC_FL]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1454 { "fr_in", "set front right channel input level", OFFSET(f_i[SC_FR]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1455 { "fr_out", "set front right channel output level", OFFSET(f_o[SC_FR]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1456 { "sl_in", "set side left channel input level", OFFSET(f_i[SC_SL]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1457 { "sl_out", "set side left channel output level", OFFSET(f_o[SC_SL]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1458 { "sr_in", "set side right channel input level", OFFSET(f_i[SC_SR]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1459 { "sr_out", "set side right channel output level", OFFSET(f_o[SC_SR]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1460 { "bl_in", "set back left channel input level", OFFSET(f_i[SC_BL]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1461 { "bl_out", "set back left channel output level", OFFSET(f_o[SC_BL]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1462 { "br_in", "set back right channel input level", OFFSET(f_i[SC_BR]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1463 { "br_out", "set back right channel output level", OFFSET(f_o[SC_BR]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1464 { "bc_in", "set back center channel input level", OFFSET(f_i[SC_BC]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1465 { "bc_out", "set back center channel output level", OFFSET(f_o[SC_BC]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1466 { "lfe_in", "set lfe channel input level", OFFSET(f_i[SC_LF]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1467 { "lfe_out", "set lfe channel output level", OFFSET(f_o[SC_LF]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
1468 { "allx", "set all channel's x spread", OFFSET(all_x), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, TFLAGS },
1469 { "ally", "set all channel's y spread", OFFSET(all_y), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, TFLAGS },
1470 { "fcx", "set front center channel x spread", OFFSET(f_x[SC_FC]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1471 { "flx", "set front left channel x spread", OFFSET(f_x[SC_FL]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1472 { "frx", "set front right channel x spread", OFFSET(f_x[SC_FR]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1473 { "blx", "set back left channel x spread", OFFSET(f_x[SC_BL]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1474 { "brx", "set back right channel x spread", OFFSET(f_x[SC_BR]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1475 { "slx", "set side left channel x spread", OFFSET(f_x[SC_SL]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1476 { "srx", "set side right channel x spread", OFFSET(f_x[SC_SR]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1477 { "bcx", "set back center channel x spread", OFFSET(f_x[SC_BC]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1478 { "fcy", "set front center channel y spread", OFFSET(f_y[SC_FC]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1479 { "fly", "set front left channel y spread", OFFSET(f_y[SC_FL]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1480 { "fry", "set front right channel y spread", OFFSET(f_y[SC_FR]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1481 { "bly", "set back left channel y spread", OFFSET(f_y[SC_BL]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1482 { "bry", "set back right channel y spread", OFFSET(f_y[SC_BR]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1483 { "sly", "set side left channel y spread", OFFSET(f_y[SC_SL]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1484 { "sry", "set side right channel y spread", OFFSET(f_y[SC_SR]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1485 { "bcy", "set back center channel y spread", OFFSET(f_y[SC_BC]), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, TFLAGS },
1486 { "win_size", "set window size", OFFSET(win_size), AV_OPT_TYPE_INT, {.i64=4096},1024,65536,FLAGS },
1487 WIN_FUNC_OPTION("win_func", OFFSET(win_func), FLAGS, WFUNC_HANNING),
1488 { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, TFLAGS },
1489 { NULL }
1490 };
1491
1492 AVFILTER_DEFINE_CLASS(surround);
1493
1494 static const AVFilterPad inputs[] = {
1495 {
1496 .name = "default",
1497 .type = AVMEDIA_TYPE_AUDIO,
1498 .config_props = config_input,
1499 },
1500 };
1501
1502 static const AVFilterPad outputs[] = {
1503 {
1504 .name = "default",
1505 .type = AVMEDIA_TYPE_AUDIO,
1506 .config_props = config_output,
1507 },
1508 };
1509
1510 const AVFilter ff_af_surround = {
1511 .name = "surround",
1512 .description = NULL_IF_CONFIG_SMALL("Apply audio surround upmix filter."),
1513 .priv_size = sizeof(AudioSurroundContext),
1514 .priv_class = &surround_class,
1515 .init = init,
1516 .uninit = uninit,
1517 .activate = activate,
1518 FILTER_INPUTS(inputs),
1519 FILTER_OUTPUTS(outputs),
1520 FILTER_QUERY_FUNC(query_formats),
1521 .flags = AVFILTER_FLAG_SLICE_THREADS,
1522 .process_command = process_command,
1523 };
1524