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"
22 #include "libavutil/audio_fifo.h"
24 #include "libavutil/opt.h"
25 #include "libavcodec/avfft.h"
26 #include "avfilter.h"
27 #include "audio.h"
28 #include "filters.h"
29 #include "internal.h"
30 #include "formats.h"
31 #include "window_func.h"
32 
33 typedef struct AudioSurroundContext {
34  const AVClass *class;
35 
38 
39  float level_in;
40  float level_out;
41  float fc_in;
42  float fc_out;
43  float fl_in;
44  float fl_out;
45  float fr_in;
46  float fr_out;
47  float sl_in;
48  float sl_out;
49  float sr_in;
50  float sr_out;
51  float bl_in;
52  float bl_out;
53  float br_in;
54  float br_out;
55  float bc_in;
56  float bc_out;
57  float lfe_in;
58  float lfe_out;
59  int lfe_mode;
60  float angle;
61  int win_size;
62  int win_func;
63  float overlap;
64 
65  float all_x;
66  float all_y;
67 
68  float fc_x;
69  float fl_x;
70  float fr_x;
71  float bl_x;
72  float br_x;
73  float sl_x;
74  float sr_x;
75  float bc_x;
76 
77  float fc_y;
78  float fl_y;
79  float fr_y;
80  float bl_y;
81  float br_y;
82  float sl_y;
83  float sr_y;
84  float bc_y;
85 
86  float *input_levels;
87  float *output_levels;
89  int lowcutf;
90  int highcutf;
91 
92  float lowcut;
93  float highcut;
94 
99 
103 
104  int buf_size;
105  int hop_size;
109 
110  int64_t pts;
111  int eof;
112 
115  float l_phase,
116  float r_phase,
117  float c_phase,
118  float mag_total,
119  float x, float y,
120  int n);
122  float l_phase,
123  float r_phase,
124  float c_phase,
125  float mag_total,
126  float lfe_im,
127  float lfe_re,
128  float x, float y,
129  int n);
131  float l_phase,
132  float r_phase,
133  float c_mag,
134  float c_phase,
135  float mag_total,
136  float x, float y,
137  int n);
139  float c_re, float c_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);
148  float c_re, float c_im,
149  float lfe_re, float lfe_im,
150  float mag_totall, float mag_totalr,
151  float fl_phase, float fr_phase,
152  float bl_phase, float br_phase,
153  float sl_phase, float sr_phase,
154  float xl, float yl,
155  float xr, float yr,
156  int n);
158 
160 {
161  AudioSurroundContext *s = ctx->priv;
164  int ret;
165 
167  if (ret)
168  return ret;
170  if (ret)
171  return ret;
172 
173  layouts = NULL;
174  ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
175  if (ret)
176  return ret;
177 
178  ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
179  if (ret)
180  return ret;
181 
182  layouts = NULL;
183  ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
184  if (ret)
185  return ret;
186 
187  ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
188  if (ret)
189  return ret;
190 
192  if (!formats)
193  return AVERROR(ENOMEM);
195 }
196 
198 {
199  AVFilterContext *ctx = inlink->dst;
200  AudioSurroundContext *s = ctx->priv;
201  int ch;
202 
203  s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
204  if (!s->rdft)
205  return AVERROR(ENOMEM);
206 
207  for (ch = 0; ch < inlink->channels; ch++) {
208  s->rdft[ch] = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
209  if (!s->rdft[ch])
210  return AVERROR(ENOMEM);
211  }
212  s->nb_in_channels = inlink->channels;
213  s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
214  if (!s->input_levels)
215  return AVERROR(ENOMEM);
216  for (ch = 0; ch < s->nb_in_channels; ch++)
217  s->input_levels[ch] = s->level_in;
219  if (ch >= 0)
220  s->input_levels[ch] *= s->fc_in;
222  if (ch >= 0)
223  s->input_levels[ch] *= s->fl_in;
225  if (ch >= 0)
226  s->input_levels[ch] *= s->fr_in;
228  if (ch >= 0)
229  s->input_levels[ch] *= s->sl_in;
231  if (ch >= 0)
232  s->input_levels[ch] *= s->sr_in;
234  if (ch >= 0)
235  s->input_levels[ch] *= s->bl_in;
237  if (ch >= 0)
238  s->input_levels[ch] *= s->br_in;
240  if (ch >= 0)
241  s->input_levels[ch] *= s->bc_in;
243  if (ch >= 0)
244  s->input_levels[ch] *= s->lfe_in;
245 
246  s->input = ff_get_audio_buffer(inlink, s->buf_size * 2);
247  if (!s->input)
248  return AVERROR(ENOMEM);
249 
250  s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->buf_size);
251  if (!s->fifo)
252  return AVERROR(ENOMEM);
253 
254  s->lowcut = 1.f * s->lowcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
255  s->highcut = 1.f * s->highcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
256 
257  return 0;
258 }
259 
260 static int config_output(AVFilterLink *outlink)
261 {
262  AVFilterContext *ctx = outlink->src;
263  AudioSurroundContext *s = ctx->priv;
264  int ch;
265 
266  s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft));
267  if (!s->irdft)
268  return AVERROR(ENOMEM);
269 
270  for (ch = 0; ch < outlink->channels; ch++) {
271  s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
272  if (!s->irdft[ch])
273  return AVERROR(ENOMEM);
274  }
275  s->nb_out_channels = outlink->channels;
276  s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
277  if (!s->output_levels)
278  return AVERROR(ENOMEM);
279  for (ch = 0; ch < s->nb_out_channels; ch++)
280  s->output_levels[ch] = s->level_out;
282  if (ch >= 0)
283  s->output_levels[ch] *= s->fc_out;
285  if (ch >= 0)
286  s->output_levels[ch] *= s->fl_out;
288  if (ch >= 0)
289  s->output_levels[ch] *= s->fr_out;
291  if (ch >= 0)
292  s->output_levels[ch] *= s->sl_out;
294  if (ch >= 0)
295  s->output_levels[ch] *= s->sr_out;
297  if (ch >= 0)
298  s->output_levels[ch] *= s->bl_out;
300  if (ch >= 0)
301  s->output_levels[ch] *= s->br_out;
303  if (ch >= 0)
304  s->output_levels[ch] *= s->bc_out;
306  if (ch >= 0)
307  s->output_levels[ch] *= s->lfe_out;
308 
309  s->output = ff_get_audio_buffer(outlink, s->buf_size * 2);
310  s->overlap_buffer = ff_get_audio_buffer(outlink, s->buf_size * 2);
311  if (!s->overlap_buffer || !s->output)
312  return AVERROR(ENOMEM);
313 
314  return 0;
315 }
316 
317 static void stereo_transform(float *x, float *y, float angle)
318 {
319  float reference, r, a;
320 
321  if (angle == 90.f)
322  return;
323 
324  reference = angle * M_PI / 180.f;
325  r = hypotf(*x, *y);
326  a = atan2f(*x, *y);
327 
328  if (fabsf(a) <= M_PI_4)
329  a *= reference / M_PI_2;
330  else
331  a = M_PI + 2 * (-2 * M_PI + reference) * (M_PI - fabsf(a)) * FFDIFFSIGN(a, 0) / (3 * M_PI);
332 
333  *x = av_clipf(sinf(a) * r, -1, 1);
334  *y = av_clipf(cosf(a) * r, -1, 1);
335 }
336 
337 static void stereo_position(float a, float p, float *x, float *y)
338 {
339  av_assert2(a >= -1.f && a <= 1.f);
340  av_assert2(p >= 0.f && p <= M_PI);
341  *x = av_clipf(a+a*FFMAX(0, p*p-M_PI_2), -1, 1);
342  *y = av_clipf(cosf(a*M_PI_2+M_PI)*cosf(M_PI_2-p/M_PI)*M_LN10+1, -1, 1);
343 }
344 
345 static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut,
346  float *lfe_mag, float *mag_total, int lfe_mode)
347 {
348  if (output_lfe && n < highcut) {
349  *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PI*(lowcut-n)/(lowcut-highcut)));
350  *lfe_mag *= *mag_total;
351  if (lfe_mode)
352  *mag_total -= *lfe_mag;
353  } else {
354  *lfe_mag = 0.f;
355  }
356 }
357 
359  float l_phase,
360  float r_phase,
361  float c_phase,
362  float mag_total,
363  float x, float y,
364  int n)
365 {
366  AudioSurroundContext *s = ctx->priv;
367  float mag, *dst;
368 
369  dst = (float *)s->output->extended_data[0];
370 
371  mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
372 
373  dst[2 * n ] = mag * cosf(c_phase);
374  dst[2 * n + 1] = mag * sinf(c_phase);
375 }
376 
378  float l_phase,
379  float r_phase,
380  float c_phase,
381  float mag_total,
382  float x, float y,
383  int n)
384 {
385  AudioSurroundContext *s = ctx->priv;
386  float l_mag, r_mag, *dstl, *dstr;
387 
388  dstl = (float *)s->output->extended_data[0];
389  dstr = (float *)s->output->extended_data[1];
390 
391  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
392  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
393 
394  dstl[2 * n ] = l_mag * cosf(l_phase);
395  dstl[2 * n + 1] = l_mag * sinf(l_phase);
396 
397  dstr[2 * n ] = r_mag * cosf(r_phase);
398  dstr[2 * n + 1] = r_mag * sinf(r_phase);
399 }
400 
402  float l_phase,
403  float r_phase,
404  float c_phase,
405  float mag_total,
406  float x, float y,
407  int n)
408 {
409  AudioSurroundContext *s = ctx->priv;
410  float lfe_mag, l_mag, r_mag, *dstl, *dstr, *dstlfe;
411 
412  dstl = (float *)s->output->extended_data[0];
413  dstr = (float *)s->output->extended_data[1];
414  dstlfe = (float *)s->output->extended_data[2];
415 
416  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
417 
418  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
419  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
420 
421  dstl[2 * n ] = l_mag * cosf(l_phase);
422  dstl[2 * n + 1] = l_mag * sinf(l_phase);
423 
424  dstr[2 * n ] = r_mag * cosf(r_phase);
425  dstr[2 * n + 1] = r_mag * sinf(r_phase);
426 
427  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
428  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
429 }
430 
432  float l_phase,
433  float r_phase,
434  float c_phase,
435  float mag_total,
436  float x, float y,
437  int n)
438 {
439  AudioSurroundContext *s = ctx->priv;
440  float l_mag, r_mag, c_mag, *dstc, *dstl, *dstr;
441 
442  dstl = (float *)s->output->extended_data[0];
443  dstr = (float *)s->output->extended_data[1];
444  dstc = (float *)s->output->extended_data[2];
445 
446  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
447  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
448  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
449 
450  dstl[2 * n ] = l_mag * cosf(l_phase);
451  dstl[2 * n + 1] = l_mag * sinf(l_phase);
452 
453  dstr[2 * n ] = r_mag * cosf(r_phase);
454  dstr[2 * n + 1] = r_mag * sinf(r_phase);
455 
456  dstc[2 * n ] = c_mag * cosf(c_phase);
457  dstc[2 * n + 1] = c_mag * sinf(c_phase);
458 }
459 
461  float l_phase,
462  float r_phase,
463  float c_phase,
464  float mag_total,
465  float x, float y,
466  int n)
467 {
468  AudioSurroundContext *s = ctx->priv;
469  float lfe_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstlfe;
470 
471  dstl = (float *)s->output->extended_data[0];
472  dstr = (float *)s->output->extended_data[1];
473  dstc = (float *)s->output->extended_data[2];
474  dstlfe = (float *)s->output->extended_data[3];
475 
476  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
477 
478  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
479  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
480  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
481 
482  dstl[2 * n ] = l_mag * cosf(l_phase);
483  dstl[2 * n + 1] = l_mag * sinf(l_phase);
484 
485  dstr[2 * n ] = r_mag * cosf(r_phase);
486  dstr[2 * n + 1] = r_mag * sinf(r_phase);
487 
488  dstc[2 * n ] = c_mag * cosf(c_phase);
489  dstc[2 * n + 1] = c_mag * sinf(c_phase);
490 
491  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
492  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
493 }
494 
496  float l_phase,
497  float r_phase,
498  float c_phase,
499  float c_mag,
500  float mag_total,
501  float x, float y,
502  int n)
503 {
504  AudioSurroundContext *s = ctx->priv;
505  float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
506 
507  dstl = (float *)s->output->extended_data[0];
508  dstr = (float *)s->output->extended_data[1];
509  dstc = (float *)s->output->extended_data[2];
510  dstlfe = (float *)s->output->extended_data[3];
511 
512  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
513 
514  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
515  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
516 
517  dstl[2 * n ] = l_mag * cosf(l_phase);
518  dstl[2 * n + 1] = l_mag * sinf(l_phase);
519 
520  dstr[2 * n ] = r_mag * cosf(r_phase);
521  dstr[2 * n + 1] = r_mag * sinf(r_phase);
522 
523  dstc[2 * n ] = c_mag * cosf(c_phase);
524  dstc[2 * n + 1] = c_mag * sinf(c_phase);
525 
526  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
527  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
528 }
529 
531  float l_phase,
532  float r_phase,
533  float c_phase,
534  float mag_total,
535  float x, float y,
536  int n)
537 {
538  AudioSurroundContext *s = ctx->priv;
539  float b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb;
540 
541  dstl = (float *)s->output->extended_data[0];
542  dstr = (float *)s->output->extended_data[1];
543  dstc = (float *)s->output->extended_data[2];
544  dstb = (float *)s->output->extended_data[3];
545 
546  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
547  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
548  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
549  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
550 
551  dstl[2 * n ] = l_mag * cosf(l_phase);
552  dstl[2 * n + 1] = l_mag * sinf(l_phase);
553 
554  dstr[2 * n ] = r_mag * cosf(r_phase);
555  dstr[2 * n + 1] = r_mag * sinf(r_phase);
556 
557  dstc[2 * n ] = c_mag * cosf(c_phase);
558  dstc[2 * n + 1] = c_mag * sinf(c_phase);
559 
560  dstb[2 * n ] = b_mag * cosf(c_phase);
561  dstb[2 * n + 1] = b_mag * sinf(c_phase);
562 }
563 
565  float l_phase,
566  float r_phase,
567  float c_phase,
568  float mag_total,
569  float x, float y,
570  int n)
571 {
572  AudioSurroundContext *s = ctx->priv;
573  float lfe_mag, b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb, *dstlfe;
574 
575  dstl = (float *)s->output->extended_data[0];
576  dstr = (float *)s->output->extended_data[1];
577  dstc = (float *)s->output->extended_data[2];
578  dstlfe = (float *)s->output->extended_data[3];
579  dstb = (float *)s->output->extended_data[4];
580 
581  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
582 
583  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
584  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
585 
586  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
587  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
588  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
589  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
590 
591  dstl[2 * n ] = l_mag * cosf(l_phase);
592  dstl[2 * n + 1] = l_mag * sinf(l_phase);
593 
594  dstr[2 * n ] = r_mag * cosf(r_phase);
595  dstr[2 * n + 1] = r_mag * sinf(r_phase);
596 
597  dstc[2 * n ] = c_mag * cosf(c_phase);
598  dstc[2 * n + 1] = c_mag * sinf(c_phase);
599 
600  dstb[2 * n ] = b_mag * cosf(c_phase);
601  dstb[2 * n + 1] = b_mag * sinf(c_phase);
602 }
603 
605  float l_phase,
606  float r_phase,
607  float c_phase,
608  float mag_total,
609  float x, float y,
610  int n)
611 {
612  AudioSurroundContext *s = ctx->priv;
613  float l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs;
614 
615  dstl = (float *)s->output->extended_data[0];
616  dstr = (float *)s->output->extended_data[1];
617  dstc = (float *)s->output->extended_data[2];
618  dstls = (float *)s->output->extended_data[3];
619  dstrs = (float *)s->output->extended_data[4];
620 
621  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
622  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
623  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
624  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
625  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
626 
627  dstl[2 * n ] = l_mag * cosf(l_phase);
628  dstl[2 * n + 1] = l_mag * sinf(l_phase);
629 
630  dstr[2 * n ] = r_mag * cosf(r_phase);
631  dstr[2 * n + 1] = r_mag * sinf(r_phase);
632 
633  dstc[2 * n ] = c_mag * cosf(c_phase);
634  dstc[2 * n + 1] = c_mag * sinf(c_phase);
635 
636  dstls[2 * n ] = ls_mag * cosf(l_phase);
637  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
638 
639  dstrs[2 * n ] = rs_mag * cosf(r_phase);
640  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
641 }
642 
644  float l_phase,
645  float r_phase,
646  float c_phase,
647  float mag_total,
648  float x, float y,
649  int n)
650 {
651  AudioSurroundContext *s = ctx->priv;
652  float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
653 
654  dstl = (float *)s->output->extended_data[0];
655  dstr = (float *)s->output->extended_data[1];
656  dstc = (float *)s->output->extended_data[2];
657  dstlfe = (float *)s->output->extended_data[3];
658  dstls = (float *)s->output->extended_data[4];
659  dstrs = (float *)s->output->extended_data[5];
660 
661  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
662 
663  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
664  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
665  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
666  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
667  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
668 
669  dstl[2 * n ] = l_mag * cosf(l_phase);
670  dstl[2 * n + 1] = l_mag * sinf(l_phase);
671 
672  dstr[2 * n ] = r_mag * cosf(r_phase);
673  dstr[2 * n + 1] = r_mag * sinf(r_phase);
674 
675  dstc[2 * n ] = c_mag * cosf(c_phase);
676  dstc[2 * n + 1] = c_mag * sinf(c_phase);
677 
678  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
679  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
680 
681  dstls[2 * n ] = ls_mag * cosf(l_phase);
682  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
683 
684  dstrs[2 * n ] = rs_mag * cosf(r_phase);
685  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
686 }
687 
689  float l_phase,
690  float r_phase,
691  float c_phase,
692  float mag_total,
693  float x, float y,
694  int n)
695 {
696  AudioSurroundContext *s = ctx->priv;
697  float l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs;
698 
699  dstl = (float *)s->output->extended_data[0];
700  dstr = (float *)s->output->extended_data[1];
701  dstc = (float *)s->output->extended_data[2];
702  dstb = (float *)s->output->extended_data[3];
703  dstls = (float *)s->output->extended_data[4];
704  dstrs = (float *)s->output->extended_data[5];
705 
706  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
707  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
708  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
709  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
710  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
711  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
712 
713  dstl[2 * n ] = l_mag * cosf(l_phase);
714  dstl[2 * n + 1] = l_mag * sinf(l_phase);
715 
716  dstr[2 * n ] = r_mag * cosf(r_phase);
717  dstr[2 * n + 1] = r_mag * sinf(r_phase);
718 
719  dstc[2 * n ] = c_mag * cosf(c_phase);
720  dstc[2 * n + 1] = c_mag * sinf(c_phase);
721 
722  dstls[2 * n ] = ls_mag * cosf(l_phase);
723  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
724 
725  dstrs[2 * n ] = rs_mag * cosf(r_phase);
726  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
727 
728  dstb[2 * n ] = b_mag * cosf(c_phase);
729  dstb[2 * n + 1] = b_mag * sinf(c_phase);
730 }
731 
733  float l_phase,
734  float r_phase,
735  float c_phase,
736  float mag_total,
737  float x, float y,
738  int n)
739 {
740  AudioSurroundContext *s = ctx->priv;
741  float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
742 
743  dstl = (float *)s->output->extended_data[0];
744  dstr = (float *)s->output->extended_data[1];
745  dstc = (float *)s->output->extended_data[2];
746  dstlfe = (float *)s->output->extended_data[3];
747  dstb = (float *)s->output->extended_data[4];
748  dstls = (float *)s->output->extended_data[5];
749  dstrs = (float *)s->output->extended_data[6];
750 
751  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
752 
753  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
754  b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;
755  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
756  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
757  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
758  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
759 
760  dstl[2 * n ] = l_mag * cosf(l_phase);
761  dstl[2 * n + 1] = l_mag * sinf(l_phase);
762 
763  dstr[2 * n ] = r_mag * cosf(r_phase);
764  dstr[2 * n + 1] = r_mag * sinf(r_phase);
765 
766  dstc[2 * n ] = c_mag * cosf(c_phase);
767  dstc[2 * n + 1] = c_mag * sinf(c_phase);
768 
769  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
770  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
771 
772  dstls[2 * n ] = ls_mag * cosf(l_phase);
773  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
774 
775  dstrs[2 * n ] = rs_mag * cosf(r_phase);
776  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
777 
778  dstb[2 * n ] = b_mag * cosf(c_phase);
779  dstb[2 * n + 1] = b_mag * sinf(c_phase);
780 }
781 
783  float l_phase,
784  float r_phase,
785  float c_phase,
786  float c_mag,
787  float mag_total,
788  float x, float y,
789  int n)
790 {
791  AudioSurroundContext *s = ctx->priv;
792  float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
793  float ls_mag, rs_mag, *dstls, *dstrs;
794 
795  dstl = (float *)s->output->extended_data[0];
796  dstr = (float *)s->output->extended_data[1];
797  dstc = (float *)s->output->extended_data[2];
798  dstlfe = (float *)s->output->extended_data[3];
799  dstls = (float *)s->output->extended_data[4];
800  dstrs = (float *)s->output->extended_data[5];
801 
802  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
803 
804  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
805  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
806  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
807  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
808 
809  dstl[2 * n ] = l_mag * cosf(l_phase);
810  dstl[2 * n + 1] = l_mag * sinf(l_phase);
811 
812  dstr[2 * n ] = r_mag * cosf(r_phase);
813  dstr[2 * n + 1] = r_mag * sinf(r_phase);
814 
815  dstc[2 * n ] = c_mag * cosf(c_phase);
816  dstc[2 * n + 1] = c_mag * sinf(c_phase);
817 
818  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
819  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
820 
821  dstls[2 * n ] = ls_mag * cosf(l_phase);
822  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
823 
824  dstrs[2 * n ] = rs_mag * cosf(r_phase);
825  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
826 }
827 
829  float l_phase,
830  float r_phase,
831  float c_phase,
832  float mag_total,
833  float lfe_re,
834  float lfe_im,
835  float x, float y,
836  int n)
837 {
838  AudioSurroundContext *s = ctx->priv;
839  float c_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
840  float ls_mag, rs_mag, *dstls, *dstrs;
841 
842  dstl = (float *)s->output->extended_data[0];
843  dstr = (float *)s->output->extended_data[1];
844  dstc = (float *)s->output->extended_data[2];
845  dstlfe = (float *)s->output->extended_data[3];
846  dstls = (float *)s->output->extended_data[4];
847  dstrs = (float *)s->output->extended_data[5];
848 
849  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
850  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
851  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
852  ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
853  rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
854 
855  dstl[2 * n ] = l_mag * cosf(l_phase);
856  dstl[2 * n + 1] = l_mag * sinf(l_phase);
857 
858  dstr[2 * n ] = r_mag * cosf(r_phase);
859  dstr[2 * n + 1] = r_mag * sinf(r_phase);
860 
861  dstc[2 * n ] = c_mag * cosf(c_phase);
862  dstc[2 * n + 1] = c_mag * sinf(c_phase);
863 
864  dstlfe[2 * n ] = lfe_re;
865  dstlfe[2 * n + 1] = lfe_im;
866 
867  dstls[2 * n ] = ls_mag * cosf(l_phase);
868  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
869 
870  dstrs[2 * n ] = rs_mag * cosf(r_phase);
871  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
872 }
873 
875  float l_phase,
876  float r_phase,
877  float c_phase,
878  float mag_total,
879  float x, float y,
880  int n)
881 {
882  float l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
883  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb;
884  AudioSurroundContext *s = ctx->priv;
885 
886  dstl = (float *)s->output->extended_data[0];
887  dstr = (float *)s->output->extended_data[1];
888  dstc = (float *)s->output->extended_data[2];
889  dstlb = (float *)s->output->extended_data[3];
890  dstrb = (float *)s->output->extended_data[4];
891  dstls = (float *)s->output->extended_data[5];
892  dstrs = (float *)s->output->extended_data[6];
893 
894  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
895  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
896  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
897  lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
898  rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
899  ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
900  rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
901 
902  dstl[2 * n ] = l_mag * cosf(l_phase);
903  dstl[2 * n + 1] = l_mag * sinf(l_phase);
904 
905  dstr[2 * n ] = r_mag * cosf(r_phase);
906  dstr[2 * n + 1] = r_mag * sinf(r_phase);
907 
908  dstc[2 * n ] = c_mag * cosf(c_phase);
909  dstc[2 * n + 1] = c_mag * sinf(c_phase);
910 
911  dstlb[2 * n ] = lb_mag * cosf(l_phase);
912  dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
913 
914  dstrb[2 * n ] = rb_mag * cosf(r_phase);
915  dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
916 
917  dstls[2 * n ] = ls_mag * cosf(l_phase);
918  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
919 
920  dstrs[2 * n ] = rs_mag * cosf(r_phase);
921  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
922 }
923 
925  float l_phase,
926  float r_phase,
927  float c_phase,
928  float mag_total,
929  float x, float y,
930  int n)
931 {
932  float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
933  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
934  AudioSurroundContext *s = ctx->priv;
935 
936  dstl = (float *)s->output->extended_data[0];
937  dstr = (float *)s->output->extended_data[1];
938  dstc = (float *)s->output->extended_data[2];
939  dstlfe = (float *)s->output->extended_data[3];
940  dstlb = (float *)s->output->extended_data[4];
941  dstrb = (float *)s->output->extended_data[5];
942  dstls = (float *)s->output->extended_data[6];
943  dstrs = (float *)s->output->extended_data[7];
944 
945  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
946 
947  c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
948  l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
949  r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
950  lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
951  rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
952  ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
953  rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
954 
955  dstl[2 * n ] = l_mag * cosf(l_phase);
956  dstl[2 * n + 1] = l_mag * sinf(l_phase);
957 
958  dstr[2 * n ] = r_mag * cosf(r_phase);
959  dstr[2 * n + 1] = r_mag * sinf(r_phase);
960 
961  dstc[2 * n ] = c_mag * cosf(c_phase);
962  dstc[2 * n + 1] = c_mag * sinf(c_phase);
963 
964  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
965  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
966 
967  dstlb[2 * n ] = lb_mag * cosf(l_phase);
968  dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
969 
970  dstrb[2 * n ] = rb_mag * cosf(r_phase);
971  dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
972 
973  dstls[2 * n ] = ls_mag * cosf(l_phase);
974  dstls[2 * n + 1] = ls_mag * sinf(l_phase);
975 
976  dstrs[2 * n ] = rs_mag * cosf(r_phase);
977  dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
978 }
979 
981  float c_re, float c_im,
982  float mag_totall, float mag_totalr,
983  float fl_phase, float fr_phase,
984  float bl_phase, float br_phase,
985  float sl_phase, float sr_phase,
986  float xl, float yl,
987  float xr, float yr,
988  int n)
989 {
990  float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
991  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
992  float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5;
993  AudioSurroundContext *s = ctx->priv;
994 
995  dstl = (float *)s->output->extended_data[0];
996  dstr = (float *)s->output->extended_data[1];
997  dstc = (float *)s->output->extended_data[2];
998  dstlfe = (float *)s->output->extended_data[3];
999  dstlb = (float *)s->output->extended_data[4];
1000  dstrb = (float *)s->output->extended_data[5];
1001  dstls = (float *)s->output->extended_data[6];
1002  dstrs = (float *)s->output->extended_data[7];
1003 
1004  c_phase = atan2f(c_im, c_re);
1005 
1006  get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
1007 
1008  fl_mag = powf(.5f * (xl + 1.f), s->fl_x) * powf((yl + 1.f) * .5f, s->fl_y) * mag_totall;
1009  fr_mag = powf(.5f * (xr + 1.f), s->fr_x) * powf((yr + 1.f) * .5f, s->fr_y) * mag_totalr;
1010  lb_mag = powf(.5f * (-xl + 1.f), s->bl_x) * powf((yl + 1.f) * .5f, s->bl_y) * mag_totall;
1011  rb_mag = powf(.5f * (-xr + 1.f), s->br_x) * powf((yr + 1.f) * .5f, s->br_y) * mag_totalr;
1012  ls_mag = powf(1.f - fabsf(xl), s->sl_x) * powf((yl + 1.f) * .5f, s->sl_y) * mag_totall;
1013  rs_mag = powf(1.f - fabsf(xr), s->sr_x) * powf((yr + 1.f) * .5f, s->sr_y) * mag_totalr;
1014 
1015  dstl[2 * n ] = fl_mag * cosf(fl_phase);
1016  dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
1017 
1018  dstr[2 * n ] = fr_mag * cosf(fr_phase);
1019  dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
1020 
1021  dstc[2 * n ] = c_re;
1022  dstc[2 * n + 1] = c_im;
1023 
1024  dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
1025  dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
1026 
1027  dstlb[2 * n ] = lb_mag * cosf(bl_phase);
1028  dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
1029 
1030  dstrb[2 * n ] = rb_mag * cosf(br_phase);
1031  dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
1032 
1033  dstls[2 * n ] = ls_mag * cosf(sl_phase);
1034  dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
1035 
1036  dstrs[2 * n ] = rs_mag * cosf(sr_phase);
1037  dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1038 }
1039 
1041  float c_re, float c_im,
1042  float lfe_re, float lfe_im,
1043  float mag_totall, float mag_totalr,
1044  float fl_phase, float fr_phase,
1045  float bl_phase, float br_phase,
1046  float sl_phase, float sr_phase,
1047  float xl, float yl,
1048  float xr, float yr,
1049  int n)
1050 {
1051  float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
1052  float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
1053  AudioSurroundContext *s = ctx->priv;
1054 
1055  dstl = (float *)s->output->extended_data[0];
1056  dstr = (float *)s->output->extended_data[1];
1057  dstc = (float *)s->output->extended_data[2];
1058  dstlfe = (float *)s->output->extended_data[3];
1059  dstlb = (float *)s->output->extended_data[4];
1060  dstrb = (float *)s->output->extended_data[5];
1061  dstls = (float *)s->output->extended_data[6];
1062  dstrs = (float *)s->output->extended_data[7];
1063 
1064  fl_mag = powf(.5f * (xl + 1.f), s->fl_x) * powf((yl + 1.f) * .5f, s->fl_y) * mag_totall;
1065  fr_mag = powf(.5f * (xr + 1.f), s->fr_x) * powf((yr + 1.f) * .5f, s->fr_y) * mag_totalr;
1066  lb_mag = powf(.5f * (-xl + 1.f), s->bl_x) * powf((yl + 1.f) * .5f, s->bl_y) * mag_totall;
1067  rb_mag = powf(.5f * (-xr + 1.f), s->br_x) * powf((yr + 1.f) * .5f, s->br_y) * mag_totalr;
1068  ls_mag = powf(1.f - fabsf(xl), s->sl_x) * powf((yl + 1.f) * .5f, s->sl_y) * mag_totall;
1069  rs_mag = powf(1.f - fabsf(xr), s->sr_x) * powf((yr + 1.f) * .5f, s->sr_y) * mag_totalr;
1070 
1071  dstl[2 * n ] = fl_mag * cosf(fl_phase);
1072  dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
1073 
1074  dstr[2 * n ] = fr_mag * cosf(fr_phase);
1075  dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
1076 
1077  dstc[2 * n ] = c_re;
1078  dstc[2 * n + 1] = c_im;
1079 
1080  dstlfe[2 * n ] = lfe_re;
1081  dstlfe[2 * n + 1] = lfe_im;
1082 
1083  dstlb[2 * n ] = lb_mag * cosf(bl_phase);
1084  dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
1085 
1086  dstrb[2 * n ] = rb_mag * cosf(br_phase);
1087  dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
1088 
1089  dstls[2 * n ] = ls_mag * cosf(sl_phase);
1090  dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
1091 
1092  dstrs[2 * n ] = rs_mag * cosf(sr_phase);
1093  dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1094 }
1095 
1097 {
1098  AudioSurroundContext *s = ctx->priv;
1099  float *srcl, *srcr;
1100  int n;
1101 
1102  srcl = (float *)s->input->extended_data[0];
1103  srcr = (float *)s->input->extended_data[1];
1104 
1105  for (n = 0; n < s->buf_size; n++) {
1106  float l_re = srcl[2 * n], r_re = srcr[2 * n];
1107  float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1108  float c_phase = atan2f(l_im + r_im, l_re + r_re);
1109  float l_mag = hypotf(l_re, l_im);
1110  float r_mag = hypotf(r_re, r_im);
1111  float l_phase = atan2f(l_im, l_re);
1112  float r_phase = atan2f(r_im, r_re);
1113  float phase_dif = fabsf(l_phase - r_phase);
1114  float mag_sum = l_mag + r_mag;
1115  float mag_dif = mag_sum < 0.000001 ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;
1116  float mag_total = hypotf(l_mag, r_mag);
1117  float x, y;
1118 
1119  if (phase_dif > M_PI)
1120  phase_dif = 2 * M_PI - phase_dif;
1121 
1122  stereo_position(mag_dif, phase_dif, &x, &y);
1123  stereo_transform(&x, &y, s->angle);
1124 
1125  s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);
1126  }
1127 }
1128 
1130 {
1131  AudioSurroundContext *s = ctx->priv;
1132  float *srcl, *srcr, *srcc;
1133  int n;
1134 
1135  srcl = (float *)s->input->extended_data[0];
1136  srcr = (float *)s->input->extended_data[1];
1137  srcc = (float *)s->input->extended_data[2];
1138 
1139  for (n = 0; n < s->buf_size; n++) {
1140  float l_re = srcl[2 * n], r_re = srcr[2 * n];
1141  float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1142  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1143  float c_mag = hypotf(c_re, c_im);
1144  float c_phase = atan2f(c_im, c_re);
1145  float l_mag = hypotf(l_re, l_im);
1146  float r_mag = hypotf(r_re, r_im);
1147  float l_phase = atan2f(l_im, l_re);
1148  float r_phase = atan2f(r_im, r_re);
1149  float phase_dif = fabsf(l_phase - r_phase);
1150  float mag_sum = l_mag + r_mag;
1151  float mag_dif = mag_sum < 0.000001 ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;
1152  float mag_total = hypotf(l_mag, r_mag);
1153  float x, y;
1154 
1155  if (phase_dif > M_PI)
1156  phase_dif = 2 * M_PI - phase_dif;
1157 
1158  stereo_position(mag_dif, phase_dif, &x, &y);
1159  stereo_transform(&x, &y, s->angle);
1160 
1161  s->upmix_3_0(ctx, l_phase, r_phase, c_phase, c_mag, mag_total, x, y, n);
1162  }
1163 }
1164 
1166 {
1167  AudioSurroundContext *s = ctx->priv;
1168  float *srcl, *srcr, *srclfe;
1169  int n;
1170 
1171  srcl = (float *)s->input->extended_data[0];
1172  srcr = (float *)s->input->extended_data[1];
1173  srclfe = (float *)s->input->extended_data[2];
1174 
1175  for (n = 0; n < s->buf_size; n++) {
1176  float l_re = srcl[2 * n], r_re = srcr[2 * n];
1177  float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1178  float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1179  float c_phase = atan2f(l_im + r_im, l_re + r_re);
1180  float l_mag = hypotf(l_re, l_im);
1181  float r_mag = hypotf(r_re, r_im);
1182  float l_phase = atan2f(l_im, l_re);
1183  float r_phase = atan2f(r_im, r_re);
1184  float phase_dif = fabsf(l_phase - r_phase);
1185  float mag_sum = l_mag + r_mag;
1186  float mag_dif = mag_sum < 0.000001 ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;
1187  float mag_total = hypotf(l_mag, r_mag);
1188  float x, y;
1189 
1190  if (phase_dif > M_PI)
1191  phase_dif = 2 * M_PI - phase_dif;
1192 
1193  stereo_position(mag_dif, phase_dif, &x, &y);
1194  stereo_transform(&x, &y, s->angle);
1195 
1196  s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
1197  }
1198 }
1199 
1201 {
1202  AudioSurroundContext *s = ctx->priv;
1203  float *srcl, *srcr, *srcc, *srcsl, *srcsr;
1204  int n;
1205 
1206  srcl = (float *)s->input->extended_data[0];
1207  srcr = (float *)s->input->extended_data[1];
1208  srcc = (float *)s->input->extended_data[2];
1209  srcsl = (float *)s->input->extended_data[3];
1210  srcsr = (float *)s->input->extended_data[4];
1211 
1212  for (n = 0; n < s->buf_size; n++) {
1213  float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1214  float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1215  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1216  float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
1217  float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
1218  float fl_mag = hypotf(fl_re, fl_im);
1219  float fr_mag = hypotf(fr_re, fr_im);
1220  float fl_phase = atan2f(fl_im, fl_re);
1221  float fr_phase = atan2f(fr_im, fr_re);
1222  float sl_mag = hypotf(sl_re, sl_im);
1223  float sr_mag = hypotf(sr_re, sr_im);
1224  float sl_phase = atan2f(sl_im, sl_re);
1225  float sr_phase = atan2f(sr_im, sr_re);
1226  float phase_difl = fabsf(fl_phase - sl_phase);
1227  float phase_difr = fabsf(fr_phase - sr_phase);
1228  float magl_sum = fl_mag + sl_mag;
1229  float magr_sum = fr_mag + sr_mag;
1230  float mag_difl = magl_sum < 0.000001 ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1231  float mag_difr = magr_sum < 0.000001 ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1232  float mag_totall = hypotf(fl_mag, sl_mag);
1233  float mag_totalr = hypotf(fr_mag, sr_mag);
1234  float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1235  float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1236  float xl, yl;
1237  float xr, yr;
1238 
1239  if (phase_difl > M_PI)
1240  phase_difl = 2 * M_PI - phase_difl;
1241 
1242  if (phase_difr > M_PI)
1243  phase_difr = 2 * M_PI - phase_difr;
1244 
1245  stereo_position(mag_difl, phase_difl, &xl, &yl);
1246  stereo_position(mag_difr, phase_difr, &xr, &yr);
1247 
1248  s->upmix_5_0(ctx, c_re, c_im,
1249  mag_totall, mag_totalr,
1250  fl_phase, fr_phase,
1251  bl_phase, br_phase,
1252  sl_phase, sr_phase,
1253  xl, yl, xr, yr, n);
1254  }
1255 }
1256 
1258 {
1259  AudioSurroundContext *s = ctx->priv;
1260  float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
1261  int n;
1262 
1263  srcl = (float *)s->input->extended_data[0];
1264  srcr = (float *)s->input->extended_data[1];
1265  srcc = (float *)s->input->extended_data[2];
1266  srclfe = (float *)s->input->extended_data[3];
1267  srcsl = (float *)s->input->extended_data[4];
1268  srcsr = (float *)s->input->extended_data[5];
1269 
1270  for (n = 0; n < s->buf_size; n++) {
1271  float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1272  float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1273  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1274  float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1275  float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
1276  float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
1277  float fl_mag = hypotf(fl_re, fl_im);
1278  float fr_mag = hypotf(fr_re, fr_im);
1279  float fl_phase = atan2f(fl_im, fl_re);
1280  float fr_phase = atan2f(fr_im, fr_re);
1281  float sl_mag = hypotf(sl_re, sl_im);
1282  float sr_mag = hypotf(sr_re, sr_im);
1283  float sl_phase = atan2f(sl_im, sl_re);
1284  float sr_phase = atan2f(sr_im, sr_re);
1285  float phase_difl = fabsf(fl_phase - sl_phase);
1286  float phase_difr = fabsf(fr_phase - sr_phase);
1287  float magl_sum = fl_mag + sl_mag;
1288  float magr_sum = fr_mag + sr_mag;
1289  float mag_difl = magl_sum < 0.000001 ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1290  float mag_difr = magr_sum < 0.000001 ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1291  float mag_totall = hypotf(fl_mag, sl_mag);
1292  float mag_totalr = hypotf(fr_mag, sr_mag);
1293  float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
1294  float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
1295  float xl, yl;
1296  float xr, yr;
1297 
1298  if (phase_difl > M_PI)
1299  phase_difl = 2 * M_PI - phase_difl;
1300 
1301  if (phase_difr > M_PI)
1302  phase_difr = 2 * M_PI - phase_difr;
1303 
1304  stereo_position(mag_difl, phase_difl, &xl, &yl);
1305  stereo_position(mag_difr, phase_difr, &xr, &yr);
1306 
1307  s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1308  mag_totall, mag_totalr,
1309  fl_phase, fr_phase,
1310  bl_phase, br_phase,
1311  sl_phase, sr_phase,
1312  xl, yl, xr, yr, n);
1313  }
1314 }
1315 
1317 {
1318  AudioSurroundContext *s = ctx->priv;
1319  float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
1320  int n;
1321 
1322  srcl = (float *)s->input->extended_data[0];
1323  srcr = (float *)s->input->extended_data[1];
1324  srcc = (float *)s->input->extended_data[2];
1325  srclfe = (float *)s->input->extended_data[3];
1326  srcbl = (float *)s->input->extended_data[4];
1327  srcbr = (float *)s->input->extended_data[5];
1328 
1329  for (n = 0; n < s->buf_size; n++) {
1330  float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1331  float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1332  float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1333  float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1334  float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
1335  float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
1336  float fl_mag = hypotf(fl_re, fl_im);
1337  float fr_mag = hypotf(fr_re, fr_im);
1338  float fl_phase = atan2f(fl_im, fl_re);
1339  float fr_phase = atan2f(fr_im, fr_re);
1340  float bl_mag = hypotf(bl_re, bl_im);
1341  float br_mag = hypotf(br_re, br_im);
1342  float bl_phase = atan2f(bl_im, bl_re);
1343  float br_phase = atan2f(br_im, br_re);
1344  float phase_difl = fabsf(fl_phase - bl_phase);
1345  float phase_difr = fabsf(fr_phase - br_phase);
1346  float magl_sum = fl_mag + bl_mag;
1347  float magr_sum = fr_mag + br_mag;
1348  float mag_difl = magl_sum < 0.000001 ? FFDIFFSIGN(fl_mag, bl_mag) : (fl_mag - bl_mag) / magl_sum;
1349  float mag_difr = magr_sum < 0.000001 ? FFDIFFSIGN(fr_mag, br_mag) : (fr_mag - br_mag) / magr_sum;
1350  float mag_totall = hypotf(fl_mag, bl_mag);
1351  float mag_totalr = hypotf(fr_mag, br_mag);
1352  float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
1353  float sr_phase = atan2f(fr_im + br_im, fr_re + br_re);
1354  float xl, yl;
1355  float xr, yr;
1356 
1357  if (phase_difl > M_PI)
1358  phase_difl = 2 * M_PI - phase_difl;
1359 
1360  if (phase_difr > M_PI)
1361  phase_difr = 2 * M_PI - phase_difr;
1362 
1363  stereo_position(mag_difl, phase_difl, &xl, &yl);
1364  stereo_position(mag_difr, phase_difr, &xr, &yr);
1365 
1366  s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
1367  mag_totall, mag_totalr,
1368  fl_phase, fr_phase,
1369  bl_phase, br_phase,
1370  sl_phase, sr_phase,
1371  xl, yl, xr, yr, n);
1372  }
1373 }
1374 
1376 {
1377  AudioSurroundContext *s = ctx->priv;
1378  float overlap;
1379  int i;
1380 
1381  if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) {
1382  av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
1383  s->out_channel_layout_str);
1384  return AVERROR(EINVAL);
1385  }
1386 
1387  if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) {
1388  av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
1389  s->in_channel_layout_str);
1390  return AVERROR(EINVAL);
1391  }
1392 
1393  if (s->lowcutf >= s->highcutf) {
1394  av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
1395  s->lowcutf, s->highcutf);
1396  return AVERROR(EINVAL);
1397  }
1398 
1399  switch (s->in_channel_layout) {
1400  case AV_CH_LAYOUT_STEREO:
1401  s->filter = filter_stereo;
1402  switch (s->out_channel_layout) {
1403  case AV_CH_LAYOUT_MONO:
1404  s->upmix_stereo = upmix_1_0;
1405  break;
1406  case AV_CH_LAYOUT_STEREO:
1407  s->upmix_stereo = upmix_stereo;
1408  break;
1409  case AV_CH_LAYOUT_2POINT1:
1410  s->upmix_stereo = upmix_2_1;
1411  break;
1412  case AV_CH_LAYOUT_SURROUND:
1413  s->upmix_stereo = upmix_3_0;
1414  break;
1415  case AV_CH_LAYOUT_3POINT1:
1416  s->upmix_stereo = upmix_3_1;
1417  break;
1418  case AV_CH_LAYOUT_4POINT0:
1419  s->upmix_stereo = upmix_4_0;
1420  break;
1421  case AV_CH_LAYOUT_4POINT1:
1422  s->upmix_stereo = upmix_4_1;
1423  break;
1425  s->upmix_stereo = upmix_5_0_back;
1426  break;
1428  s->upmix_stereo = upmix_5_1_back;
1429  break;
1430  case AV_CH_LAYOUT_6POINT0:
1431  s->upmix_stereo = upmix_6_0;
1432  break;
1433  case AV_CH_LAYOUT_6POINT1:
1434  s->upmix_stereo = upmix_6_1;
1435  break;
1436  case AV_CH_LAYOUT_7POINT0:
1437  s->upmix_stereo = upmix_7_0;
1438  break;
1439  case AV_CH_LAYOUT_7POINT1:
1440  s->upmix_stereo = upmix_7_1;
1441  break;
1442  default:
1443  goto fail;
1444  }
1445  break;
1446  case AV_CH_LAYOUT_2POINT1:
1447  s->filter = filter_2_1;
1448  switch (s->out_channel_layout) {
1450  s->upmix_2_1 = upmix_5_1_back_2_1;
1451  break;
1452  default:
1453  goto fail;
1454  }
1455  break;
1456  case AV_CH_LAYOUT_SURROUND:
1457  s->filter = filter_surround;
1458  switch (s->out_channel_layout) {
1459  case AV_CH_LAYOUT_3POINT1:
1460  s->upmix_3_0 = upmix_3_1_surround;
1461  break;
1463  s->upmix_3_0 = upmix_5_1_back_surround;
1464  break;
1465  default:
1466  goto fail;
1467  }
1468  break;
1469  case AV_CH_LAYOUT_5POINT0:
1470  s->filter = filter_5_0_side;
1471  switch (s->out_channel_layout) {
1472  case AV_CH_LAYOUT_7POINT1:
1473  s->upmix_5_0 = upmix_7_1_5_0_side;
1474  break;
1475  default:
1476  goto fail;
1477  }
1478  break;
1479  case AV_CH_LAYOUT_5POINT1:
1480  s->filter = filter_5_1_side;
1481  switch (s->out_channel_layout) {
1482  case AV_CH_LAYOUT_7POINT1:
1483  s->upmix_5_1 = upmix_7_1_5_1;
1484  break;
1485  default:
1486  goto fail;
1487  }
1488  break;
1490  s->filter = filter_5_1_back;
1491  switch (s->out_channel_layout) {
1492  case AV_CH_LAYOUT_7POINT1:
1493  s->upmix_5_1 = upmix_7_1_5_1;
1494  break;
1495  default:
1496  goto fail;
1497  }
1498  break;
1499  default:
1500 fail:
1501  av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
1502  s->in_channel_layout_str, s->out_channel_layout_str);
1503  return AVERROR(EINVAL);
1504  }
1505 
1506  s->buf_size = 1 << av_log2(s->win_size);
1507  s->pts = AV_NOPTS_VALUE;
1508 
1509  s->window_func_lut = av_calloc(s->buf_size, sizeof(*s->window_func_lut));
1510  if (!s->window_func_lut)
1511  return AVERROR(ENOMEM);
1512 
1513  generate_window_func(s->window_func_lut, s->buf_size, s->win_func, &overlap);
1514  if (s->overlap == 1)
1515  s->overlap = overlap;
1516 
1517  for (i = 0; i < s->buf_size; i++)
1518  s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->buf_size);
1519  s->hop_size = s->buf_size * (1. - s->overlap);
1520  if (s->hop_size <= 0)
1521  return AVERROR(EINVAL);
1522 
1523  if (s->all_x >= 0.f)
1524  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;
1525  if (s->all_y >= 0.f)
1526  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;
1527 
1528  return 0;
1529 }
1530 
1531 static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1532 {
1533  AudioSurroundContext *s = ctx->priv;
1534  const float level_in = s->input_levels[ch];
1535  float *dst;
1536  int n;
1537 
1538  memset(s->input->extended_data[ch] + s->buf_size * sizeof(float), 0, s->buf_size * sizeof(float));
1539 
1540  dst = (float *)s->input->extended_data[ch];
1541  for (n = 0; n < s->buf_size; n++) {
1542  dst[n] *= s->window_func_lut[n] * level_in;
1543  }
1544 
1545  av_rdft_calc(s->rdft[ch], (float *)s->input->extended_data[ch]);
1546 
1547  return 0;
1548 }
1549 
1550 static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1551 {
1552  AudioSurroundContext *s = ctx->priv;
1553  const float level_out = s->output_levels[ch];
1554  AVFrame *out = arg;
1555  float *dst, *ptr;
1556  int n;
1557 
1558  av_rdft_calc(s->irdft[ch], (float *)s->output->extended_data[ch]);
1559 
1560  dst = (float *)s->output->extended_data[ch];
1561  ptr = (float *)s->overlap_buffer->extended_data[ch];
1562 
1563  memmove(s->overlap_buffer->extended_data[ch],
1564  s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
1565  s->buf_size * sizeof(float));
1566  memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),
1567  0, s->hop_size * sizeof(float));
1568 
1569  for (n = 0; n < s->buf_size; n++) {
1570  ptr[n] += dst[n] * s->window_func_lut[n] * level_out;
1571  }
1572 
1573  ptr = (float *)s->overlap_buffer->extended_data[ch];
1574  dst = (float *)out->extended_data[ch];
1575  memcpy(dst, ptr, s->hop_size * sizeof(float));
1576 
1577  return 0;
1578 }
1579 
1581 {
1582  AVFilterContext *ctx = inlink->dst;
1583  AVFilterLink *outlink = ctx->outputs[0];
1584  AudioSurroundContext *s = ctx->priv;
1585  AVFrame *out;
1586  int ret;
1587 
1588  ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size);
1589  if (ret < 0)
1590  return ret;
1591 
1592  ctx->internal->execute(ctx, fft_channel, NULL, NULL, inlink->channels);
1593 
1594  s->filter(ctx);
1595 
1596  out = ff_get_audio_buffer(outlink, s->hop_size);
1597  if (!out)
1598  return AVERROR(ENOMEM);
1599 
1600  ctx->internal->execute(ctx, ifft_channel, out, NULL, outlink->channels);
1601 
1602  out->pts = s->pts;
1603  if (s->pts != AV_NOPTS_VALUE)
1604  s->pts += av_rescale_q(out->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1605  av_audio_fifo_drain(s->fifo, FFMIN(av_audio_fifo_size(s->fifo), s->hop_size));
1606 
1607  return ff_filter_frame(outlink, out);
1608 }
1609 
1611 {
1612  AVFilterLink *inlink = ctx->inputs[0];
1613  AVFilterLink *outlink = ctx->outputs[0];
1614  AudioSurroundContext *s = ctx->priv;
1615  AVFrame *in = NULL;
1616  int ret = 0, status;
1617  int64_t pts;
1618 
1620 
1621  if (!s->eof && av_audio_fifo_size(s->fifo) < s->buf_size) {
1623  if (ret < 0)
1624  return ret;
1625 
1626  if (ret > 0) {
1627  ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
1628  in->nb_samples);
1629  if (ret >= 0 && s->pts == AV_NOPTS_VALUE)
1630  s->pts = in->pts;
1631 
1632  av_frame_free(&in);
1633  if (ret < 0)
1634  return ret;
1635  }
1636  }
1637 
1638  if ((av_audio_fifo_size(s->fifo) >= s->buf_size) ||
1639  (av_audio_fifo_size(s->fifo) > 0 && s->eof)) {
1640  ret = filter_frame(inlink);
1641  if (av_audio_fifo_size(s->fifo) >= s->buf_size)
1642  ff_filter_set_ready(ctx, 100);
1643  return ret;
1644  }
1645 
1646  if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
1647  if (status == AVERROR_EOF) {
1648  s->eof = 1;
1649  if (av_audio_fifo_size(s->fifo) >= 0) {
1650  ff_filter_set_ready(ctx, 100);
1651  return 0;
1652  }
1653  }
1654  }
1655 
1656  if (s->eof && av_audio_fifo_size(s->fifo) <= 0) {
1657  ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
1658  return 0;
1659  }
1660 
1661  if (!s->eof)
1662  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1663 
1664  return FFERROR_NOT_READY;
1665 }
1666 
1668 {
1669  AudioSurroundContext *s = ctx->priv;
1670  int ch;
1671 
1672  av_frame_free(&s->input);
1673  av_frame_free(&s->output);
1674  av_frame_free(&s->overlap_buffer);
1675 
1676  for (ch = 0; ch < s->nb_in_channels; ch++) {
1677  av_rdft_end(s->rdft[ch]);
1678  }
1679  for (ch = 0; ch < s->nb_out_channels; ch++) {
1680  av_rdft_end(s->irdft[ch]);
1681  }
1682  av_freep(&s->input_levels);
1683  av_freep(&s->output_levels);
1684  av_freep(&s->rdft);
1685  av_freep(&s->irdft);
1686  av_audio_fifo_free(s->fifo);
1687  av_freep(&s->window_func_lut);
1688 }
1689 
1690 #define OFFSET(x) offsetof(AudioSurroundContext, x)
1691 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1692 
1693 static const AVOption surround_options[] = {
1694  { "chl_out", "set output channel layout", OFFSET(out_channel_layout_str), AV_OPT_TYPE_STRING, {.str="5.1"}, 0, 0, FLAGS },
1695  { "chl_in", "set input channel layout", OFFSET(in_channel_layout_str), AV_OPT_TYPE_STRING, {.str="stereo"},0, 0, FLAGS },
1696  { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1697  { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1698  { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
1699  { "lfe_low", "LFE low cut off", OFFSET(lowcutf), AV_OPT_TYPE_INT, {.i64=128}, 0, 256, FLAGS },
1700  { "lfe_high", "LFE high cut off", OFFSET(highcutf), AV_OPT_TYPE_INT, {.i64=256}, 0, 512, FLAGS },
1701  { "lfe_mode", "set LFE channel mode", OFFSET(lfe_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
1702  { "add", "just add LFE channel", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
1703  { "sub", "substract LFE channel with others", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 1, FLAGS, "lfe_mode" },
1704  { "angle", "set soundfield transform angle", OFFSET(angle), AV_OPT_TYPE_FLOAT, {.dbl=90}, 0, 360, FLAGS },
1705  { "fc_in", "set front center channel input level", OFFSET(fc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1706  { "fc_out", "set front center channel output level", OFFSET(fc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1707  { "fl_in", "set front left channel input level", OFFSET(fl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1708  { "fl_out", "set front left channel output level", OFFSET(fl_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1709  { "fr_in", "set front right channel input level", OFFSET(fr_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1710  { "fr_out", "set front right channel output level", OFFSET(fr_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1711  { "sl_in", "set side left channel input level", OFFSET(sl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1712  { "sl_out", "set side left channel output level", OFFSET(sl_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1713  { "sr_in", "set side right channel input level", OFFSET(sr_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1714  { "sr_out", "set side right channel output level", OFFSET(sr_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1715  { "bl_in", "set back left channel input level", OFFSET(bl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1716  { "bl_out", "set back left channel output level", OFFSET(bl_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1717  { "br_in", "set back right channel input level", OFFSET(br_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1718  { "br_out", "set back right channel output level", OFFSET(br_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1719  { "bc_in", "set back center channel input level", OFFSET(bc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1720  { "bc_out", "set back center channel output level", OFFSET(bc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1721  { "lfe_in", "set lfe channel input level", OFFSET(lfe_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1722  { "lfe_out", "set lfe channel output level", OFFSET(lfe_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
1723  { "allx", "set all channel's x spread", OFFSET(all_x), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, FLAGS },
1724  { "ally", "set all channel's y spread", OFFSET(all_y), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 15, FLAGS },
1725  { "fcx", "set front center channel x spread", OFFSET(fc_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1726  { "flx", "set front left channel x spread", OFFSET(fl_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1727  { "frx", "set front right channel x spread", OFFSET(fr_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1728  { "blx", "set back left channel x spread", OFFSET(bl_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1729  { "brx", "set back right channel x spread", OFFSET(br_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1730  { "slx", "set side left channel x spread", OFFSET(sl_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1731  { "srx", "set side right channel x spread", OFFSET(sr_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1732  { "bcx", "set back center channel x spread", OFFSET(bc_x), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1733  { "fcy", "set front center channel y spread", OFFSET(fc_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1734  { "fly", "set front left channel y spread", OFFSET(fl_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1735  { "fry", "set front right channel y spread", OFFSET(fr_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1736  { "bly", "set back left channel y spread", OFFSET(bl_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1737  { "bry", "set back right channel y spread", OFFSET(br_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1738  { "sly", "set side left channel y spread", OFFSET(sl_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1739  { "sry", "set side right channel y spread", OFFSET(sr_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1740  { "bcy", "set back center channel y spread", OFFSET(bc_y), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 15, FLAGS },
1741  { "win_size", "set window size", OFFSET(win_size), AV_OPT_TYPE_INT, {.i64 = 4096}, 1024, 65536, FLAGS },
1742  { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
1743  { "rect", "Rectangular", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT}, 0, 0, FLAGS, "win_func" },
1744  { "bartlett", "Bartlett", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
1745  { "hann", "Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
1746  { "hanning", "Hanning", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
1747  { "hamming", "Hamming", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
1748  { "blackman", "Blackman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
1749  { "welch", "Welch", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH}, 0, 0, FLAGS, "win_func" },
1750  { "flattop", "Flat-top", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP}, 0, 0, FLAGS, "win_func" },
1751  { "bharris", "Blackman-Harris", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS}, 0, 0, FLAGS, "win_func" },
1752  { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
1753  { "bhann", "Bartlett-Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN}, 0, 0, FLAGS, "win_func" },
1754  { "sine", "Sine", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE}, 0, 0, FLAGS, "win_func" },
1755  { "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
1756  { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
1757  { "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
1758  { "tukey", "Tukey", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY}, 0, 0, FLAGS, "win_func" },
1759  { "dolph", "Dolph-Chebyshev", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH}, 0, 0, FLAGS, "win_func" },
1760  { "cauchy", "Cauchy", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY}, 0, 0, FLAGS, "win_func" },
1761  { "parzen", "Parzen", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN}, 0, 0, FLAGS, "win_func" },
1762  { "poisson", "Poisson", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON}, 0, 0, FLAGS, "win_func" },
1763  { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, FLAGS, "win_func" },
1764  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
1765  { NULL }
1766 };
1767 
1768 AVFILTER_DEFINE_CLASS(surround);
1769 
1770 static const AVFilterPad inputs[] = {
1771  {
1772  .name = "default",
1773  .type = AVMEDIA_TYPE_AUDIO,
1774  .config_props = config_input,
1775  },
1776  { NULL }
1777 };
1778 
1779 static const AVFilterPad outputs[] = {
1780  {
1781  .name = "default",
1782  .type = AVMEDIA_TYPE_AUDIO,
1783  .config_props = config_output,
1784  },
1785  { NULL }
1786 };
1787 
1789  .name = "surround",
1790  .description = NULL_IF_CONFIG_SMALL("Apply audio surround upmix filter."),
1791  .query_formats = query_formats,
1792  .priv_size = sizeof(AudioSurroundContext),
1793  .priv_class = &surround_class,
1794  .init = init,
1795  .uninit = uninit,
1796  .activate = activate,
1797  .inputs = inputs,
1798  .outputs = outputs,
1800 };
AV_CH_LAYOUT_7POINT0
#define AV_CH_LAYOUT_7POINT0
Definition: channel_layout.h:105
av_audio_fifo_free
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
formats
formats
Definition: signature.h:48
AudioSurroundContext::irdft
RDFTContext ** irdft
Definition: af_surround.c:107
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:86
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:147
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:530
AV_CH_LAYOUT_6POINT1
#define AV_CH_LAYOUT_6POINT1
Definition: channel_layout.h:102
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:1040
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
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:97
r
const char * r
Definition: vf_curves.c:114
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:90
opt.h
AudioSurroundContext
Definition: af_surround.c:33
AudioSurroundContext::fl_x
float fl_x
Definition: af_surround.c:69
AudioSurroundContext::fr_y
float fr_y
Definition: af_surround.c:79
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:121
AudioSurroundContext::br_x
float br_x
Definition: af_surround.c:72
n
int n
Definition: avisynth_c.h:760
AudioSurroundContext::sr_y
float sr_y
Definition: af_surround.c:83
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
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:85
atan2f
#define atan2f(y, x)
Definition: libm.h:45
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
AudioSurroundContext::bl_in
float bl_in
Definition: af_surround.c:51
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:1690
init
static int init(AVFilterContext *ctx)
Definition: af_surround.c:1375
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AudioSurroundContext::sl_y
float sl_y
Definition: af_surround.c:82
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AudioSurroundContext::hop_size
int hop_size
Definition: af_surround.c:105
AudioSurroundContext::sl_x
float sl_x
Definition: af_surround.c:73
AudioSurroundContext::output_levels
float * output_levels
Definition: af_surround.c:87
M_PI_2
#define M_PI_2
Definition: mathematics.h:55
AudioSurroundContext::nb_out_channels
int nb_out_channels
Definition: af_surround.c:98
AVOption
AVOption.
Definition: opt.h:246
av_get_channel_layout
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Definition: channel_layout.c:139
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:130
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
AudioSurroundContext::overlap
float overlap
Definition: af_surround.c:63
AudioSurroundContext::fc_y
float fc_y
Definition: af_surround.c:77
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1795
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:401
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:59
WFUNC_FLATTOP
@ WFUNC_FLATTOP
Definition: window_func.h:29
AudioSurroundContext::fc_in
float fc_in
Definition: af_surround.c:41
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_surround.c:1667
AudioSurroundContext::output_lfe
int output_lfe
Definition: af_surround.c:88
AV_CH_LAYOUT_6POINT0
#define AV_CH_LAYOUT_6POINT0
Definition: channel_layout.h:99
filter_frame
static int filter_frame(AVFilterLink *inlink)
Definition: af_surround.c:1580
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1481
WFUNC_BLACKMAN
@ WFUNC_BLACKMAN
Definition: af_firequalizer.c:36
WFUNC_PARZEN
@ WFUNC_PARZEN
Definition: window_func.h:32
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:688
AVAudioFifo
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
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:604
cosf
#define cosf(x)
Definition: libm.h:78
av_audio_fifo_drain
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:201
fail
#define fail()
Definition: checkasm.h:120
AudioSurroundContext::all_y
float all_y
Definition: af_surround.c:66
AV_CH_BACK_LEFT
#define AV_CH_BACK_LEFT
Definition: channel_layout.h:53
IDFT_C2R
@ IDFT_C2R
Definition: avfft.h:73
AudioSurroundContext::sr_out
float sr_out
Definition: af_surround.c:50
AudioSurroundContext::level_in
float level_in
Definition: af_surround.c:39
pts
static int64_t pts
Definition: transcode_aac.c:647
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
WFUNC_BHANN
@ WFUNC_BHANN
Definition: window_func.h:31
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
FLAGS
#define FLAGS
Definition: af_surround.c:1691
AudioSurroundContext::pts
int64_t pts
Definition: af_surround.c:110
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
WFUNC_DOLPH
@ WFUNC_DOLPH
Definition: window_func.h:32
av_cold
#define av_cold
Definition: attributes.h:84
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:568
AV_CH_LOW_FREQUENCY
#define AV_CH_LOW_FREQUENCY
Definition: channel_layout.h:52
filter_5_1_back
static void filter_5_1_back(AVFilterContext *ctx)
Definition: af_surround.c:1316
WFUNC_NUTTALL
@ WFUNC_NUTTALL
Definition: af_firequalizer.c:39
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
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
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:643
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_surround.c:159
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_audio_fifo_write
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
AudioSurroundContext::fr_in
float fr_in
Definition: af_surround.c:45
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AudioSurroundContext::br_in
float br_in
Definition: af_surround.c:53
surround_options
static const AVOption surround_options[]
Definition: af_surround.c:1693
outputs
static const AVFilterPad outputs[]
Definition: af_surround.c:1779
AudioSurroundContext::buf_size
int buf_size
Definition: af_surround.c:104
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:495
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:924
WFUNC_LANCZOS
@ WFUNC_LANCZOS
Definition: window_func.h:31
filters.h
WFUNC_RECT
@ WFUNC_RECT
Definition: window_func.h:28
ctx
AVFormatContext * ctx
Definition: movenc.c:48
WFUNC_BHARRIS
@ WFUNC_BHARRIS
Definition: af_firequalizer.c:41
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AudioSurroundContext::overlap_buffer
AVFrame * overlap_buffer
Definition: af_surround.c:102
AudioSurroundContext::fr_x
float fr_x
Definition: af_surround.c:70
f
#define f(width, name)
Definition: cbs_vp9.c:255
av_rdft_calc
void av_rdft_calc(RDFTContext *s, FFTSample *data)
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:138
AudioSurroundContext::in_channel_layout
uint64_t in_channel_layout
Definition: af_surround.c:96
arg
const char * arg
Definition: jacosubdec.c:66
AudioSurroundContext::br_y
float br_y
Definition: af_surround.c:81
AudioSurroundContext::lowcutf
int lowcutf
Definition: af_surround.c:89
AudioSurroundContext::bc_in
float bc_in
Definition: af_surround.c:55
AudioSurroundContext::level_out
float level_out
Definition: af_surround.c:40
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
AudioSurroundContext::sr_x
float sr_x
Definition: af_surround.c:74
filter_stereo
static void filter_stereo(AVFilterContext *ctx)
Definition: af_surround.c:1096
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_audio_fifo_alloc
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
WFUNC_HAMMING
@ WFUNC_HAMMING
Definition: af_firequalizer.c:35
AudioSurroundContext::filter
void(* filter)(AVFilterContext *ctx)
Definition: af_surround.c:113
AudioSurroundContext::fifo
AVAudioFifo * fifo
Definition: af_surround.c:106
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:337
filter_5_0_side
static void filter_5_0_side(AVFilterContext *ctx)
Definition: af_surround.c:1200
AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_5POINT1
Definition: channel_layout.h:96
AudioSurroundContext::lowcut
float lowcut
Definition: af_surround.c:92
ff_log2
#define ff_log2
Definition: intmath.h:50
DFT_R2C
@ DFT_R2C
Definition: avfft.h:72
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:36
AudioSurroundContext::fc_x
float fc_x
Definition: af_surround.c:68
avfft.h
WFUNC_HANNING
@ WFUNC_HANNING
Definition: window_func.h:28
AudioSurroundContext::input_levels
float * input_levels
Definition: af_surround.c:86
WFUNC_BARTLETT
@ WFUNC_BARTLETT
Definition: window_func.h:29
sinf
#define sinf(x)
Definition: libm.h:419
AudioSurroundContext::nb_in_channels
int nb_in_channels
Definition: af_surround.c:97
stereo_transform
static void stereo_transform(float *x, float *y, float angle)
Definition: af_surround.c:317
WFUNC_BOHMAN
@ WFUNC_BOHMAN
Definition: window_func.h:33
fft_channel
static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_surround.c:1531
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:51
ifft_channel
static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_surround.c:1550
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:1436
AudioSurroundContext::bl_out
float bl_out
Definition: af_surround.c:52
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
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:564
AudioSurroundContext::eof
int eof
Definition: af_surround.c:111
av_rdft_init
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
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:188
powf
#define powf(x, y)
Definition: libm.h:50
AudioSurroundContext::out_channel_layout_str
char * out_channel_layout_str
Definition: af_surround.c:36
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
activate
static int activate(AVFilterContext *ctx)
Definition: af_surround.c:1610
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
WFUNC_TUKEY
@ WFUNC_TUKEY
Definition: af_firequalizer.c:42
AudioSurroundContext::fl_out
float fl_out
Definition: af_surround.c:44
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: common.h:92
AudioSurroundContext::sl_out
float sl_out
Definition: af_surround.c:48
AudioSurroundContext::in_channel_layout_str
char * in_channel_layout_str
Definition: af_surround.c:37
AudioSurroundContext::lfe_out
float lfe_out
Definition: af_surround.c:58
AudioSurroundContext::fc_out
float fc_out
Definition: af_surround.c:42
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
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_CH_LAYOUT_5POINT1_BACK
#define AV_CH_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:98
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
AudioSurroundContext::sl_in
float sl_in
Definition: af_surround.c:47
av_audio_fifo_size
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
M_PI
#define M_PI
Definition: mathematics.h:52
AV_CH_LAYOUT_3POINT1
#define AV_CH_LAYOUT_3POINT1
Definition: channel_layout.h:90
AudioSurroundContext::out_channel_layout
uint64_t out_channel_layout
Definition: af_surround.c:95
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_surround.c:260
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
AudioSurroundContext::bc_y
float bc_y
Definition: af_surround.c:84
AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_5POINT0
Definition: channel_layout.h:95
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
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:54
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(surround)
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
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:828
AV_CH_LAYOUT_2POINT1
#define AV_CH_LAYOUT_2POINT1
Definition: channel_layout.h:87
AudioSurroundContext::fl_y
float fl_y
Definition: af_surround.c:78
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:874
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
RDFTContext
Definition: rdft.h:28
filter_5_1_side
static void filter_5_1_side(AVFilterContext *ctx)
Definition: af_surround.c:1257
av_get_channel_layout_channel_index
int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel)
Get the index of a channel in channel_layout.
Definition: channel_layout.c:233
AV_CH_LAYOUT_7POINT1
#define AV_CH_LAYOUT_7POINT1
Definition: channel_layout.h:107
AV_CH_LAYOUT_4POINT1
#define AV_CH_LAYOUT_4POINT1
Definition: channel_layout.h:92
AV_CH_BACK_CENTER
#define AV_CH_BACK_CENTER
Definition: channel_layout.h:57
AV_CH_FRONT_LEFT
#define AV_CH_FRONT_LEFT
Definition: channel_layout.h:49
audio_fifo.h
AV_CH_SIDE_RIGHT
#define AV_CH_SIDE_RIGHT
Definition: channel_layout.h:59
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
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:431
filter_surround
static void filter_surround(AVFilterContext *ctx)
Definition: af_surround.c:1129
AudioSurroundContext::win_size
int win_size
Definition: af_surround.c:61
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:377
AVFilter
Filter definition.
Definition: avfilter.h:144
AudioSurroundContext::output
AVFrame * output
Definition: af_surround.c:101
ff_af_surround
AVFilter ff_af_surround
Definition: af_surround.c:1788
ret
ret
Definition: filter_design.txt:187
AudioSurroundContext::angle
float angle
Definition: af_surround.c:60
AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_SURROUND
Definition: channel_layout.h:89
AudioSurroundContext::fl_in
float fl_in
Definition: af_surround.c:43
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_surround.c:197
AudioSurroundContext::rdft
RDFTContext ** rdft
Definition: af_surround.c:107
AudioSurroundContext::win_func
int win_func
Definition: af_surround.c:62
window_func.h
AudioSurroundContext::window_func_lut
float * window_func_lut
Definition: af_surround.c:108
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:114
NB_WFUNC
@ NB_WFUNC
Definition: af_firequalizer.c:43
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
channel_layout.h
WFUNC_SINE
@ WFUNC_SINE
Definition: window_func.h:30
WFUNC_CAUCHY
@ WFUNC_CAUCHY
Definition: window_func.h:32
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:980
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
AudioSurroundContext::bc_x
float bc_x
Definition: af_surround.c:75
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:345
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:460
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
AV_CH_FRONT_RIGHT
#define AV_CH_FRONT_RIGHT
Definition: channel_layout.h:50
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:358
AudioSurroundContext::sr_in
float sr_in
Definition: af_surround.c:49
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:116
WFUNC_GAUSS
@ WFUNC_GAUSS
Definition: window_func.h:31
WFUNC_BNUTTALL
@ WFUNC_BNUTTALL
Definition: af_firequalizer.c:40
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:782
audio.h
M_LN10
#define M_LN10
Definition: mathematics.h:43
WFUNC_POISSON
@ WFUNC_POISSON
Definition: window_func.h:32
AudioSurroundContext::highcut
float highcut
Definition: af_surround.c:93
AudioSurroundContext::lfe_in
float lfe_in
Definition: af_surround.c:57
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AudioSurroundContext::bc_out
float bc_out
Definition: af_surround.c:56
AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_4POINT0
Definition: channel_layout.h:91
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_rdft_end
void av_rdft_end(RDFTContext *s)
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
AV_CH_BACK_RIGHT
#define AV_CH_BACK_RIGHT
Definition: channel_layout.h:54
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
AudioSurroundContext::fr_out
float fr_out
Definition: af_surround.c:46
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:732
av_audio_fifo_peek
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
Definition: audio_fifo.c:138
AudioSurroundContext::bl_y
float bl_y
Definition: af_surround.c:80
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AudioSurroundContext::bl_x
float bl_x
Definition: af_surround.c:71
WFUNC_WELCH
@ WFUNC_WELCH
Definition: window_func.h:29
stereo_position
static void stereo_position(float a, float p, float *x, float *y)
Definition: af_surround.c:337
filter_2_1
static void filter_2_1(AVFilterContext *ctx)
Definition: af_surround.c:1165
AV_CH_SIDE_LEFT
#define AV_CH_SIDE_LEFT
Definition: channel_layout.h:58
AudioSurroundContext::all_x
float all_x
Definition: af_surround.c:65
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:193
inputs
static const AVFilterPad inputs[]
Definition: af_surround.c:1770