FFmpeg
af_surround.c
Go to the documentation of this file.
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"
23 #include "libavutil/opt.h"
24 #include "libavutil/tx.h"
25 #include "avfilter.h"
26 #include "audio.h"
27 #include "filters.h"
28 #include "internal.h"
29 #include "formats.h"
30 #include "window_func.h"
31 
32 typedef struct AudioSurroundContext {
33  const AVClass *class;
34 
37 
38  float level_in;
39  float level_out;
40  float fc_in;
41  float fc_out;
42  float fl_in;
43  float fl_out;
44  float fr_in;
45  float fr_out;
46  float sl_in;
47  float sl_out;
48  float sr_in;
49  float sr_out;
50  float bl_in;
51  float bl_out;
52  float br_in;
53  float br_out;
54  float bc_in;
55  float bc_out;
56  float lfe_in;
57  float lfe_out;
58  int lfe_mode;
59  float angle;
60  int win_size;
61  int win_func;
62  float overlap;
63 
64  float all_x;
65  float all_y;
66 
67  float fc_x;
68  float fl_x;
69  float fr_x;
70  float bl_x;
71  float br_x;
72  float sl_x;
73  float sr_x;
74  float bc_x;
75 
76  float fc_y;
77  float fl_y;
78  float fr_y;
79  float bl_y;
80  float br_y;
81  float sl_y;
82  float sr_y;
83  float bc_y;
84 
85  float *input_levels;
86  float *output_levels;
88  int lowcutf;
89  int highcutf;
90 
91  float lowcut;
92  float highcut;
93 
98 
105 
106  int buf_size;
107  int hop_size;
111 
114  float l_phase,
115  float r_phase,
116  float c_phase,
117  float mag_total,
118  float x, float y,
119  int n);
121  float l_phase,
122  float r_phase,
123  float c_phase,
124  float mag_total,
125  float lfe_im,
126  float lfe_re,
127  float x, float y,
128  int n);
130  float l_phase,
131  float r_phase,
132  float c_mag,
133  float c_phase,
134  float mag_total,
135  float x, float y,
136  int n);
138  float c_re, float c_im,
139  float mag_totall, float mag_totalr,
140  float fl_phase, float fr_phase,
141  float bl_phase, float br_phase,
142  float sl_phase, float sr_phase,
143  float xl, float yl,
144  float xr, float yr,
145  int n);
147  float c_re, float c_im,
148  float lfe_re, float lfe_im,
149  float mag_totall, float mag_totalr,
150  float fl_phase, float fr_phase,
151  float bl_phase, float br_phase,
152  float sl_phase, float sr_phase,
153  float xl, float yl,
154  float xr, float yr,
155  int n);
157 
159 {
160  AudioSurroundContext *s = ctx->priv;
163  int ret;
164 
166  if (ret)
167  return ret;
169  if (ret)
170  return ret;
171 
172  layouts = NULL;
173  ret = ff_add_channel_layout(&layouts, &s->out_channel_layout);
174  if (ret)
175  return ret;
176 
177  ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts);
178  if (ret)
179  return ret;
180 
181  layouts = NULL;
182  ret = ff_add_channel_layout(&layouts, &s->in_channel_layout);
183  if (ret)
184  return ret;
185 
186  ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts);
187  if (ret)
188  return ret;
189 
191 }
192 
194 {
195  AVFilterContext *ctx = inlink->dst;
196  AudioSurroundContext *s = ctx->priv;
197  int ch;
198 
199  s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft));
200  if (!s->rdft)
201  return AVERROR(ENOMEM);
202  s->nb_in_channels = inlink->ch_layout.nb_channels;
203 
204  for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
205  float scale = 1.f;
206 
207  av_tx_init(&s->rdft[ch], &s->tx_fn, AV_TX_FLOAT_RDFT, 0, s->buf_size, &scale, 0);
208  if (!s->rdft[ch])
209  return AVERROR(ENOMEM);
210  }
211  s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
212  if (!s->input_levels)
213  return AVERROR(ENOMEM);
214  for (ch = 0; ch < s->nb_in_channels; ch++)
215  s->input_levels[ch] = s->level_in;
217  if (ch >= 0)
218  s->input_levels[ch] *= s->fc_in;
220  if (ch >= 0)
221  s->input_levels[ch] *= s->fl_in;
223  if (ch >= 0)
224  s->input_levels[ch] *= s->fr_in;
226  if (ch >= 0)
227  s->input_levels[ch] *= s->sl_in;
229  if (ch >= 0)
230  s->input_levels[ch] *= s->sr_in;
232  if (ch >= 0)
233  s->input_levels[ch] *= s->bl_in;
235  if (ch >= 0)
236  s->input_levels[ch] *= s->br_in;
238  if (ch >= 0)
239  s->input_levels[ch] *= s->bc_in;
241  if (ch >= 0)
242  s->input_levels[ch] *= s->lfe_in;
243 
244  s->window = ff_get_audio_buffer(inlink, s->buf_size * 2);
245  if (!s->window)
246  return AVERROR(ENOMEM);
247 
248  s->input_in = ff_get_audio_buffer(inlink, s->buf_size * 2);
249  if (!s->input_in)
250  return AVERROR(ENOMEM);
251 
252  s->input = ff_get_audio_buffer(inlink, s->buf_size + 2);
253  if (!s->input)
254  return AVERROR(ENOMEM);
255 
256  s->lowcut = 1.f * s->lowcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
257  s->highcut = 1.f * s->highcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
258 
259  return 0;
260 }
261 
262 static int config_output(AVFilterLink *outlink)
263 {
264  AVFilterContext *ctx = outlink->src;
265  AudioSurroundContext *s = ctx->priv;
266  int ch;
267 
268  s->irdft = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->irdft));
269  if (!s->irdft)
270  return AVERROR(ENOMEM);
271  s->nb_out_channels = outlink->ch_layout.nb_channels;
272 
273  for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
274  float iscale = 1.f;
275 
276  av_tx_init(&s->irdft[ch], &s->itx_fn, AV_TX_FLOAT_RDFT, 1, s->buf_size, &iscale, 0);
277  if (!s->irdft[ch])
278  return AVERROR(ENOMEM);
279  }
280  s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
281  if (!s->output_levels)
282  return AVERROR(ENOMEM);
283  for (ch = 0; ch < s->nb_out_channels; ch++)
284  s->output_levels[ch] = s->level_out;
286  if (ch >= 0)
287  s->output_levels[ch] *= s->fc_out;
289  if (ch >= 0)
290  s->output_levels[ch] *= s->fl_out;
292  if (ch >= 0)
293  s->output_levels[ch] *= s->fr_out;
295  if (ch >= 0)
296  s->output_levels[ch] *= s->sl_out;
298  if (ch >= 0)
299  s->output_levels[ch] *= s->sr_out;
301  if (ch >= 0)
302  s->output_levels[ch] *= s->bl_out;
304  if (ch >= 0)
305  s->output_levels[ch] *= s->br_out;
307  if (ch >= 0)
308  s->output_levels[ch] *= s->bc_out;
310  if (ch >= 0)
311  s->output_levels[ch] *= s->lfe_out;
312 
313  s->output_out = ff_get_audio_buffer(outlink, s->buf_size + 2);
314  s->output = ff_get_audio_buffer(outlink, s->buf_size + 2);
315  s->overlap_buffer = ff_get_audio_buffer(outlink, s->buf_size * 2);
316  if (!s->overlap_buffer || !s->output || !s->output_out)
317  return AVERROR(ENOMEM);
318 
319  return 0;
320 }
321 
322 static void stereo_transform(float *x, float *y, float angle)
323 {
324  float reference, r, a;
325 
326  if (angle == 90.f)
327  return;
328 
329  reference = angle * M_PI / 180.f;
330  r = hypotf(*x, *y);
331  a = atan2f(*x, *y);
332 
333  if (fabsf(a) <= M_PI_4)
334  a *= reference / M_PI_2;
335  else
336  a = M_PI + 2 * (-2 * M_PI + reference) * (M_PI - fabsf(a)) * FFDIFFSIGN(a, 0) / (3 * M_PI);
337 
338  *x = av_clipf(sinf(a) * r, -1.f, 1.f);
339  *y = av_clipf(cosf(a) * r, -1.f, 1.f);
340 }
341 
342 static void stereo_position(float a, float p, float *x, float *y)
343 {
344  av_assert2(a >= -1.f && a <= 1.f);
345  av_assert2(p >= 0.f && p <= M_PI);
346  *x = av_clipf(a+a*FFMAX(0, p*p-M_PI_2), -1.f, 1.f);
347  *y = av_clipf(cosf(a*M_PI_2+M_PI)*cosf(M_PI_2-p/M_PI)*M_LN10+1, -1.f, 1.f);
348 }
349 
350 static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut,
351  float *lfe_mag, float *mag_total, int lfe_mode)
352 {
353  if (output_lfe && n < highcut) {
354  *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PI*(lowcut-n)/(lowcut-highcut)));
355  *lfe_mag *= *mag_total;
356  if (lfe_mode)
357  *mag_total -= *lfe_mag;
358  } else {
359  *lfe_mag = 0.f;
360  }
361 }
362 
364  float l_phase,
365  float r_phase,
366  float c_phase,
367  float mag_total,
368  float x, float y,
369  int n)
370 {
371  AudioSurroundContext *s = ctx->priv;
372  float mag, *dst;
373 
374  dst = (float *)s->output->extended_data[0];
375 
376  mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
377 
378  dst[2 * n ] = mag * cosf(c_phase);
379  dst[2 * n + 1] = mag * sinf(c_phase);
380 }
381 
383  float l_phase,
384  float r_phase,
385  float c_phase,
386  float mag_total,
387  float x, float y,
388  int n)
389 {
390  AudioSurroundContext *s = ctx->priv;
391  float l_mag, r_mag, *dstl, *dstr;
392 
393  dstl = (float *)s->output->extended_data[0];
394  dstr = (float *)s->output->extended_data[1];
395 
396  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
397  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
398 
399  dstl[2 * n ] = l_mag * cosf(l_phase);
400  dstl[2 * n + 1] = l_mag * sinf(l_phase);
401 
402  dstr[2 * n ] = r_mag * cosf(r_phase);
403  dstr[2 * n + 1] = r_mag * sinf(r_phase);
404 }
405 
407  float l_phase,
408  float r_phase,
409  float c_phase,
410  float mag_total,
411  float x, float y,
412  int n)
413 {
414  AudioSurroundContext *s = ctx->priv;
415  float lfe_mag, l_mag, r_mag, *dstl, *dstr, *dstlfe;
416 
417  dstl = (float *)s->output->extended_data[0];
418  dstr = (float *)s->output->extended_data[1];
419  dstlfe = (float *)s->output->extended_data[2];
420 
421  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
422 
423  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
424  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
425 
426  dstl[2 * n ] = l_mag * cosf(l_phase);
427  dstl[2 * n + 1] = l_mag * sinf(l_phase);
428 
429  dstr[2 * n ] = r_mag * cosf(r_phase);
430  dstr[2 * n + 1] = r_mag * sinf(r_phase);
431 
432  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
433  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
434 }
435 
437  float l_phase,
438  float r_phase,
439  float c_phase,
440  float mag_total,
441  float x, float y,
442  int n)
443 {
444  AudioSurroundContext *s = ctx->priv;
445  float l_mag, r_mag, c_mag, *dstc, *dstl, *dstr;
446 
447  dstl = (float *)s->output->extended_data[0];
448  dstr = (float *)s->output->extended_data[1];
449  dstc = (float *)s->output->extended_data[2];
450 
451  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
452  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
453  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
454 
455  dstl[2 * n ] = l_mag * cosf(l_phase);
456  dstl[2 * n + 1] = l_mag * sinf(l_phase);
457 
458  dstr[2 * n ] = r_mag * cosf(r_phase);
459  dstr[2 * n + 1] = r_mag * sinf(r_phase);
460 
461  dstc[2 * n ] = c_mag * cosf(c_phase);
462  dstc[2 * n + 1] = c_mag * sinf(c_phase);
463 }
464 
466  float l_phase,
467  float r_phase,
468  float c_phase,
469  float mag_total,
470  float x, float y,
471  int n)
472 {
473  AudioSurroundContext *s = ctx->priv;
474  float lfe_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstlfe;
475 
476  dstl = (float *)s->output->extended_data[0];
477  dstr = (float *)s->output->extended_data[1];
478  dstc = (float *)s->output->extended_data[2];
479  dstlfe = (float *)s->output->extended_data[3];
480 
481  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
482 
483  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
484  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
485  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
486 
487  dstl[2 * n ] = l_mag * cosf(l_phase);
488  dstl[2 * n + 1] = l_mag * sinf(l_phase);
489 
490  dstr[2 * n ] = r_mag * cosf(r_phase);
491  dstr[2 * n + 1] = r_mag * sinf(r_phase);
492 
493  dstc[2 * n ] = c_mag * cosf(c_phase);
494  dstc[2 * n + 1] = c_mag * sinf(c_phase);
495 
496  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
497  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
498 }
499 
501  float l_phase,
502  float r_phase,
503  float c_phase,
504  float c_mag,
505  float mag_total,
506  float x, float y,
507  int n)
508 {
509  AudioSurroundContext *s = ctx->priv;
510  float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
511 
512  dstl = (float *)s->output->extended_data[0];
513  dstr = (float *)s->output->extended_data[1];
514  dstc = (float *)s->output->extended_data[2];
515  dstlfe = (float *)s->output->extended_data[3];
516 
517  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
518 
519  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
520  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
521 
522  dstl[2 * n ] = l_mag * cosf(l_phase);
523  dstl[2 * n + 1] = l_mag * sinf(l_phase);
524 
525  dstr[2 * n ] = r_mag * cosf(r_phase);
526  dstr[2 * n + 1] = r_mag * sinf(r_phase);
527 
528  dstc[2 * n ] = c_mag * cosf(c_phase);
529  dstc[2 * n + 1] = c_mag * sinf(c_phase);
530 
531  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
532  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
533 }
534 
536  float l_phase,
537  float r_phase,
538  float c_phase,
539  float mag_total,
540  float x, float y,
541  int n)
542 {
543  AudioSurroundContext *s = ctx->priv;
544  float b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb;
545 
546  dstl = (float *)s->output->extended_data[0];
547  dstr = (float *)s->output->extended_data[1];
548  dstc = (float *)s->output->extended_data[2];
549  dstb = (float *)s->output->extended_data[3];
550 
551  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
552  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
553  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
554  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
555 
556  dstl[2 * n ] = l_mag * cosf(l_phase);
557  dstl[2 * n + 1] = l_mag * sinf(l_phase);
558 
559  dstr[2 * n ] = r_mag * cosf(r_phase);
560  dstr[2 * n + 1] = r_mag * sinf(r_phase);
561 
562  dstc[2 * n ] = c_mag * cosf(c_phase);
563  dstc[2 * n + 1] = c_mag * sinf(c_phase);
564 
565  dstb[2 * n ] = b_mag * cosf(c_phase);
566  dstb[2 * n + 1] = b_mag * sinf(c_phase);
567 }
568 
570  float l_phase,
571  float r_phase,
572  float c_phase,
573  float mag_total,
574  float x, float y,
575  int n)
576 {
577  AudioSurroundContext *s = ctx->priv;
578  float lfe_mag, b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb, *dstlfe;
579 
580  dstl = (float *)s->output->extended_data[0];
581  dstr = (float *)s->output->extended_data[1];
582  dstc = (float *)s->output->extended_data[2];
583  dstlfe = (float *)s->output->extended_data[3];
584  dstb = (float *)s->output->extended_data[4];
585 
586  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
587 
588  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
589  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
590 
591  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
592  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
593  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
594  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
595 
596  dstl[2 * n ] = l_mag * cosf(l_phase);
597  dstl[2 * n + 1] = l_mag * sinf(l_phase);
598 
599  dstr[2 * n ] = r_mag * cosf(r_phase);
600  dstr[2 * n + 1] = r_mag * sinf(r_phase);
601 
602  dstc[2 * n ] = c_mag * cosf(c_phase);
603  dstc[2 * n + 1] = c_mag * sinf(c_phase);
604 
605  dstb[2 * n ] = b_mag * cosf(c_phase);
606  dstb[2 * n + 1] = b_mag * sinf(c_phase);
607 }
608 
610  float l_phase,
611  float r_phase,
612  float c_phase,
613  float mag_total,
614  float x, float y,
615  int n)
616 {
617  AudioSurroundContext *s = ctx->priv;
618  float l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs;
619 
620  dstl = (float *)s->output->extended_data[0];
621  dstr = (float *)s->output->extended_data[1];
622  dstc = (float *)s->output->extended_data[2];
623  dstls = (float *)s->output->extended_data[3];
624  dstrs = (float *)s->output->extended_data[4];
625 
626  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
627  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
628  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
629  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
630  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
631 
632  dstl[2 * n ] = l_mag * cosf(l_phase);
633  dstl[2 * n + 1] = l_mag * sinf(l_phase);
634 
635  dstr[2 * n ] = r_mag * cosf(r_phase);
636  dstr[2 * n + 1] = r_mag * sinf(r_phase);
637 
638  dstc[2 * n ] = c_mag * cosf(c_phase);
639  dstc[2 * n + 1] = c_mag * sinf(c_phase);
640 
641  dstls[2 * n ] = ls_mag * cosf(l_phase);
642  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
643 
644  dstrs[2 * n ] = rs_mag * cosf(r_phase);
645  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
646 }
647 
649  float l_phase,
650  float r_phase,
651  float c_phase,
652  float mag_total,
653  float x, float y,
654  int n)
655 {
656  AudioSurroundContext *s = ctx->priv;
657  float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
658 
659  dstl = (float *)s->output->extended_data[0];
660  dstr = (float *)s->output->extended_data[1];
661  dstc = (float *)s->output->extended_data[2];
662  dstlfe = (float *)s->output->extended_data[3];
663  dstls = (float *)s->output->extended_data[4];
664  dstrs = (float *)s->output->extended_data[5];
665 
666  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
667 
668  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
669  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
670  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
671  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
672  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
673 
674  dstl[2 * n ] = l_mag * cosf(l_phase);
675  dstl[2 * n + 1] = l_mag * sinf(l_phase);
676 
677  dstr[2 * n ] = r_mag * cosf(r_phase);
678  dstr[2 * n + 1] = r_mag * sinf(r_phase);
679 
680  dstc[2 * n ] = c_mag * cosf(c_phase);
681  dstc[2 * n + 1] = c_mag * sinf(c_phase);
682 
683  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
684  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
685 
686  dstls[2 * n ] = ls_mag * cosf(l_phase);
687  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
688 
689  dstrs[2 * n ] = rs_mag * cosf(r_phase);
690  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
691 }
692 
694  float l_phase,
695  float r_phase,
696  float c_phase,
697  float mag_total,
698  float x, float y,
699  int n)
700 {
701  AudioSurroundContext *s = ctx->priv;
702  float l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs;
703 
704  dstl = (float *)s->output->extended_data[0];
705  dstr = (float *)s->output->extended_data[1];
706  dstc = (float *)s->output->extended_data[2];
707  dstb = (float *)s->output->extended_data[3];
708  dstls = (float *)s->output->extended_data[4];
709  dstrs = (float *)s->output->extended_data[5];
710 
711  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
712  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
713  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
714  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
715  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
716  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
717 
718  dstl[2 * n ] = l_mag * cosf(l_phase);
719  dstl[2 * n + 1] = l_mag * sinf(l_phase);
720 
721  dstr[2 * n ] = r_mag * cosf(r_phase);
722  dstr[2 * n + 1] = r_mag * sinf(r_phase);
723 
724  dstc[2 * n ] = c_mag * cosf(c_phase);
725  dstc[2 * n + 1] = c_mag * sinf(c_phase);
726 
727  dstls[2 * n ] = ls_mag * cosf(l_phase);
728  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
729 
730  dstrs[2 * n ] = rs_mag * cosf(r_phase);
731  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
732 
733  dstb[2 * n ] = b_mag * cosf(c_phase);
734  dstb[2 * n + 1] = b_mag * sinf(c_phase);
735 }
736 
738  float l_phase,
739  float r_phase,
740  float c_phase,
741  float mag_total,
742  float x, float y,
743  int n)
744 {
745  AudioSurroundContext *s = ctx->priv;
746  float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
747 
748  dstl = (float *)s->output->extended_data[0];
749  dstr = (float *)s->output->extended_data[1];
750  dstc = (float *)s->output->extended_data[2];
751  dstlfe = (float *)s->output->extended_data[3];
752  dstb = (float *)s->output->extended_data[4];
753  dstls = (float *)s->output->extended_data[5];
754  dstrs = (float *)s->output->extended_data[6];
755 
756  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
757 
758  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
759  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
760  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
761  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
762  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
763  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
764 
765  dstl[2 * n ] = l_mag * cosf(l_phase);
766  dstl[2 * n + 1] = l_mag * sinf(l_phase);
767 
768  dstr[2 * n ] = r_mag * cosf(r_phase);
769  dstr[2 * n + 1] = r_mag * sinf(r_phase);
770 
771  dstc[2 * n ] = c_mag * cosf(c_phase);
772  dstc[2 * n + 1] = c_mag * sinf(c_phase);
773 
774  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
775  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
776 
777  dstls[2 * n ] = ls_mag * cosf(l_phase);
778  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
779 
780  dstrs[2 * n ] = rs_mag * cosf(r_phase);
781  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
782 
783  dstb[2 * n ] = b_mag * cosf(c_phase);
784  dstb[2 * n + 1] = b_mag * sinf(c_phase);
785 }
786 
788  float l_phase,
789  float r_phase,
790  float c_phase,
791  float c_mag,
792  float mag_total,
793  float x, float y,
794  int n)
795 {
796  AudioSurroundContext *s = ctx->priv;
797  float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
798  float ls_mag, rs_mag, *dstls, *dstrs;
799 
800  dstl = (float *)s->output->extended_data[0];
801  dstr = (float *)s->output->extended_data[1];
802  dstc = (float *)s->output->extended_data[2];
803  dstlfe = (float *)s->output->extended_data[3];
804  dstls = (float *)s->output->extended_data[4];
805  dstrs = (float *)s->output->extended_data[5];
806 
807  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
808 
809  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
810  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
811  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
812  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
813 
814  dstl[2 * n ] = l_mag * cosf(l_phase);
815  dstl[2 * n + 1] = l_mag * sinf(l_phase);
816 
817  dstr[2 * n ] = r_mag * cosf(r_phase);
818  dstr[2 * n + 1] = r_mag * sinf(r_phase);
819 
820  dstc[2 * n ] = c_mag * cosf(c_phase);
821  dstc[2 * n + 1] = c_mag * sinf(c_phase);
822 
823  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
824  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
825 
826  dstls[2 * n ] = ls_mag * cosf(l_phase);
827  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
828 
829  dstrs[2 * n ] = rs_mag * cosf(r_phase);
830  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
831 }
832 
834  float l_phase,
835  float r_phase,
836  float c_phase,
837  float mag_total,
838  float lfe_re,
839  float lfe_im,
840  float x, float y,
841  int n)
842 {
843  AudioSurroundContext *s = ctx->priv;
844  float c_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
845  float ls_mag, rs_mag, *dstls, *dstrs;
846 
847  dstl = (float *)s->output->extended_data[0];
848  dstr = (float *)s->output->extended_data[1];
849  dstc = (float *)s->output->extended_data[2];
850  dstlfe = (float *)s->output->extended_data[3];
851  dstls = (float *)s->output->extended_data[4];
852  dstrs = (float *)s->output->extended_data[5];
853 
854  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
855  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
856  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
857  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
858  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
859 
860  dstl[2 * n ] = l_mag * cosf(l_phase);
861  dstl[2 * n + 1] = l_mag * sinf(l_phase);
862 
863  dstr[2 * n ] = r_mag * cosf(r_phase);
864  dstr[2 * n + 1] = r_mag * sinf(r_phase);
865 
866  dstc[2 * n ] = c_mag * cosf(c_phase);
867  dstc[2 * n + 1] = c_mag * sinf(c_phase);
868 
869  dstlfe[2 * n ] = lfe_re;
870  dstlfe[2 * n + 1] = lfe_im;
871 
872  dstls[2 * n ] = ls_mag * cosf(l_phase);
873  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
874 
875  dstrs[2 * n ] = rs_mag * cosf(r_phase);
876  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
877 }
878 
880  float l_phase,
881  float r_phase,
882  float c_phase,
883  float mag_total,
884  float x, float y,
885  int n)
886 {
887  float l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
888  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb;
889  AudioSurroundContext *s = ctx->priv;
890 
891  dstl = (float *)s->output->extended_data[0];
892  dstr = (float *)s->output->extended_data[1];
893  dstc = (float *)s->output->extended_data[2];
894  dstlb = (float *)s->output->extended_data[3];
895  dstrb = (float *)s->output->extended_data[4];
896  dstls = (float *)s->output->extended_data[5];
897  dstrs = (float *)s->output->extended_data[6];
898 
899  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
900  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
901  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
902  lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
903  rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
904  ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
905  rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
906 
907  dstl[2 * n ] = l_mag * cosf(l_phase);
908  dstl[2 * n + 1] = l_mag * sinf(l_phase);
909 
910  dstr[2 * n ] = r_mag * cosf(r_phase);
911  dstr[2 * n + 1] = r_mag * sinf(r_phase);
912 
913  dstc[2 * n ] = c_mag * cosf(c_phase);
914  dstc[2 * n + 1] = c_mag * sinf(c_phase);
915 
916  dstlb[2 * n ] = lb_mag * cosf(l_phase);
917  dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
918 
919  dstrb[2 * n ] = rb_mag * cosf(r_phase);
920  dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
921 
922  dstls[2 * n ] = ls_mag * cosf(l_phase);
923  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
924 
925  dstrs[2 * n ] = rs_mag * cosf(r_phase);
926  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
927 }
928 
930  float l_phase,
931  float r_phase,
932  float c_phase,
933  float mag_total,
934  float x, float y,
935  int n)
936 {
937  float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
938  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
939  AudioSurroundContext *s = ctx->priv;
940 
941  dstl = (float *)s->output->extended_data[0];
942  dstr = (float *)s->output->extended_data[1];
943  dstc = (float *)s->output->extended_data[2];
944  dstlfe = (float *)s->output->extended_data[3];
945  dstlb = (float *)s->output->extended_data[4];
946  dstrb = (float *)s->output->extended_data[5];
947  dstls = (float *)s->output->extended_data[6];
948  dstrs = (float *)s->output->extended_data[7];
949 
950  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
951 
952  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
953  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
954  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
955  lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
956  rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
957  ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
958  rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
959 
960  dstl[2 * n ] = l_mag * cosf(l_phase);
961  dstl[2 * n + 1] = l_mag * sinf(l_phase);
962 
963  dstr[2 * n ] = r_mag * cosf(r_phase);
964  dstr[2 * n + 1] = r_mag * sinf(r_phase);
965 
966  dstc[2 * n ] = c_mag * cosf(c_phase);
967  dstc[2 * n + 1] = c_mag * sinf(c_phase);
968 
969  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
970  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
971 
972  dstlb[2 * n ] = lb_mag * cosf(l_phase);
973  dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
974 
975  dstrb[2 * n ] = rb_mag * cosf(r_phase);
976  dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
977 
978  dstls[2 * n ] = ls_mag * cosf(l_phase);
979  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
980 
981  dstrs[2 * n ] = rs_mag * cosf(r_phase);
982  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
983 }
984 
986  float c_re, float c_im,
987  float mag_totall, float mag_totalr,
988  float fl_phase, float fr_phase,
989  float bl_phase, float br_phase,
990  float sl_phase, float sr_phase,
991  float xl, float yl,
992  float xr, float yr,
993  int n)
994 {
995  float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
996  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
997  float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5;
998  AudioSurroundContext *s = ctx->priv;
999 
1000  dstl = (float *)s->output->extended_data[0];
1001  dstr = (float *)s->output->extended_data[1];
1002  dstc = (float *)s->output->extended_data[2];
1003  dstlfe = (float *)s->output->extended_data[3];
1004  dstlb = (float *)s->output->extended_data[4];
1005  dstrb = (float *)s->output->extended_data[5];
1006  dstls = (float *)s->output->extended_data[6];
1007  dstrs = (float *)s->output->extended_data[7];
1008 
1009  c_phase = atan2f(c_im, c_re);
1010 
1011  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
1012 
1013  fl_mag = powf(.5f * (xl + 1.f), s->fl_x) * powf((yl + 1.f) * .5f, s->fl_y) * mag_totall;
1014  fr_mag = powf(.5f * (xr + 1.f), s->fr_x) * powf((yr + 1.f) * .5f, s->fr_y) * mag_totalr;
1015  lb_mag = powf(.5f * (-xl + 1.f), s->bl_x) * powf((yl + 1.f) * .5f, s->bl_y) * mag_totall;
1016  rb_mag = powf(.5f * (-xr + 1.f), s->br_x) * powf((yr + 1.f) * .5f, s->br_y) * mag_totalr;
1017  ls_mag = powf(1.f - fabsf(xl), s->sl_x) * powf((yl + 1.f) * .5f, s->sl_y) * mag_totall;
1018  rs_mag = powf(1.f - fabsf(xr), s->sr_x) * powf((yr + 1.f) * .5f, s->sr_y) * mag_totalr;
1019 
1020  dstl[2 * n ] = fl_mag * cosf(fl_phase);
1021  dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
1022 
1023  dstr[2 * n ] = fr_mag * cosf(fr_phase);
1024  dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
1025 
1026  dstc[2 * n ] = c_re;
1027  dstc[2 * n + 1] = c_im;
1028 
1029  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
1030  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
1031 
1032  dstlb[2 * n ] = lb_mag * cosf(bl_phase);
1033  dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
1034 
1035  dstrb[2 * n ] = rb_mag * cosf(br_phase);
1036  dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
1037 
1038  dstls[2 * n ] = ls_mag * cosf(sl_phase);
1039  dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
1040 
1041  dstrs[2 * n ] = rs_mag * cosf(sr_phase);
1042  dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1043 }
1044 
1046  float c_re, float c_im,
1047  float lfe_re, float lfe_im,
1048  float mag_totall, float mag_totalr,
1049  float fl_phase, float fr_phase,
1050  float bl_phase, float br_phase,
1051  float sl_phase, float sr_phase,
1052  float xl, float yl,
1053  float xr, float yr,
1054  int n)
1055 {
1056  float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
1057  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
1058  AudioSurroundContext *s = ctx->priv;
1059 
1060  dstl = (float *)s->output->extended_data[0];
1061  dstr = (float *)s->output->extended_data[1];
1062  dstc = (float *)s->output->extended_data[2];
1063  dstlfe = (float *)s->output->extended_data[3];
1064  dstlb = (float *)s->output->extended_data[4];
1065  dstrb = (float *)s->output->extended_data[5];
1066  dstls = (float *)s->output->extended_data[6];
1067  dstrs = (float *)s->output->extended_data[7];
1068 
1069  fl_mag = powf(.5f * (xl + 1.f), s->fl_x) * powf((yl + 1.f) * .5f, s->fl_y) * mag_totall;
1070  fr_mag = powf(.5f * (xr + 1.f), s->fr_x) * powf((yr + 1.f) * .5f, s->fr_y) * mag_totalr;
1071  lb_mag = powf(.5f * (-xl + 1.f), s->bl_x) * powf((yl + 1.f) * .5f, s->bl_y) * mag_totall;
1072  rb_mag = powf(.5f * (-xr + 1.f), s->br_x) * powf((yr + 1.f) * .5f, s->br_y) * mag_totalr;
1073  ls_mag = powf(1.f - fabsf(xl), s->sl_x) * powf((yl + 1.f) * .5f, s->sl_y) * mag_totall;
1074  rs_mag = powf(1.f - fabsf(xr), s->sr_x) * powf((yr + 1.f) * .5f, s->sr_y) * mag_totalr;
1075 
1076  dstl[2 * n ] = fl_mag * cosf(fl_phase);
1077  dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
1078 
1079  dstr[2 * n ] = fr_mag * cosf(fr_phase);
1080  dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
1081 
1082  dstc[2 * n ] = c_re;
1083  dstc[2 * n + 1] = c_im;
1084 
1085  dstlfe[2 * n ] = lfe_re;
1086  dstlfe[2 * n + 1] = lfe_im;
1087 
1088  dstlb[2 * n ] = lb_mag * cosf(bl_phase);
1089  dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
1090 
1091  dstrb[2 * n ] = rb_mag * cosf(br_phase);
1092  dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
1093 
1094  dstls[2 * n ] = ls_mag * cosf(sl_phase);
1095  dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
1096 
1097  dstrs[2 * n ] = rs_mag * cosf(sr_phase);
1098  dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1099 }
1100 
1102 {
1103  AudioSurroundContext *s = ctx->priv;
1104  float *srcl, *srcr;
1105  int n;
1106 
1107  srcl = (float *)s->input->extended_data[0];
1108  srcr = (float *)s->input->extended_data[1];
1109 
1110  for (n = 0; n < s->buf_size / 2 + 1; n++) {
1111  float l_re = srcl[2 * n], r_re = srcr[2 * n];
1112  float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1113  float c_phase = atan2f(l_im + r_im, l_re + r_re);
1114  float l_mag = hypotf(l_re, l_im);
1115  float r_mag = hypotf(r_re, r_im);
1116  float l_phase = atan2f(l_im, l_re);
1117  float r_phase = atan2f(r_im, r_re);
1118  float phase_dif = fabsf(l_phase - r_phase);
1119  float mag_sum = l_mag + r_mag;
1120  float mag_dif = mag_sum < 0.000001 ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;
1121  float mag_total = hypotf(l_mag, r_mag);
1122  float x, y;
1123 
1124  if (phase_dif > M_PI)
1125  phase_dif = 2 * M_PI - phase_dif;
1126 
1127  stereo_position(mag_dif, phase_dif, &x, &y);
1128  stereo_transform(&x, &y, s->angle);
1129 
1130  s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);
1131  }
1132 }
1133 
1135 {
1136  AudioSurroundContext *s = ctx->priv;
1137  float *srcl, *srcr, *srcc;
1138  int n;
1139 
1140  srcl = (float *)s->input->extended_data[0];
1141  srcr = (float *)s->input->extended_data[1];
1142  srcc = (float *)s->input->extended_data[2];
1143 
1144  for (n = 0; n < s->buf_size / 2 + 1; n++) {
1145  float l_re = srcl[2 * n], r_re = srcr[2 * n];
1146  float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1147  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1148  float c_mag = hypotf(c_re, c_im);
1149  float c_phase = atan2f(c_im, c_re);
1150  float l_mag = hypotf(l_re, l_im);
1151  float r_mag = hypotf(r_re, r_im);
1152  float l_phase = atan2f(l_im, l_re);
1153  float r_phase = atan2f(r_im, r_re);
1154  float phase_dif = fabsf(l_phase - r_phase);
1155  float mag_sum = l_mag + r_mag;
1156  float mag_dif = mag_sum < 0.000001 ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;
1157  float mag_total = hypotf(l_mag, r_mag);
1158  float x, y;
1159 
1160  if (phase_dif > M_PI)
1161  phase_dif = 2 * M_PI - phase_dif;
1162 
1163  stereo_position(mag_dif, phase_dif, &x, &y);
1164  stereo_transform(&x, &y, s->angle);
1165 
1166  s->upmix_3_0(ctx, l_phase, r_phase, c_phase, c_mag, mag_total, x, y, n);
1167  }
1168 }
1169 
1171 {
1172  AudioSurroundContext *s = ctx->priv;
1173  float *srcl, *srcr, *srclfe;
1174  int n;
1175 
1176  srcl = (float *)s->input->extended_data[0];
1177  srcr = (float *)s->input->extended_data[1];
1178  srclfe = (float *)s->input->extended_data[2];
1179 
1180  for (n = 0; n < s->buf_size / 2 + 1; n++) {
1181  float l_re = srcl[2 * n], r_re = srcr[2 * n];
1182  float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1183  float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1184  float c_phase = atan2f(l_im + r_im, l_re + r_re);
1185  float l_mag = hypotf(l_re, l_im);
1186  float r_mag = hypotf(r_re, r_im);
1187  float l_phase = atan2f(l_im, l_re);
1188  float r_phase = atan2f(r_im, r_re);
1189  float phase_dif = fabsf(l_phase - r_phase);
1190  float mag_sum = l_mag + r_mag;
1191  float mag_dif = mag_sum < 0.000001 ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;
1192  float mag_total = hypotf(l_mag, r_mag);
1193  float x, y;
1194 
1195  if (phase_dif > M_PI)
1196  phase_dif = 2 * M_PI - phase_dif;
1197 
1198  stereo_position(mag_dif, phase_dif, &x, &y);
1199  stereo_transform(&x, &y, s->angle);
1200 
1201  s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
1202  }
1203 }
1204 
1206 {
1207  AudioSurroundContext *s = ctx->priv;
1208  float *srcl, *srcr, *srcc, *srcsl, *srcsr;
1209  int n;
1210 
1211  srcl = (float *)s->input->extended_data[0];
1212  srcr = (float *)s->input->extended_data[1];
1213  srcc = (float *)s->input->extended_data[2];
1214  srcsl = (float *)s->input->extended_data[3];
1215  srcsr = (float *)s->input->extended_data[4];
1216 
1217  for (n = 0; n < s->buf_size / 2 + 1; n++) {
1218  float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1219  float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1220  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1221  float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
1222  float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
1223  float fl_mag = hypotf(fl_re, fl_im);
1224  float fr_mag = hypotf(fr_re, fr_im);
1225  float fl_phase = atan2f(fl_im, fl_re);
1226  float fr_phase = atan2f(fr_im, fr_re);
1227  float sl_mag = hypotf(sl_re, sl_im);
1228  float sr_mag = hypotf(sr_re, sr_im);
1229  float sl_phase = atan2f(sl_im, sl_re);
1230  float sr_phase = atan2f(sr_im, sr_re);
1231  float phase_difl = fabsf(fl_phase - sl_phase);
1232  float phase_difr = fabsf(fr_phase - sr_phase);
1233  float magl_sum = fl_mag + sl_mag;
1234  float magr_sum = fr_mag + sr_mag;
1235  float mag_difl = magl_sum < 0.000001 ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1236  float mag_difr = magr_sum < 0.000001 ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1237  float mag_totall = hypotf(fl_mag, sl_mag);
1238  float mag_totalr = hypotf(fr_mag, sr_mag);
1239  float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1240  float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1241  float xl, yl;
1242  float xr, yr;
1243 
1244  if (phase_difl > M_PI)
1245  phase_difl = 2 * M_PI - phase_difl;
1246 
1247  if (phase_difr > M_PI)
1248  phase_difr = 2 * M_PI - phase_difr;
1249 
1250  stereo_position(mag_difl, phase_difl, &xl, &yl);
1251  stereo_position(mag_difr, phase_difr, &xr, &yr);
1252 
1253  s->upmix_5_0(ctx, c_re, c_im,
1254  mag_totall, mag_totalr,
1255  fl_phase, fr_phase,
1256  bl_phase, br_phase,
1257  sl_phase, sr_phase,
1258  xl, yl, xr, yr, n);
1259  }
1260 }
1261 
1263 {
1264  AudioSurroundContext *s = ctx->priv;
1265  float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
1266  int n;
1267 
1268  srcl = (float *)s->input->extended_data[0];
1269  srcr = (float *)s->input->extended_data[1];
1270  srcc = (float *)s->input->extended_data[2];
1271  srclfe = (float *)s->input->extended_data[3];
1272  srcsl = (float *)s->input->extended_data[4];
1273  srcsr = (float *)s->input->extended_data[5];
1274 
1275  for (n = 0; n < s->buf_size / 2 + 1; n++) {
1276  float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1277  float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1278  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1279  float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1280  float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
1281  float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
1282  float fl_mag = hypotf(fl_re, fl_im);
1283  float fr_mag = hypotf(fr_re, fr_im);
1284  float fl_phase = atan2f(fl_im, fl_re);
1285  float fr_phase = atan2f(fr_im, fr_re);
1286  float sl_mag = hypotf(sl_re, sl_im);
1287  float sr_mag = hypotf(sr_re, sr_im);
1288  float sl_phase = atan2f(sl_im, sl_re);
1289  float sr_phase = atan2f(sr_im, sr_re);
1290  float phase_difl = fabsf(fl_phase - sl_phase);
1291  float phase_difr = fabsf(fr_phase - sr_phase);
1292  float magl_sum = fl_mag + sl_mag;
1293  float magr_sum = fr_mag + sr_mag;
1294  float mag_difl = magl_sum < 0.000001 ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1295  float mag_difr = magr_sum < 0.000001 ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1296  float mag_totall = hypotf(fl_mag, sl_mag);
1297  float mag_totalr = hypotf(fr_mag, sr_mag);
1298  float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1299  float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1300  float xl, yl;
1301  float xr, yr;
1302 
1303  if (phase_difl > M_PI)
1304  phase_difl = 2 * M_PI - phase_difl;
1305 
1306  if (phase_difr > M_PI)
1307  phase_difr = 2 * M_PI - phase_difr;
1308 
1309  stereo_position(mag_difl, phase_difl, &xl, &yl);
1310  stereo_position(mag_difr, phase_difr, &xr, &yr);
1311 
1312  s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1313  mag_totall, mag_totalr,
1314  fl_phase, fr_phase,
1315  bl_phase, br_phase,
1316  sl_phase, sr_phase,
1317  xl, yl, xr, yr, n);
1318  }
1319 }
1320 
1322 {
1323  AudioSurroundContext *s = ctx->priv;
1324  float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
1325  int n;
1326 
1327  srcl = (float *)s->input->extended_data[0];
1328  srcr = (float *)s->input->extended_data[1];
1329  srcc = (float *)s->input->extended_data[2];
1330  srclfe = (float *)s->input->extended_data[3];
1331  srcbl = (float *)s->input->extended_data[4];
1332  srcbr = (float *)s->input->extended_data[5];
1333 
1334  for (n = 0; n < s->buf_size / 2 + 1; n++) {
1335  float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1336  float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1337  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1338  float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1339  float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
1340  float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
1341  float fl_mag = hypotf(fl_re, fl_im);
1342  float fr_mag = hypotf(fr_re, fr_im);
1343  float fl_phase = atan2f(fl_im, fl_re);
1344  float fr_phase = atan2f(fr_im, fr_re);
1345  float bl_mag = hypotf(bl_re, bl_im);
1346  float br_mag = hypotf(br_re, br_im);
1347  float bl_phase = atan2f(bl_im, bl_re);
1348  float br_phase = atan2f(br_im, br_re);
1349  float phase_difl = fabsf(fl_phase - bl_phase);
1350  float phase_difr = fabsf(fr_phase - br_phase);
1351  float magl_sum = fl_mag + bl_mag;
1352  float magr_sum = fr_mag + br_mag;
1353  float mag_difl = magl_sum < 0.000001 ? FFDIFFSIGN(fl_mag, bl_mag) : (fl_mag - bl_mag) / magl_sum;
1354  float mag_difr = magr_sum < 0.000001 ? FFDIFFSIGN(fr_mag, br_mag) : (fr_mag - br_mag) / magr_sum;
1355  float mag_totall = hypotf(fl_mag, bl_mag);
1356  float mag_totalr = hypotf(fr_mag, br_mag);
1357  float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
1358  float sr_phase = atan2f(fr_im + br_im, fr_re + br_re);
1359  float xl, yl;
1360  float xr, yr;
1361 
1362  if (phase_difl > M_PI)
1363  phase_difl = 2 * M_PI - phase_difl;
1364 
1365  if (phase_difr > M_PI)
1366  phase_difr = 2 * M_PI - phase_difr;
1367 
1368  stereo_position(mag_difl, phase_difl, &xl, &yl);
1369  stereo_position(mag_difr, phase_difr, &xr, &yr);
1370 
1371  s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1372  mag_totall, mag_totalr,
1373  fl_phase, fr_phase,
1374  bl_phase, br_phase,
1375  sl_phase, sr_phase,
1376  xl, yl, xr, yr, n);
1377  }
1378 }
1379 
1381 {
1382  AudioSurroundContext *s = ctx->priv;
1383  float overlap;
1384  int64_t in_channel_layout, out_channel_layout;
1385  int i, ret;
1386 
1387  if ((ret = av_channel_layout_from_string(&s->out_channel_layout, s->out_channel_layout_str)) < 0) {
1388  av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
1389  s->out_channel_layout_str);
1390  return ret;
1391  }
1392 
1393  if ((ret = av_channel_layout_from_string(&s->in_channel_layout, s->in_channel_layout_str)) < 0) {
1394  av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
1395  s->in_channel_layout_str);
1396  return AVERROR(EINVAL);
1397  }
1398 
1399  if (s->lowcutf >= s->highcutf) {
1400  av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
1401  s->lowcutf, s->highcutf);
1402  return AVERROR(EINVAL);
1403  }
1404 
1405  in_channel_layout = s->in_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1406  s->in_channel_layout.u.mask : 0;
1407  out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1408  s->out_channel_layout.u.mask : 0;
1409 
1410  switch (in_channel_layout) {
1411  case AV_CH_LAYOUT_STEREO:
1412  s->filter = filter_stereo;
1413  switch (out_channel_layout) {
1414  case AV_CH_LAYOUT_MONO:
1415  s->upmix_stereo = upmix_1_0;
1416  break;
1417  case AV_CH_LAYOUT_STEREO:
1418  s->upmix_stereo = upmix_stereo;
1419  break;
1420  case AV_CH_LAYOUT_2POINT1:
1421  s->upmix_stereo = upmix_2_1;
1422  break;
1423  case AV_CH_LAYOUT_SURROUND:
1424  s->upmix_stereo = upmix_3_0;
1425  break;
1426  case AV_CH_LAYOUT_3POINT1:
1427  s->upmix_stereo = upmix_3_1;
1428  break;
1429  case AV_CH_LAYOUT_4POINT0:
1430  s->upmix_stereo = upmix_4_0;
1431  break;
1432  case AV_CH_LAYOUT_4POINT1:
1433  s->upmix_stereo = upmix_4_1;
1434  break;
1436  s->upmix_stereo = upmix_5_0_back;
1437  break;
1439  s->upmix_stereo = upmix_5_1_back;
1440  break;
1441  case AV_CH_LAYOUT_6POINT0:
1442  s->upmix_stereo = upmix_6_0;
1443  break;
1444  case AV_CH_LAYOUT_6POINT1:
1445  s->upmix_stereo = upmix_6_1;
1446  break;
1447  case AV_CH_LAYOUT_7POINT0:
1448  s->upmix_stereo = upmix_7_0;
1449  break;
1450  case AV_CH_LAYOUT_7POINT1:
1451  s->upmix_stereo = upmix_7_1;
1452  break;
1453  default:
1454  goto fail;
1455  }
1456  break;
1457  case AV_CH_LAYOUT_2POINT1:
1458  s->filter = filter_2_1;
1459  switch (out_channel_layout) {
1461  s->upmix_2_1 = upmix_5_1_back_2_1;
1462  break;
1463  default:
1464  goto fail;
1465  }
1466  break;
1467  case AV_CH_LAYOUT_SURROUND:
1468  s->filter = filter_surround;
1469  switch (out_channel_layout) {
1470  case AV_CH_LAYOUT_3POINT1:
1471  s->upmix_3_0 = upmix_3_1_surround;
1472  break;
1474  s->upmix_3_0 = upmix_5_1_back_surround;
1475  break;
1476  default:
1477  goto fail;
1478  }
1479  break;
1480  case AV_CH_LAYOUT_5POINT0:
1481  s->filter = filter_5_0_side;
1482  switch (out_channel_layout) {
1483  case AV_CH_LAYOUT_7POINT1:
1484  s->upmix_5_0 = upmix_7_1_5_0_side;
1485  break;
1486  default:
1487  goto fail;
1488  }
1489  break;
1490  case AV_CH_LAYOUT_5POINT1:
1491  s->filter = filter_5_1_side;
1492  switch (out_channel_layout) {
1493  case AV_CH_LAYOUT_7POINT1:
1494  s->upmix_5_1 = upmix_7_1_5_1;
1495  break;
1496  default:
1497  goto fail;
1498  }
1499  break;
1501  s->filter = filter_5_1_back;
1502  switch (out_channel_layout) {
1503  case AV_CH_LAYOUT_7POINT1:
1504  s->upmix_5_1 = upmix_7_1_5_1;
1505  break;
1506  default:
1507  goto fail;
1508  }
1509  break;
1510  default:
1511 fail:
1512  av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
1513  s->in_channel_layout_str, s->out_channel_layout_str);
1514  return AVERROR(EINVAL);
1515  }
1516 
1517  s->buf_size = 1 << av_log2(s->win_size);
1518 
1519  s->window_func_lut = av_calloc(s->buf_size, sizeof(*s->window_func_lut));
1520  if (!s->window_func_lut)
1521  return AVERROR(ENOMEM);
1522 
1523  generate_window_func(s->window_func_lut, s->buf_size, s->win_func, &overlap);
1524  if (s->overlap == 1)
1525  s->overlap = overlap;
1526 
1527  for (i = 0; i < s->buf_size; i++)
1528  s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->buf_size);
1529  s->hop_size = s->buf_size * (1. - s->overlap);
1530  if (s->hop_size <= 0)
1531  return AVERROR(EINVAL);
1532 
1533  if (s->all_x >= 0.f)
1534  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;
1535  if (s->all_y >= 0.f)
1536  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;
1537 
1538  return 0;
1539 }
1540 
1541 static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1542 {
1543  AudioSurroundContext *s = ctx->priv;
1544  float *src = (float *)s->input_in->extended_data[ch];
1545  float *win = (float *)s->window->extended_data[ch];
1546  const int offset = s->buf_size - s->hop_size;
1547  const float level_in = s->input_levels[ch];
1548  AVFrame *in = arg;
1549 
1550  memmove(src, &src[s->hop_size], offset * sizeof(float));
1551  memcpy(&src[offset], in->extended_data[ch], in->nb_samples * sizeof(float));
1552  memset(&src[offset + in->nb_samples], 0, (s->hop_size - in->nb_samples) * sizeof(float));
1553 
1554  for (int n = 0; n < s->buf_size; n++) {
1555  win[n] = src[n] * s->window_func_lut[n] * level_in;
1556  }
1557 
1558  s->tx_fn(s->rdft[ch], (float *)s->input->extended_data[ch], win, sizeof(float));
1559 
1560  return 0;
1561 }
1562 
1563 static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1564 {
1565  AudioSurroundContext *s = ctx->priv;
1566  const float level_out = s->output_levels[ch];
1567  AVFrame *out = arg;
1568  float *dst, *ptr;
1569  int n;
1570 
1571  dst = (float *)s->output_out->extended_data[ch];
1572  ptr = (float *)s->overlap_buffer->extended_data[ch];
1573  s->itx_fn(s->irdft[ch], dst, (float *)s->output->extended_data[ch], sizeof(float));
1574 
1575  memmove(s->overlap_buffer->extended_data[ch],
1576  s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
1577  s->buf_size * sizeof(float));
1578  memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),
1579  0, s->hop_size * sizeof(float));
1580 
1581  for (n = 0; n < s->buf_size; n++) {
1582  ptr[n] += dst[n] * s->window_func_lut[n] * level_out;
1583  }
1584 
1585  ptr = (float *)s->overlap_buffer->extended_data[ch];
1586  dst = (float *)out->extended_data[ch];
1587  memcpy(dst, ptr, s->hop_size * sizeof(float));
1588 
1589  return 0;
1590 }
1591 
1593 {
1594  AVFilterContext *ctx = inlink->dst;
1595  AVFilterLink *outlink = ctx->outputs[0];
1596  AudioSurroundContext *s = ctx->priv;
1597  AVFrame *out;
1598 
1599  ff_filter_execute(ctx, fft_channel, in, NULL, inlink->ch_layout.nb_channels);
1600 
1601  s->filter(ctx);
1602 
1603  out = ff_get_audio_buffer(outlink, s->hop_size);
1604  if (!out)
1605  return AVERROR(ENOMEM);
1606 
1608 
1609  out->pts = in->pts;
1610  out->nb_samples = in->nb_samples;
1611 
1612  av_frame_free(&in);
1613  return ff_filter_frame(outlink, out);
1614 }
1615 
1617 {
1618  AVFilterLink *inlink = ctx->inputs[0];
1619  AVFilterLink *outlink = ctx->outputs[0];
1620  AudioSurroundContext *s = ctx->priv;
1621  AVFrame *in = NULL;
1622  int ret = 0, status;
1623  int64_t pts;
1624 
1626 
1627  ret = ff_inlink_consume_samples(inlink, s->hop_size, s->hop_size, &in);
1628  if (ret < 0)
1629  return ret;
1630 
1631  if (ret > 0)
1632  ret = filter_frame(inlink, in);
1633  if (ret < 0)
1634  return ret;
1635 
1636  if (ff_inlink_queued_samples(inlink) >= s->hop_size) {
1637  ff_filter_set_ready(ctx, 10);
1638  return 0;
1639  }
1640 
1642  ff_outlink_set_status(outlink, status, pts);
1643  return 0;
1644  }
1645 
1646  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1647 
1648  return FFERROR_NOT_READY;
1649 }
1650 
1652 {
1653  AudioSurroundContext *s = ctx->priv;
1654 
1655  av_frame_free(&s->window);
1656  av_frame_free(&s->input_in);
1657  av_frame_free(&s->input);
1658  av_frame_free(&s->output);
1659  av_frame_free(&s->output_out);
1660  av_frame_free(&s->overlap_buffer);
1661 
1662  for (int ch = 0; ch < s->nb_in_channels; ch++)
1663  av_tx_uninit(&s->rdft[ch]);
1664  for (int ch = 0; ch < s->nb_out_channels; ch++)
1665  av_tx_uninit(&s->irdft[ch]);
1666  av_freep(&s->input_levels);
1667  av_freep(&s->output_levels);
1668  av_freep(&s->rdft);
1669  av_freep(&s->irdft);
1670  av_freep(&s->window_func_lut);
1671 }
1672 
1673 #define OFFSET(x) offsetof(AudioSurroundContext, x)
1674 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1675 
1676 static const AVOption surround_options[] = {
1677  { "chl_out", "set output channel layout", OFFSET(out_channel_layout_str), AV_OPT_TYPE_STRING, {.str="5.1"}, 0, 0, FLAGS },
1678  { "chl_in", "set input channel layout", OFFSET(in_channel_layout_str), AV_OPT_TYPE_STRING, {.str="stereo"},0, 0, FLAGS },
1679  { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1680  { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1681  { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
1682  { "lfe_low", "LFE low cut off", OFFSET(lowcutf), AV_OPT_TYPE_INT, {.i64=128}, 0, 256, FLAGS },
1683  { "lfe_high", "LFE high cut off", OFFSET(highcutf), AV_OPT_TYPE_INT, {.i64=256}, 0, 512, FLAGS },
1684  { "lfe_mode", "set LFE channel mode", OFFSET(lfe_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
1685  { "add", "just add LFE channel", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
1686  { "sub", "substract LFE channel with others", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 1, FLAGS, "lfe_mode" },
1687  { "angle", "set soundfield transform angle", OFFSET(angle), AV_OPT_TYPE_FLOAT, {.dbl=90}, 0, 360, FLAGS },
1688  { "fc_in", "set front center channel input level", OFFSET(fc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1689  { "fc_out", "set front center channel output level", OFFSET(fc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1690  { "fl_in", "set front left channel input level", OFFSET(fl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1691  { "fl_out", "set front left channel output level", OFFSET(fl_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1692  { "fr_in", "set front right channel input level", OFFSET(fr_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1693  { "fr_out", "set front right channel output level", OFFSET(fr_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1694  { "sl_in", "set side left channel input level", OFFSET(sl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1695  { "sl_out", "set side left channel output level", OFFSET(sl_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1696  { "sr_in", "set side right channel input level", OFFSET(sr_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1697  { "sr_out", "set side right channel output level", OFFSET(sr_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1698  { "bl_in", "set back left channel input level", OFFSET(bl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1699  { "bl_out", "set back left channel output level", OFFSET(bl_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1700  { "br_in", "set back right channel input level", OFFSET(br_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1701  { "br_out", "set back right channel output level", OFFSET(br_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1702  { "bc_in", "set back center channel input level", OFFSET(bc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1703  { "bc_out", "set back center channel output level", OFFSET(bc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1704  { "lfe_in", "set lfe channel input level", OFFSET(lfe_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1705  { "lfe_out", "set lfe channel output level", OFFSET(lfe_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1706  { "allx", "set all channel's x spread", OFFSET(all_x), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, FLAGS },
1707  { "ally", "set all channel's y spread", OFFSET(all_y), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, FLAGS },
1708  { "fcx", "set front center channel x spread", OFFSET(fc_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1709  { "flx", "set front left channel x spread", OFFSET(fl_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1710  { "frx", "set front right channel x spread", OFFSET(fr_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1711  { "blx", "set back left channel x spread", OFFSET(bl_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1712  { "brx", "set back right channel x spread", OFFSET(br_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1713  { "slx", "set side left channel x spread", OFFSET(sl_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1714  { "srx", "set side right channel x spread", OFFSET(sr_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1715  { "bcx", "set back center channel x spread", OFFSET(bc_x), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1716  { "fcy", "set front center channel y spread", OFFSET(fc_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1717  { "fly", "set front left channel y spread", OFFSET(fl_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1718  { "fry", "set front right channel y spread", OFFSET(fr_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1719  { "bly", "set back left channel y spread", OFFSET(bl_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1720  { "bry", "set back right channel y spread", OFFSET(br_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1721  { "sly", "set side left channel y spread", OFFSET(sl_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1722  { "sry", "set side right channel y spread", OFFSET(sr_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1723  { "bcy", "set back center channel y spread", OFFSET(bc_y), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, .06, 15, FLAGS },
1724  { "win_size", "set window size", OFFSET(win_size), AV_OPT_TYPE_INT, {.i64 = 4096}, 1024, 65536, FLAGS },
1725  WIN_FUNC_OPTION("win_func", OFFSET(win_func), FLAGS, WFUNC_HANNING),
1726  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
1727  { NULL }
1728 };
1729 
1730 AVFILTER_DEFINE_CLASS(surround);
1731 
1732 static const AVFilterPad inputs[] = {
1733  {
1734  .name = "default",
1735  .type = AVMEDIA_TYPE_AUDIO,
1736  .config_props = config_input,
1737  },
1738 };
1739 
1740 static const AVFilterPad outputs[] = {
1741  {
1742  .name = "default",
1743  .type = AVMEDIA_TYPE_AUDIO,
1744  .config_props = config_output,
1745  },
1746 };
1747 
1749  .name = "surround",
1750  .description = NULL_IF_CONFIG_SMALL("Apply audio surround upmix filter."),
1751  .priv_size = sizeof(AudioSurroundContext),
1752  .priv_class = &surround_class,
1753  .init = init,
1754  .uninit = uninit,
1755  .activate = activate,
1759  .flags = AVFILTER_FLAG_SLICE_THREADS,
1760 };
AV_CHAN_BACK_RIGHT
@ AV_CHAN_BACK_RIGHT
Definition: channel_layout.h:49
AV_CH_LAYOUT_7POINT0
#define AV_CH_LAYOUT_7POINT0
Definition: channel_layout.h:224
formats
formats
Definition: signature.h:48
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:100
AudioSurroundContext::upmix_5_1
void(* upmix_5_1)(AVFilterContext *ctx, float c_re, float c_im, float lfe_re, float lfe_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
Definition: af_surround.c:146
upmix_4_0
static void upmix_4_0(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:535
AV_CH_LAYOUT_6POINT1
#define AV_CH_LAYOUT_6POINT1
Definition: channel_layout.h:221
upmix_7_1_5_1
static void upmix_7_1_5_1(AVFilterContext *ctx, float c_re, float c_im, float lfe_re, float lfe_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
Definition: af_surround.c:1045
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
AV_CH_LAYOUT_5POINT0_BACK
#define AV_CH_LAYOUT_5POINT0_BACK
Definition: channel_layout.h:216
r
const char * r
Definition: vf_curves.c:116
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AudioSurroundContext::highcutf
int highcutf
Definition: af_surround.c:89
opt.h
AudioSurroundContext
Definition: af_surround.c:32
AudioSurroundContext::fl_x
float fl_x
Definition: af_surround.c:68
AudioSurroundContext::fr_y
float fr_y
Definition: af_surround.c:78
out
FILE * out
Definition: movenc.c:54
AudioSurroundContext::upmix_2_1
void(* upmix_2_1)(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float lfe_im, float lfe_re, float x, float y, int n)
Definition: af_surround.c:120
AudioSurroundContext::br_x
float br_x
Definition: af_surround.c:71
AudioSurroundContext::sr_y
float sr_y
Definition: af_surround.c:82
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:999
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:591
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:330
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AudioSurroundContext::input
AVFrame * input
Definition: af_surround.c:100
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:204
AVTXContext
Definition: tx_priv.h:201
atan2f
#define atan2f(y, x)
Definition: libm.h:45
AudioSurroundContext::bl_in
float bl_in
Definition: af_surround.c:50
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
OFFSET
#define OFFSET(x)
Definition: af_surround.c:1673
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:111
AudioSurroundContext::sl_y
float sl_y
Definition: af_surround.c:81
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:432
AudioSurroundContext::hop_size
int hop_size
Definition: af_surround.c:107
AudioSurroundContext::sl_x
float sl_x
Definition: af_surround.c:72
AudioSurroundContext::out_channel_layout
AVChannelLayout out_channel_layout
Definition: af_surround.c:94
AudioSurroundContext::output_levels
float * output_levels
Definition: af_surround.c:86
M_PI_2
#define M_PI_2
Definition: mathematics.h:55
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:47
AudioSurroundContext::nb_out_channels
int nb_out_channels
Definition: af_surround.c:97
AVOption
AVOption.
Definition: opt.h:251
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:167
AudioSurroundContext::input_in
AVFrame * input_in
Definition: af_surround.c:99
ff_set_common_all_samplerates
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition: formats.c:739
WIN_FUNC_OPTION
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
Definition: window_func.h:37
AudioSurroundContext::upmix_3_0
void(* upmix_3_0)(AVFilterContext *ctx, float l_phase, float r_phase, float c_mag, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:129
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
AudioSurroundContext::overlap
float overlap
Definition: af_surround.c:62
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
AudioSurroundContext::fc_y
float fc_y
Definition: af_surround.c:76
upmix_2_1
static void upmix_2_1(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:406
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
AudioSurroundContext::lfe_mode
int lfe_mode
Definition: af_surround.c:58
AudioSurroundContext::fc_in
float fc_in
Definition: af_surround.c:40
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:649
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
formats.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_surround.c:1651
AudioSurroundContext::output_lfe
int output_lfe
Definition: af_surround.c:87
AV_CH_LAYOUT_6POINT0
#define AV_CH_LAYOUT_6POINT0
Definition: channel_layout.h:218
upmix_6_0
static void upmix_6_0(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:693
upmix_5_0_back
static void upmix_5_0_back(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:609
cosf
#define cosf(x)
Definition: libm.h:78
fail
#define fail()
Definition: checkasm.h:131
AudioSurroundContext::all_y
float all_y
Definition: af_surround.c:65
AudioSurroundContext::sr_out
float sr_out
Definition: af_surround.c:49
AudioSurroundContext::level_in
float level_in
Definition: af_surround.c:38
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
pts
static int64_t pts
Definition: transcode_aac.c:654
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:205
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: macros.h:45
FLAGS
#define FLAGS
Definition: af_surround.c:1674
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:749
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:111
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:112
filter_5_1_back
static void filter_5_1_back(AVFilterContext *ctx)
Definition: af_surround.c:1321
float
float
Definition: af_crystalizer.c:122
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
upmix_5_1_back
static void upmix_5_1_back(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:648
AV_CHAN_FRONT_RIGHT
@ AV_CHAN_FRONT_RIGHT
Definition: channel_layout.h:45
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_surround.c:158
s
#define s(width, name)
Definition: cbs_vp9.c:256
ff_af_surround
const AVFilter ff_af_surround
Definition: af_surround.c:1748
AudioSurroundContext::fr_in
float fr_in
Definition: af_surround.c:44
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AudioSurroundContext::br_in
float br_in
Definition: af_surround.c:52
surround_options
static const AVOption surround_options[]
Definition: af_surround.c:1676
outputs
static const AVFilterPad outputs[]
Definition: af_surround.c:1740
AudioSurroundContext::buf_size
int buf_size
Definition: af_surround.c:106
upmix_3_1_surround
static void upmix_3_1_surround(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float c_mag, float mag_total, float x, float y, int n)
Definition: af_surround.c:500
upmix_7_1
static void upmix_7_1(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:929
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AudioSurroundContext::overlap_buffer
AVFrame * overlap_buffer
Definition: af_surround.c:103
AudioSurroundContext::fr_x
float fr_x
Definition: af_surround.c:69
AudioSurroundContext::output_out
AVFrame * output_out
Definition: af_surround.c:102
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
AudioSurroundContext::upmix_5_0
void(* upmix_5_0)(AVFilterContext *ctx, float c_re, float c_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
Definition: af_surround.c:137
arg
const char * arg
Definition: jacosubdec.c:67
AudioSurroundContext::br_y
float br_y
Definition: af_surround.c:80
AudioSurroundContext::lowcutf
int lowcutf
Definition: af_surround.c:88
AudioSurroundContext::bc_in
float bc_in
Definition: af_surround.c:54
AudioSurroundContext::in_channel_layout
AVChannelLayout in_channel_layout
Definition: af_surround.c:95
AudioSurroundContext::level_out
float level_out
Definition: af_surround.c:39
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1413
NULL
#define NULL
Definition: coverity.c:32
AudioSurroundContext::sr_x
float sr_x
Definition: af_surround.c:73
filter_stereo
static void filter_stereo(AVFilterContext *ctx)
Definition: af_surround.c:1101
AudioSurroundContext::irdft
AVTXContext ** irdft
Definition: af_surround.c:108
AudioSurroundContext::filter
void(* filter)(AVFilterContext *ctx)
Definition: af_surround.c:112
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:449
AV_CHAN_FRONT_LEFT
@ AV_CHAN_FRONT_LEFT
Definition: channel_layout.h:44
filter_5_0_side
static void filter_5_0_side(AVFilterContext *ctx)
Definition: af_surround.c:1205
AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_5POINT1
Definition: channel_layout.h:215
AudioSurroundContext::lowcut
float lowcut
Definition: af_surround.c:91
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:61
AudioSurroundContext::fc_x
float fc_x
Definition: af_surround.c:67
WFUNC_HANNING
@ WFUNC_HANNING
Definition: window_func.h:29
AudioSurroundContext::input_levels
float * input_levels
Definition: af_surround.c:85
sinf
#define sinf(x)
Definition: libm.h:419
AudioSurroundContext::nb_in_channels
int nb_in_channels
Definition: af_surround.c:96
stereo_transform
static void stereo_transform(float *x, float *y, float angle)
Definition: af_surround.c:322
av_clipf
av_clipf
Definition: af_crystalizer.c:122
fft_channel
static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_surround.c:1541
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:466
ifft_channel
static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_surround.c:1563
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1348
AudioSurroundContext::bl_out
float bl_out
Definition: af_surround.c:51
upmix_4_1
static void upmix_4_1(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:569
AV_CHAN_SIDE_RIGHT
@ AV_CHAN_SIDE_RIGHT
Definition: channel_layout.h:54
AV_CHAN_BACK_LEFT
@ AV_CHAN_BACK_LEFT
Definition: channel_layout.h:48
f
f
Definition: af_crystalizer.c:122
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
powf
#define powf(x, y)
Definition: libm.h:50
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:290
AudioSurroundContext::out_channel_layout_str
char * out_channel_layout_str
Definition: af_surround.c:35
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
activate
static int activate(AVFilterContext *ctx)
Definition: af_surround.c:1616
AV_CHAN_BACK_CENTER
@ AV_CHAN_BACK_CENTER
Definition: channel_layout.h:52
AudioSurroundContext::fl_out
float fl_out
Definition: af_surround.c:43
AudioSurroundContext::sl_out
float sl_out
Definition: af_surround.c:47
AudioSurroundContext::in_channel_layout_str
char * in_channel_layout_str
Definition: af_surround.c:36
AudioSurroundContext::lfe_out
float lfe_out
Definition: af_surround.c:57
AudioSurroundContext::fc_out
float fc_out
Definition: af_surround.c:41
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_CHAN_SIDE_LEFT
@ AV_CHAN_SIDE_LEFT
Definition: channel_layout.h:53
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_surround.c:1592
AV_CH_LAYOUT_5POINT1_BACK
#define AV_CH_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:217
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
AudioSurroundContext::sl_in
float sl_in
Definition: af_surround.c:46
M_PI
#define M_PI
Definition: mathematics.h:52
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:251
AV_CH_LAYOUT_3POINT1
#define AV_CH_LAYOUT_3POINT1
Definition: channel_layout.h:209
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_surround.c:262
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
AudioSurroundContext::bc_y
float bc_y
Definition: af_surround.c:83
AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_5POINT0
Definition: channel_layout.h:214
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
AudioSurroundContext::br_out
float br_out
Definition: af_surround.c:53
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:405
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(surround)
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
upmix_5_1_back_2_1
static void upmix_5_1_back_2_1(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float lfe_re, float lfe_im, float x, float y, int n)
Definition: af_surround.c:833
AV_CH_LAYOUT_2POINT1
#define AV_CH_LAYOUT_2POINT1
Definition: channel_layout.h:206
AudioSurroundContext::fl_y
float fl_y
Definition: af_surround.c:77
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:386
upmix_7_0
static void upmix_7_0(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:879
AV_CHAN_FRONT_CENTER
@ AV_CHAN_FRONT_CENTER
Definition: channel_layout.h:46
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
filter_5_1_side
static void filter_5_1_side(AVFilterContext *ctx)
Definition: af_surround.c:1262
AV_CH_LAYOUT_7POINT1
#define AV_CH_LAYOUT_7POINT1
Definition: channel_layout.h:226
AV_CH_LAYOUT_4POINT1
#define AV_CH_LAYOUT_4POINT1
Definition: channel_layout.h:211
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
upmix_3_0
static void upmix_3_0(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:436
filter_surround
static void filter_surround(AVFilterContext *ctx)
Definition: af_surround.c:1134
ff_inlink_queued_samples
int ff_inlink_queued_samples(AVFilterLink *link)
Definition: avfilter.c:1373
av_channel_layout_index_from_channel
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
Definition: channel_layout.c:834
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
AudioSurroundContext::win_size
int win_size
Definition: af_surround.c:60
upmix_stereo
static void upmix_stereo(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:382
AVFilter
Filter definition.
Definition: avfilter.h:171
AudioSurroundContext::output
AVFrame * output
Definition: af_surround.c:101
ret
ret
Definition: filter_design.txt:187
AudioSurroundContext::angle
float angle
Definition: af_surround.c:59
AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_SURROUND
Definition: channel_layout.h:208
AudioSurroundContext::fl_in
float fl_in
Definition: af_surround.c:42
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_surround.c:193
AudioSurroundContext::win_func
int win_func
Definition: af_surround.c:61
AV_TX_FLOAT_RDFT
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
Definition: tx.h:88
window_func.h
AudioSurroundContext::window_func_lut
float * window_func_lut
Definition: af_surround.c:110
AudioSurroundContext::upmix_stereo
void(* upmix_stereo)(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:113
AudioSurroundContext::tx_fn
av_tx_fn tx_fn
Definition: af_surround.c:109
channel_layout.h
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:402
upmix_7_1_5_0_side
static void upmix_7_1_5_0_side(AVFilterContext *ctx, float c_re, float c_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
Definition: af_surround.c:985
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AudioSurroundContext::bc_x
float bc_x
Definition: af_surround.c:74
get_lfe
static void get_lfe(int output_lfe, int n, float lowcut, float highcut, float *lfe_mag, float *mag_total, int lfe_mode)
Definition: af_surround.c:350
upmix_3_1
static void upmix_3_1(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:465
AudioSurroundContext::window
AVFrame * window
Definition: af_surround.c:104
AVFilterContext
An instance of a filter.
Definition: avfilter.h:408
upmix_1_0
static void upmix_1_0(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:363
AudioSurroundContext::sr_in
float sr_in
Definition: af_surround.c:48
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:127
upmix_5_1_back_surround
static void upmix_5_1_back_surround(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float c_mag, float mag_total, float x, float y, int n)
Definition: af_surround.c:787
audio.h
M_LN10
#define M_LN10
Definition: mathematics.h:43
AudioSurroundContext::highcut
float highcut
Definition: af_surround.c:92
AudioSurroundContext::lfe_in
float lfe_in
Definition: af_surround.c:56
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AudioSurroundContext::bc_out
float bc_out
Definition: af_surround.c:55
AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_4POINT0
Definition: channel_layout.h:210
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_surround.c:1380
AudioSurroundContext::itx_fn
av_tx_fn itx_fn
Definition: af_surround.c:109
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AudioSurroundContext::rdft
AVTXContext ** rdft
Definition: af_surround.c:108
AudioSurroundContext::fr_out
float fr_out
Definition: af_surround.c:45
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:142
upmix_6_1
static void upmix_6_1(AVFilterContext *ctx, float l_phase, float r_phase, float c_phase, float mag_total, float x, float y, int n)
Definition: af_surround.c:737
AudioSurroundContext::bl_y
float bl_y
Definition: af_surround.c:79
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AudioSurroundContext::bl_x
float bl_x
Definition: af_surround.c:70
stereo_position
static void stereo_position(float a, float p, float *x, float *y)
Definition: af_surround.c:342
filter_2_1
static void filter_2_1(AVFilterContext *ctx)
Definition: af_surround.c:1170
AudioSurroundContext::all_x
float all_x
Definition: af_surround.c:64
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:191
tx.h
inputs
static const AVFilterPad inputs[]
Definition: af_surround.c:1732