History

avfilter/af_surround: speed up slice threading for stereo upmixing

And add stereo->octagonal/8.0 upmix.

Paul B Mahol committed 4 years ago

Commit e0fbf891 parent 104b5161 file · +831 −472Browse files

Unified · Split

libavfilter/af_surround.c+831−472
@@ -85,6 +85,7 @@ typedef struct AudioSurroundContext { · 84 unmodified lines
85 float *input_levels;85 float *input_levels;
86 float *output_levels;86 float *output_levels;
87 int output_lfe;87 int output_lfe;
88 int have_lfe;
88 int lowcutf;89 int lowcutf;
89 int highcutf;90 int highcutf;
90 91
@@ -103,20 +104,23 @@ typedef struct AudioSurroundContext { · 12 unmodified lines
103 AVFrame *overlap_buffer;104 AVFrame *overlap_buffer;
104 AVFrame *window;105 AVFrame *window;
105 106
107 float *x_pos;
108 float *y_pos;
109 float *l_phase;
110 float *r_phase;
111 float *c_phase;
112 float *lfe_mag;
113 float *mag_total;
114
106 int buf_size;115 int buf_size;
116 int rdft_size;
107 int hop_size;117 int hop_size;
108 AVTXContext **rdft, **irdft;118 AVTXContext **rdft, **irdft;
109 av_tx_fn tx_fn, itx_fn;119 av_tx_fn tx_fn, itx_fn;
110 float *window_func_lut;120 float *window_func_lut;
111 121
112 void (*filter)(AVFilterContext *ctx);122 void (*filter)(AVFilterContext *ctx);
113 void (*upmix_stereo)(AVFilterContext *ctx,123 int (*upmix)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs);
114 float l_phase,
115 float r_phase,
116 float c_phase,
117 float mag_total,
118 float x, float y,
119 int n);
120 void (*upmix_2_1)(AVFilterContext *ctx,124 void (*upmix_2_1)(AVFilterContext *ctx,
121 float l_phase,125 float l_phase,
122 float r_phase,126 float r_phase,
@@ -279,6 +283,7 @@ static int config_output(AVFilterLink *outlink) · 156 unmodified lines
279 if (ret < 0)283 if (ret < 0)
280 return ret;284 return ret;
281 }285 }
286
282 s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));287 s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
283 if (!s->output_levels)288 if (!s->output_levels)
284 return AVERROR(ENOMEM);289 return AVERROR(ENOMEM);
@@ -318,6 +323,19 @@ static int config_output(AVFilterLink *outlink) · 33 unmodified lines
318 if (!s->overlap_buffer || !s->output || !s->output_out)323 if (!s->overlap_buffer || !s->output || !s->output_out)
319 return AVERROR(ENOMEM);324 return AVERROR(ENOMEM);
320 325
326 s->rdft_size = s->buf_size / 2 + 1;
327
328 s->x_pos = av_calloc(s->rdft_size, sizeof(*s->x_pos));
329 s->y_pos = av_calloc(s->rdft_size, sizeof(*s->y_pos));
330 s->l_phase = av_calloc(s->rdft_size, sizeof(*s->l_phase));
331 s->r_phase = av_calloc(s->rdft_size, sizeof(*s->r_phase));
332 s->c_phase = av_calloc(s->rdft_size, sizeof(*s->c_phase));
333 s->mag_total = av_calloc(s->rdft_size, sizeof(*s->mag_total));
334 s->lfe_mag = av_calloc(s->rdft_size, sizeof(*s->lfe_mag));
335 if (!s->x_pos || !s->y_pos || !s->l_phase || !s->r_phase ||
336 !s->c_phase || !s->lfe_mag)
337 return AVERROR(ENOMEM);
338
321 return 0;339 return 0;
322}340}
323 341
@@ -362,141 +380,132 @@ static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut, · 38 unmodified lines
362 }380 }
363}381}
364 382
365static void upmix_1_0(AVFilterContext *ctx,383#define TRANSFORM \
366 float l_phase,384 dst[2 * n ] = mag * cosf(ph); \
367 float r_phase,385 dst[2 * n + 1] = mag * sinf(ph);
368 float c_phase,386
369 float mag_total,387static int upmix_1_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
370 float x, float y,
371 int n)
372{388{
373 AudioSurroundContext *s = ctx->priv;389 AudioSurroundContext *s = ctx->priv;
374 float mag, *dst;390 float *dst = (float *)s->output->extended_data[0];
375 391 const float *mag_total = s->mag_total;
376 dst = (float *)s->output->extended_data[0];392 const int rdft_size = s->rdft_size;
377 393 const float *phase = s->c_phase;
378 mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;394 const float *x = s->x_pos;
395 const float *y = s->y_pos;
396 const float fc_x = s->fc_x;
397 const float fc_y = s->fc_y;
398
399 for (int n = 0; n < rdft_size; n++) {
400 float mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
401 float ph = phase[n];
402
403 TRANSFORM
404 }
379 405
380 dst[2 * n ] = mag * cosf(c_phase);406 return 0;
381 dst[2 * n + 1] = mag * sinf(c_phase);
382}407}
383 408
384static void upmix_stereo(AVFilterContext *ctx,409static int upmix_stereo(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
385 float l_phase,
386 float r_phase,
387 float c_phase,
388 float mag_total,
389 float x, float y,
390 int n)
391{410{
392 AudioSurroundContext *s = ctx->priv;411 AudioSurroundContext *s = ctx->priv;
393 float l_mag, r_mag, *dstl, *dstr;412 float *dst = (float *)s->output->extended_data[ch];
394 413 const float *phase = ch ? s->r_phase : s->l_phase;
395 dstl = (float *)s->output->extended_data[0];414 const float f_x = ch ? s->fr_x : s->fl_x;
396 dstr = (float *)s->output->extended_data[1];415 const float f_y = ch ? s->fr_y : s->fl_y;
397 416 const float *mag_total = s->mag_total;
398 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;417 const int rdft_size = s->rdft_size;
399 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;418 const float neg = ch ? -1.f : 1.f;
400 419 const float *x = s->x_pos;
401 dstl[2 * n ] = l_mag * cosf(l_phase);420 const float *y = s->y_pos;
402 dstl[2 * n + 1] = l_mag * sinf(l_phase);421
422 for (int n = 0; n < rdft_size; n++) {
423 float mag = powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
424 float ph = phase[n];
425
426 TRANSFORM
427 }
403 428
404 dstr[2 * n ] = r_mag * cosf(r_phase);429 return 0;
405 dstr[2 * n + 1] = r_mag * sinf(r_phase);
406}430}
407 431
408static void upmix_2_1(AVFilterContext *ctx,432static int upmix_2_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
409 float l_phase,
410 float r_phase,
411 float c_phase,
412 float mag_total,
413 float x, float y,
414 int n)
415{433{
416 AudioSurroundContext *s = ctx->priv;434 AudioSurroundContext *s = ctx->priv;
417 float lfe_mag, l_mag, r_mag, *dstl, *dstr, *dstlfe;435 float *dst = (float *)s->output->extended_data[ch];
418 436 const float *mag_total = s->mag_total;
419 dstl = (float *)s->output->extended_data[0];437 const int rdft_size = s->rdft_size;
420 dstr = (float *)s->output->extended_data[1];438 const float *phase = ch == 2 ? s->c_phase : ch == 1 ? s->r_phase : s->l_phase;
421 dstlfe = (float *)s->output->extended_data[2];439 const float *lfe_mag = s->lfe_mag;
422 440 const float f_x = ch ? s->fr_x : s->fl_x;
423 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);441 const float f_y = ch ? s->fr_y : s->fl_y;
424 442 const float neg = ch ? -1.f : 1.f;
425 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;443 const float *x = s->x_pos;
426 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;444 const float *y = s->y_pos;
427 445
428 dstl[2 * n ] = l_mag * cosf(l_phase);446 for (int n = 0; n < rdft_size; n++) {
429 dstl[2 * n + 1] = l_mag * sinf(l_phase);447 float mag = ch == 2 ? lfe_mag[n] : powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
430 448 float ph = phase[n];
431 dstr[2 * n ] = r_mag * cosf(r_phase);449
432 dstr[2 * n + 1] = r_mag * sinf(r_phase);450 TRANSFORM
451 }
433 452
434 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);453 return 0;
435 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
436}454}
437 455
438static void upmix_3_0(AVFilterContext *ctx,456static int upmix_3_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
439 float l_phase,
440 float r_phase,
441 float c_phase,
442 float mag_total,
443 float x, float y,
444 int n)
445{457{
446 AudioSurroundContext *s = ctx->priv;458 AudioSurroundContext *s = ctx->priv;
447 float l_mag, r_mag, c_mag, *dstc, *dstl, *dstr;459 float *dst = (float *)s->output->extended_data[ch];
448 460 const float *phase = ch == 2 ? s->c_phase : ch == 1 ? s->r_phase : s->l_phase;
449 dstl = (float *)s->output->extended_data[0];461 const float f_x = ch ? s->fr_x : s->fl_x;
450 dstr = (float *)s->output->extended_data[1];462 const float f_y = ch ? s->fr_y : s->fl_y;
451 dstc = (float *)s->output->extended_data[2];463 const float *mag_total = s->mag_total;
452 464 const int rdft_size = s->rdft_size;
453 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;465 const float neg = ch ? -1.f : 1.f;
454 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;466 const float fc_x = s->fc_x;
455 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;467 const float fc_y = s->fc_y;
456 468 const float *x = s->x_pos;
457 dstl[2 * n ] = l_mag * cosf(l_phase);469 const float *y = s->y_pos;
458 dstl[2 * n + 1] = l_mag * sinf(l_phase);470
459 471 for (int n = 0; n < rdft_size; n++) {
460 dstr[2 * n ] = r_mag * cosf(r_phase);472 float mag = ch == 2 ?
461 dstr[2 * n + 1] = r_mag * sinf(r_phase);473 powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n] :
474 powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
475 float ph = phase[n];
476
477 TRANSFORM
478 }
462 479
463 dstc[2 * n ] = c_mag * cosf(c_phase);480 return 0;
464 dstc[2 * n + 1] = c_mag * sinf(c_phase);
465}481}
466 482
467static void upmix_3_1(AVFilterContext *ctx,483static int upmix_3_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
468 float l_phase,
469 float r_phase,
470 float c_phase,
471 float mag_total,
472 float x, float y,
473 int n)
474{484{
475 AudioSurroundContext *s = ctx->priv;485 AudioSurroundContext *s = ctx->priv;
476 float lfe_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstlfe;486 float *dst = (float *)s->output->extended_data[ch];
477 487 const float *phase = ch >= 2 ? s->c_phase : ch == 1 ? s->r_phase : s->l_phase;
478 dstl = (float *)s->output->extended_data[0];488 const float f_x = ch ? s->fr_x : s->fl_x;
479 dstr = (float *)s->output->extended_data[1];489 const float f_y = ch ? s->fr_y : s->fl_y;
480 dstc = (float *)s->output->extended_data[2];490 const float *mag_total = s->mag_total;
481 dstlfe = (float *)s->output->extended_data[3];491 const int rdft_size = s->rdft_size;
482 492 const float neg = ch ? -1.f : 1.f;
483 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);493 const float *lfe_mag = s->lfe_mag;
484 494 const float fc_x = s->fc_x;
485 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;495 const float fc_y = s->fc_y;
486 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;496 const float *x = s->x_pos;
487 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;497 const float *y = s->y_pos;
488 498
489 dstl[2 * n ] = l_mag * cosf(l_phase);499 for (int n = 0; n < rdft_size; n++) {
490 dstl[2 * n + 1] = l_mag * sinf(l_phase);500 float mag = ch == 3 ? lfe_mag[n] : ch == 2 ?
491 501 powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n] :
492 dstr[2 * n ] = r_mag * cosf(r_phase);502 powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
493 dstr[2 * n + 1] = r_mag * sinf(r_phase);503 float ph = phase[n];
494 504
495 dstc[2 * n ] = c_mag * cosf(c_phase);505 TRANSFORM
496 dstc[2 * n + 1] = c_mag * sinf(c_phase);506 }
497 507
498 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);508 return 0;
499 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
500}509}
501 510
502static void upmix_3_1_surround(AVFilterContext *ctx,511static void upmix_3_1_surround(AVFilterContext *ctx,
@@ -534,256 +543,385 @@ static void upmix_3_1_surround(AVFilterContext *ctx, · 31 unmodified lines
534 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);543 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
535}544}
536 545
537static void upmix_4_0(AVFilterContext *ctx,546static int upmix_4_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
538 float l_phase,
539 float r_phase,
540 float c_phase,
541 float mag_total,
542 float x, float y,
543 int n)
544{547{
545 AudioSurroundContext *s = ctx->priv;548 AudioSurroundContext *s = ctx->priv;
546 float b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb;549 float *dst = (float *)s->output->extended_data[ch];
547 550 const float *mag_total = s->mag_total;
548 dstl = (float *)s->output->extended_data[0];551 const int rdft_size = s->rdft_size;
549 dstr = (float *)s->output->extended_data[1];552 const float *l_phase = s->l_phase;
550 dstc = (float *)s->output->extended_data[2];553 const float *r_phase = s->r_phase;
551 dstb = (float *)s->output->extended_data[3];554 const float *c_phase = s->c_phase;
552 555 const float fl_x = s->fl_x;
553 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;556 const float fl_y = s->fl_y;
554 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;557 const float fr_x = s->fr_x;
555 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;558 const float fr_y = s->fr_y;
556 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;559 const float fc_x = s->fc_x;
557 560 const float fc_y = s->fc_y;
558 dstl[2 * n ] = l_mag * cosf(l_phase);561 const float bc_x = s->bc_x;
559 dstl[2 * n + 1] = l_mag * sinf(l_phase);562 const float bc_y = s->bc_y;
560 563 const float *x = s->x_pos;
561 dstr[2 * n ] = r_mag * cosf(r_phase);564 const float *y = s->y_pos;
562 dstr[2 * n + 1] = r_mag * sinf(r_phase);565
566 for (int n = 0; n < rdft_size; n++) {
567 float mag, ph;
568
569 switch (ch) {
570 case 0:
571 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
572 ph = l_phase[n];
573 break;
574 case 1:
575 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
576 ph = r_phase[n];
577 break;
578 case 2:
579 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
580 ph = c_phase[n];
581 break;
582 case 3:
583 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
584 ph = c_phase[n];
585 break;
586 }
563 587
564 dstc[2 * n ] = c_mag * cosf(c_phase);588 TRANSFORM
565 dstc[2 * n + 1] = c_mag * sinf(c_phase);589 }
566 590
567 dstb[2 * n ] = b_mag * cosf(c_phase);591 return 0;
568 dstb[2 * n + 1] = b_mag * sinf(c_phase);
569}592}
570 593
571static void upmix_4_1(AVFilterContext *ctx,594static int upmix_4_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
572 float l_phase,
573 float r_phase,
574 float c_phase,
575 float mag_total,
576 float x, float y,
577 int n)
578{595{
579 AudioSurroundContext *s = ctx->priv;596 AudioSurroundContext *s = ctx->priv;
580 float lfe_mag, b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb, *dstlfe;597 float *dst = (float *)s->output->extended_data[ch];
581 598 const float *mag_total = s->mag_total;
582 dstl = (float *)s->output->extended_data[0];599 const int rdft_size = s->rdft_size;
583 dstr = (float *)s->output->extended_data[1];600 const float *lfe_mag = s->lfe_mag;
584 dstc = (float *)s->output->extended_data[2];601 const float *l_phase = s->l_phase;
585 dstlfe = (float *)s->output->extended_data[3];602 const float *r_phase = s->r_phase;
586 dstb = (float *)s->output->extended_data[4];603 const float *c_phase = s->c_phase;
587 604 const float fl_x = s->fl_x;
588 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);605 const float fl_y = s->fl_y;
589 606 const float fr_x = s->fr_x;
590 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);607 const float fr_y = s->fr_y;
591 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);608 const float fc_x = s->fc_x;
592 609 const float fc_y = s->fc_y;
593 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;610 const float bc_x = s->bc_x;
594 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;611 const float bc_y = s->bc_y;
595 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;612 const float *x = s->x_pos;
596 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;613 const float *y = s->y_pos;
597 614
598 dstl[2 * n ] = l_mag * cosf(l_phase);615 for (int n = 0; n < rdft_size; n++) {
599 dstl[2 * n + 1] = l_mag * sinf(l_phase);616 float mag, ph;
600 617
601 dstr[2 * n ] = r_mag * cosf(r_phase);618 switch (ch) {
602 dstr[2 * n + 1] = r_mag * sinf(r_phase);619 case 0:
620 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
621 ph = l_phase[n];
622 break;
623 case 1:
624 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
625 ph = r_phase[n];
626 break;
627 case 2:
628 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
629 ph = c_phase[n];
630 break;
631 case 3:
632 mag = lfe_mag[n];
633 ph = c_phase[n];
634 break;
635 case 4:
636 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
637 ph = c_phase[n];
638 break;
639 }
603 640
604 dstc[2 * n ] = c_mag * cosf(c_phase);641 TRANSFORM
605 dstc[2 * n + 1] = c_mag * sinf(c_phase);642 }
606 643
607 dstb[2 * n ] = b_mag * cosf(c_phase);644 return 0;
608 dstb[2 * n + 1] = b_mag * sinf(c_phase);
609}645}
610 646
611static void upmix_5_0_back(AVFilterContext *ctx,647static int upmix_5_0_back(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
612 float l_phase,
613 float r_phase,
614 float c_phase,
615 float mag_total,
616 float x, float y,
617 int n)
618{648{
619 AudioSurroundContext *s = ctx->priv;649 AudioSurroundContext *s = ctx->priv;
620 float l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs;650 float *dst = (float *)s->output->extended_data[ch];
621 651 const float *mag_total = s->mag_total;
622 dstl = (float *)s->output->extended_data[0];652 const int rdft_size = s->rdft_size;
623 dstr = (float *)s->output->extended_data[1];653 const float *l_phase = s->l_phase;
624 dstc = (float *)s->output->extended_data[2];654 const float *r_phase = s->r_phase;
625 dstls = (float *)s->output->extended_data[3];655 const float *c_phase = s->c_phase;
626 dstrs = (float *)s->output->extended_data[4];656 const float fl_x = s->fl_x;
627 657 const float fl_y = s->fl_y;
628 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;658 const float fr_x = s->fr_x;
629 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;659 const float fr_y = s->fr_y;
630 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;660 const float bl_x = s->bl_x;
631 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;661 const float bl_y = s->bl_y;
632 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;662 const float br_x = s->br_x;
633 663 const float br_y = s->br_y;
634 dstl[2 * n ] = l_mag * cosf(l_phase);664 const float fc_x = s->fc_x;
635 dstl[2 * n + 1] = l_mag * sinf(l_phase);665 const float fc_y = s->fc_y;
636 666 const float *x = s->x_pos;
637 dstr[2 * n ] = r_mag * cosf(r_phase);667 const float *y = s->y_pos;
638 dstr[2 * n + 1] = r_mag * sinf(r_phase);668
639 669 for (int n = 0; n < rdft_size; n++) {
640 dstc[2 * n ] = c_mag * cosf(c_phase);670 float mag, ph;
641 dstc[2 * n + 1] = c_mag * sinf(c_phase);671
672 switch (ch) {
673 case 2:
674 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
675 ph = c_phase[n];
676 break;
677 case 0:
678 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
679 ph = l_phase[n];
680 break;
681 case 1:
682 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
683 ph = r_phase[n];
684 break;
685 case 3:
686 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
687 ph = l_phase[n];
688 break;
689 case 4:
690 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
691 ph = r_phase[n];
692 break;
693 }
642 694
643 dstls[2 * n ] = ls_mag * cosf(l_phase);695 TRANSFORM
644 dstls[2 * n + 1] = ls_mag * sinf(l_phase);696 }
645 697
646 dstrs[2 * n ] = rs_mag * cosf(r_phase);698 return 0;
647 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
648}699}
649 700
650static void upmix_5_1_back(AVFilterContext *ctx,701static int upmix_5_1_back(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
651 float l_phase,
652 float r_phase,
653 float c_phase,
654 float mag_total,
655 float x, float y,
656 int n)
657{702{
658 AudioSurroundContext *s = ctx->priv;703 AudioSurroundContext *s = ctx->priv;
659 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlfe;704 float *dst = (float *)s->output->extended_data[ch];
660 705 const float *mag_total = s->mag_total;
661 dstl = (float *)s->output->extended_data[0];706 const float *lfe_mag = s->lfe_mag;
662 dstr = (float *)s->output->extended_data[1];707 const int rdft_size = s->rdft_size;
663 dstc = (float *)s->output->extended_data[2];708 const float *l_phase = s->l_phase;
664 dstlfe = (float *)s->output->extended_data[3];709 const float *r_phase = s->r_phase;
665 dstls = (float *)s->output->extended_data[4];710 const float *c_phase = s->c_phase;
666 dstrs = (float *)s->output->extended_data[5];711 const float fl_x = s->fl_x;
667 712 const float fl_y = s->fl_y;
668 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);713 const float fr_x = s->fr_x;
669 714 const float fr_y = s->fr_y;
670 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;715 const float bl_x = s->bl_x;
671 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;716 const float bl_y = s->bl_y;
672 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;717 const float br_x = s->br_x;
673 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;718 const float br_y = s->br_y;
674 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;719 const float fc_x = s->fc_x;
675 720 const float fc_y = s->fc_y;
676 dstl[2 * n ] = l_mag * cosf(l_phase);721 const float *x = s->x_pos;
677 dstl[2 * n + 1] = l_mag * sinf(l_phase);722 const float *y = s->y_pos;
678 723 float mag, ph;
679 dstr[2 * n ] = r_mag * cosf(r_phase);724
680 dstr[2 * n + 1] = r_mag * sinf(r_phase);725 switch (ch) {
681 726 case 0:
682 dstc[2 * n ] = c_mag * cosf(c_phase);727 for (int n = 0; n < rdft_size; n++) {
683 dstc[2 * n + 1] = c_mag * sinf(c_phase);728 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
684 729 ph = l_phase[n];
685 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);730 TRANSFORM
686 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);731 }
687 732 break;
688 dstls[2 * n ] = ls_mag * cosf(l_phase);733 case 1:
689 dstls[2 * n + 1] = ls_mag * sinf(l_phase);734 for (int n = 0; n < rdft_size; n++) {
735 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
736 ph = r_phase[n];
737 TRANSFORM
738 }
739 break;
740 case 2:
741 for (int n = 0; n < rdft_size; n++) {
742 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
743 ph = c_phase[n];
744 TRANSFORM
745 }
746 break;
747 case 3:
748 for (int n = 0; n < rdft_size; n++) {
749 mag = lfe_mag[n];
750 ph = c_phase[n];
751 TRANSFORM
752 }
753 break;
754 case 4:
755 for (int n = 0; n < rdft_size; n++) {
756 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
757 ph = l_phase[n];
758 TRANSFORM
759 }
760 break;
761 case 5:
762 for (int n = 0; n < rdft_size; n++) {
763 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
764 ph = r_phase[n];
765 TRANSFORM
766 }
767 break;
768 }
690 769
691 dstrs[2 * n ] = rs_mag * cosf(r_phase);770 return 0;
692 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
693}771}
694 772
695static void upmix_6_0(AVFilterContext *ctx,773static int upmix_6_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
696 float l_phase,
697 float r_phase,
698 float c_phase,
699 float mag_total,
700 float x, float y,
701 int n)
702{774{
703 AudioSurroundContext *s = ctx->priv;775 AudioSurroundContext *s = ctx->priv;
704 float l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs;776 float *dst = (float *)s->output->extended_data[ch];
705 777 const float *mag_total = s->mag_total;
706 dstl = (float *)s->output->extended_data[0];778 const int rdft_size = s->rdft_size;
707 dstr = (float *)s->output->extended_data[1];779 const float *l_phase = s->l_phase;
708 dstc = (float *)s->output->extended_data[2];780 const float *r_phase = s->r_phase;
709 dstb = (float *)s->output->extended_data[3];781 const float *c_phase = s->c_phase;
710 dstls = (float *)s->output->extended_data[4];782 const float fl_x = s->fl_x;
711 dstrs = (float *)s->output->extended_data[5];783 const float fl_y = s->fl_y;
712 784 const float fr_x = s->fr_x;
713 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;785 const float fr_y = s->fr_y;
714 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;786 const float bl_x = s->bl_x;
715 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;787 const float bl_y = s->bl_y;
716 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;788 const float br_x = s->br_x;
717 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;789 const float br_y = s->br_y;
718 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;790 const float bc_x = s->bc_x;
719 791 const float bc_y = s->bc_y;
720 dstl[2 * n ] = l_mag * cosf(l_phase);792 const float fc_x = s->fc_x;
721 dstl[2 * n + 1] = l_mag * sinf(l_phase);793 const float fc_y = s->fc_y;
722 794 const float *x = s->x_pos;
723 dstr[2 * n ] = r_mag * cosf(r_phase);795 const float *y = s->y_pos;
724 dstr[2 * n + 1] = r_mag * sinf(r_phase);796 float mag, ph;
725 797
726 dstc[2 * n ] = c_mag * cosf(c_phase);798 switch (ch) {
727 dstc[2 * n + 1] = c_mag * sinf(c_phase);799 case 0:
728 800 for (int n = 0; n < rdft_size; n++) {
729 dstls[2 * n ] = ls_mag * cosf(l_phase);801 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
730 dstls[2 * n + 1] = ls_mag * sinf(l_phase);802 ph = l_phase[n];
731 803 TRANSFORM
732 dstrs[2 * n ] = rs_mag * cosf(r_phase);804 }
733 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);805 break;
806 case 1:
807 for (int n = 0; n < rdft_size; n++) {
808 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
809 ph = r_phase[n];
810 TRANSFORM
811 }
812 break;
813 case 2:
814 for (int n = 0; n < rdft_size; n++) {
815 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
816 ph = c_phase[n];
817 TRANSFORM
818 }
819 break;
820 case 3:
821 for (int n = 0; n < rdft_size; n++) {
822 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
823 ph = c_phase[n];
824 TRANSFORM
825 }
826 break;
827 case 4:
828 for (int n = 0; n < rdft_size; n++) {
829 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
830 ph = l_phase[n];
831 TRANSFORM
832 }
833 break;
834 case 5:
835 for (int n = 0; n < rdft_size; n++) {
836 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
837 ph = r_phase[n];
838 TRANSFORM
839 }
840 break;
841 }
734 842
735 dstb[2 * n ] = b_mag * cosf(c_phase);843 return 0;
736 dstb[2 * n + 1] = b_mag * sinf(c_phase);
737}844}
738 845
739static void upmix_6_1(AVFilterContext *ctx,846static int upmix_6_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
740 float l_phase,
741 float r_phase,
742 float c_phase,
743 float mag_total,
744 float x, float y,
745 int n)
746{847{
747 AudioSurroundContext *s = ctx->priv;848 AudioSurroundContext *s = ctx->priv;
748 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, b_mag, *dstc, *dstb, *dstl, *dstr, *dstls, *dstrs, *dstlfe;849 float *dst = (float *)s->output->extended_data[ch];
749 850 const float *mag_total = s->mag_total;
750 dstl = (float *)s->output->extended_data[0];851 const int rdft_size = s->rdft_size;
751 dstr = (float *)s->output->extended_data[1];852 const float *lfe_mag = s->lfe_mag;
752 dstc = (float *)s->output->extended_data[2];853 const float *l_phase = s->l_phase;
753 dstlfe = (float *)s->output->extended_data[3];854 const float *r_phase = s->r_phase;
754 dstb = (float *)s->output->extended_data[4];855 const float *c_phase = s->c_phase;
755 dstls = (float *)s->output->extended_data[5];856 const float fl_x = s->fl_x;
756 dstrs = (float *)s->output->extended_data[6];857 const float fl_y = s->fl_y;
757 858 const float fr_x = s->fr_x;
758 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);859 const float fr_y = s->fr_y;
759 860 const float bl_x = s->bl_x;
760 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;861 const float bl_y = s->bl_y;
761 b_mag = powf(1.f - fabsf(x), s->bc_x) * powf((1.f - y) * .5f, s->bc_y) * mag_total;862 const float br_x = s->br_x;
762 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;863 const float br_y = s->br_y;
763 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;864 const float bc_x = s->bc_x;
764 ls_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;865 const float bc_y = s->bc_y;
765 rs_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;866 const float fc_x = s->fc_x;
766 867 const float fc_y = s->fc_y;
767 dstl[2 * n ] = l_mag * cosf(l_phase);868 const float *x = s->x_pos;
768 dstl[2 * n + 1] = l_mag * sinf(l_phase);869 const float *y = s->y_pos;
769 870 float mag, ph;
770 dstr[2 * n ] = r_mag * cosf(r_phase);871
771 dstr[2 * n + 1] = r_mag * sinf(r_phase);872 switch (ch) {
772 873 case 0:
773 dstc[2 * n ] = c_mag * cosf(c_phase);874 for (int n = 0; n < rdft_size; n++) {
774 dstc[2 * n + 1] = c_mag * sinf(c_phase);875 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
775 876 ph = l_phase[n];
776 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);877 TRANSFORM
777 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);878 }
778 879 break;
779 dstls[2 * n ] = ls_mag * cosf(l_phase);880 case 1:
780 dstls[2 * n + 1] = ls_mag * sinf(l_phase);881 for (int n = 0; n < rdft_size; n++) {
781 882 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
782 dstrs[2 * n ] = rs_mag * cosf(r_phase);883 ph = r_phase[n];
783 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);884 TRANSFORM
885 }
886 break;
887 case 2:
888 for (int n = 0; n < rdft_size; n++) {
889 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
890 ph = c_phase[n];
891 TRANSFORM
892 }
893 break;
894 case 3:
895 for (int n = 0; n < rdft_size; n++) {
896 mag = lfe_mag[n];
897 ph = c_phase[n];
898 TRANSFORM
899 }
900 break;
901 case 4:
902 for (int n = 0; n < rdft_size; n++) {
903 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
904 ph = c_phase[n];
905 TRANSFORM
906 }
907 break;
908 case 5:
909 for (int n = 0; n < rdft_size; n++) {
910 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
911 ph = l_phase[n];
912 TRANSFORM
913 }
914 break;
915 case 6:
916 for (int n = 0; n < rdft_size; n++) {
917 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
918 ph = r_phase[n];
919 TRANSFORM
920 }
921 break;
922 }
784 923
785 dstb[2 * n ] = b_mag * cosf(c_phase);924 return 0;
786 dstb[2 * n + 1] = b_mag * sinf(c_phase);
787}925}
788 926
789static void upmix_5_1_back_surround(AVFilterContext *ctx,927static void upmix_5_1_back_surround(AVFilterContext *ctx,
@@ -878,110 +1016,176 @@ static void upmix_5_1_back_2_1(AVFilterContext *ctx, · 88 unmodified lines
878 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);1016 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
879}1017}
880 1018
881static void upmix_7_0(AVFilterContext *ctx,1019static int upmix_7_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
882 float l_phase,
883 float r_phase,
884 float c_phase,
885 float mag_total,
886 float x, float y,
887 int n)
888{1020{
889 float l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
890 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb;
891 AudioSurroundContext *s = ctx->priv;1021 AudioSurroundContext *s = ctx->priv;
1022 float *dst = (float *)s->output->extended_data[ch];
1023 const float *mag_total = s->mag_total;
1024 const int rdft_size = s->rdft_size;
1025 const float *l_phase = s->l_phase;
1026 const float *r_phase = s->r_phase;
1027 const float *c_phase = s->c_phase;
1028 const float fl_x = s->fl_x;
1029 const float fl_y = s->fl_y;
1030 const float fr_x = s->fr_x;
1031 const float fr_y = s->fr_y;
1032 const float fc_x = s->fc_x;
1033 const float fc_y = s->fc_y;
1034 const float bl_x = s->bl_x;
1035 const float bl_y = s->bl_y;
1036 const float br_x = s->br_x;
1037 const float br_y = s->br_y;
1038 const float sl_x = s->sl_x;
1039 const float sl_y = s->sl_y;
1040 const float sr_x = s->sr_x;
1041 const float sr_y = s->sr_y;
1042 const float *x = s->x_pos;
1043 const float *y = s->y_pos;
1044 float mag, ph;
1045
1046 switch (ch) {
1047 case 0:
1048 for (int n = 0; n < rdft_size; n++) {
1049 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
1050 ph = l_phase[n];
1051 TRANSFORM
1052 }
1053 break;
1054 case 1:
1055 for (int n = 0; n < rdft_size; n++) {
1056 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
1057 ph = r_phase[n];
1058 TRANSFORM
1059 }
1060 break;
1061 case 2:
1062 for (int n = 0; n < rdft_size; n++) {
1063 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
1064 ph = c_phase[n];
1065 TRANSFORM
1066 }
1067 break;
1068 case 3:
1069 for (int n = 0; n < rdft_size; n++) {
1070 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
1071 ph = l_phase[n];
1072 TRANSFORM
1073 }
1074 break;
1075 case 4:
1076 for (int n = 0; n < rdft_size; n++) {
1077 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
1078 ph = r_phase[n];
1079 TRANSFORM
1080 }
1081 break;
1082 case 5:
1083 for (int n = 0; n < rdft_size; n++) {
1084 mag = powf(.5f * ( x[n] + 1.f), sl_x) * powf(1.f - fabsf(y[n]), sl_y) * mag_total[n];
1085 ph = l_phase[n];
1086 TRANSFORM
1087 }
1088 break;
1089 case 6:
1090 for (int n = 0; n < rdft_size; n++) {
1091 mag = powf(.5f * (-x[n] + 1.f), sr_x) * powf(1.f - fabsf(y[n]), sr_y) * mag_total[n];
1092 ph = r_phase[n];
1093 TRANSFORM
1094 }
1095 break;
1096 }
892 1097
893 dstl = (float *)s->output->extended_data[0];1098 return 0;
894 dstr = (float *)s->output->extended_data[1];
895 dstc = (float *)s->output->extended_data[2];
896 dstlb = (float *)s->output->extended_data[3];
897 dstrb = (float *)s->output->extended_data[4];
898 dstls = (float *)s->output->extended_data[5];
899 dstrs = (float *)s->output->extended_data[6];
900
901 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
902 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
903 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
904 lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
905 rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
906 ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
907 rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
908
909 dstl[2 * n ] = l_mag * cosf(l_phase);
910 dstl[2 * n + 1] = l_mag * sinf(l_phase);
911
912 dstr[2 * n ] = r_mag * cosf(r_phase);
913 dstr[2 * n + 1] = r_mag * sinf(r_phase);
914
915 dstc[2 * n ] = c_mag * cosf(c_phase);
916 dstc[2 * n + 1] = c_mag * sinf(c_phase);
917
918 dstlb[2 * n ] = lb_mag * cosf(l_phase);
919 dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
920
921 dstrb[2 * n ] = rb_mag * cosf(r_phase);
922 dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
923
924 dstls[2 * n ] = ls_mag * cosf(l_phase);
925 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
926
927 dstrs[2 * n ] = rs_mag * cosf(r_phase);
928 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
929}1099}
930 1100
931static void upmix_7_1(AVFilterContext *ctx,1101static int upmix_7_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
932 float l_phase,
933 float r_phase,
934 float c_phase,
935 float mag_total,
936 float x, float y,
937 int n)
938{1102{
939 float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
940 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
941 AudioSurroundContext *s = ctx->priv;1103 AudioSurroundContext *s = ctx->priv;
1104 float *dst = (float *)s->output->extended_data[ch];
1105 const float *mag_total = s->mag_total;
1106 const int rdft_size = s->rdft_size;
1107 const float *lfe_mag = s->lfe_mag;
1108 const float *l_phase = s->l_phase;
1109 const float *r_phase = s->r_phase;
1110 const float *c_phase = s->c_phase;
1111 const float fl_x = s->fl_x;
1112 const float fl_y = s->fl_y;
1113 const float fr_x = s->fr_x;
1114 const float fr_y = s->fr_y;
1115 const float fc_x = s->fc_x;
1116 const float fc_y = s->fc_y;
1117 const float bl_x = s->bl_x;
1118 const float bl_y = s->bl_y;
1119 const float br_x = s->br_x;
1120 const float br_y = s->br_y;
1121 const float sl_x = s->sl_x;
1122 const float sl_y = s->sl_y;
1123 const float sr_x = s->sr_x;
1124 const float sr_y = s->sr_y;
1125 const float *x = s->x_pos;
1126 const float *y = s->y_pos;
1127 float mag, ph;
1128
1129 switch (ch) {
1130 case 0:
1131 for (int n = 0; n < rdft_size; n++) {
1132 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
1133 ph = l_phase[n];
1134 TRANSFORM
1135 }
1136 break;
1137 case 1:
1138 for (int n = 0; n < rdft_size; n++) {
1139 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
1140 ph = r_phase[n];
1141 TRANSFORM
1142 }
1143 break;
1144 case 2:
1145 for (int n = 0; n < rdft_size; n++) {
1146 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
1147 ph = c_phase[n];
1148 TRANSFORM
1149 }
1150 break;
1151 case 3:
1152 for (int n = 0; n < rdft_size; n++) {
1153 mag = lfe_mag[n];
1154 ph = c_phase[n];
1155 TRANSFORM
1156 }
1157 break;
1158 case 4:
1159 for (int n = 0; n < rdft_size; n++) {
1160 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
1161 ph = l_phase[n];
1162 TRANSFORM
1163 }
1164 break;
1165 case 5:
1166 for (int n = 0; n < rdft_size; n++) {
1167 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
1168 ph = r_phase[n];
1169 TRANSFORM
1170 }
1171 break;
1172 case 6:
1173 for (int n = 0; n < rdft_size; n++) {
1174 mag = powf(.5f * ( x[n] + 1.f), sl_x) * powf(1.f - fabsf(y[n]), sl_y) * mag_total[n];
1175 ph = l_phase[n];
1176 TRANSFORM
1177 }
1178 break;
1179 case 7:
1180 for (int n = 0; n < rdft_size; n++) {
1181 mag = powf(.5f * (-x[n] + 1.f), sr_x) * powf(1.f - fabsf(y[n]), sr_y) * mag_total[n];
1182 ph = r_phase[n];
1183 TRANSFORM
1184 }
1185 break;
1186 }
942 1187
943 dstl = (float *)s->output->extended_data[0];1188 return 0;
944 dstr = (float *)s->output->extended_data[1];
945 dstc = (float *)s->output->extended_data[2];
946 dstlfe = (float *)s->output->extended_data[3];
947 dstlb = (float *)s->output->extended_data[4];
948 dstrb = (float *)s->output->extended_data[5];
949 dstls = (float *)s->output->extended_data[6];
950 dstrs = (float *)s->output->extended_data[7];
951
952 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total, s->lfe_mode);
953
954 c_mag = powf(1.f - fabsf(x), s->fc_x) * powf((y + 1.f) * .5f, s->fc_y) * mag_total;
955 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
956 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
957 lb_mag = powf(.5f * ( x + 1.f), s->bl_x) * powf(1.f - ((y + 1.f) * .5f), s->bl_y) * mag_total;
958 rb_mag = powf(.5f * (-x + 1.f), s->br_x) * powf(1.f - ((y + 1.f) * .5f), s->br_y) * mag_total;
959 ls_mag = powf(.5f * ( x + 1.f), s->sl_x) * powf(1.f - fabsf(y), s->sl_y) * mag_total;
960 rs_mag = powf(.5f * (-x + 1.f), s->sr_x) * powf(1.f - fabsf(y), s->sr_y) * mag_total;
961
962 dstl[2 * n ] = l_mag * cosf(l_phase);
963 dstl[2 * n + 1] = l_mag * sinf(l_phase);
964
965 dstr[2 * n ] = r_mag * cosf(r_phase);
966 dstr[2 * n + 1] = r_mag * sinf(r_phase);
967
968 dstc[2 * n ] = c_mag * cosf(c_phase);
969 dstc[2 * n + 1] = c_mag * sinf(c_phase);
970
971 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
972 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
973
974 dstlb[2 * n ] = lb_mag * cosf(l_phase);
975 dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
976
977 dstrb[2 * n ] = rb_mag * cosf(r_phase);
978 dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
979
980 dstls[2 * n ] = ls_mag * cosf(l_phase);
981 dstls[2 * n + 1] = ls_mag * sinf(l_phase);
982
983 dstrs[2 * n ] = rs_mag * cosf(r_phase);
984 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
985}1189}
986 1190
987static void upmix_7_1_5_0_side(AVFilterContext *ctx,1191static void upmix_7_1_5_0_side(AVFilterContext *ctx,
@@ -1100,16 +1304,116 @@ static void upmix_7_1_5_1(AVFilterContext *ctx, · 112 unmodified lines
1100 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);1304 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1101}1305}
1102 1306
1103static void filter_stereo(AVFilterContext *ctx)1307static int upmix_8_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1104{1308{
1105 AudioSurroundContext *s = ctx->priv;1309 AudioSurroundContext *s = ctx->priv;
1106 float *srcl, *srcr;1310 float *dst = (float *)s->output->extended_data[ch];
1107 int n;1311 const float *mag_total = s->mag_total;
1312 const int rdft_size = s->rdft_size;
1313 const float *l_phase = s->l_phase;
1314 const float *r_phase = s->r_phase;
1315 const float *c_phase = s->c_phase;
1316 const float fl_x = s->fl_x;
1317 const float fl_y = s->fl_y;
1318 const float fr_x = s->fr_x;
1319 const float fr_y = s->fr_y;
1320 const float fc_x = s->fc_x;
1321 const float fc_y = s->fc_y;
1322 const float bl_x = s->bl_x;
1323 const float bl_y = s->bl_y;
1324 const float br_x = s->br_x;
1325 const float br_y = s->br_y;
1326 const float sl_x = s->sl_x;
1327 const float sl_y = s->sl_y;
1328 const float sr_x = s->sr_x;
1329 const float sr_y = s->sr_y;
1330 const float bc_x = s->bc_x;
1331 const float bc_y = s->bc_y;
1332 const float *x = s->x_pos;
1333 const float *y = s->y_pos;
1334 float mag, ph;
1335
1336 switch (ch) {
1337 case 0:
1338 for (int n = 0; n < rdft_size; n++) {
1339 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
1340 ph = l_phase[n];
1341 TRANSFORM
1342 }
1343 break;
1344 case 1:
1345 for (int n = 0; n < rdft_size; n++) {
1346 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
1347 ph = r_phase[n];
1348 TRANSFORM
1349 }
1350 break;
1351 case 2:
1352 for (int n = 0; n < rdft_size; n++) {
1353 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
1354 ph = c_phase[n];
1355 TRANSFORM
1356 }
1357 break;
1358 case 3:
1359 for (int n = 0; n < rdft_size; n++) {
1360 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
1361 ph = l_phase[n];
1362 TRANSFORM
1363 }
1364 break;
1365 case 4:
1366 for (int n = 0; n < rdft_size; n++) {
1367 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
1368 ph = r_phase[n];
1369 TRANSFORM
1370 }
1371 break;
1372 case 5:
1373 for (int n = 0; n < rdft_size; n++) {
1374 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
1375 ph = l_phase[n];
1376 TRANSFORM
1377 }
1378 break;
1379 case 6:
1380 for (int n = 0; n < rdft_size; n++) {
1381 mag = powf(.5f * ( x[n] + 1.f), sl_x) * powf(1.f - fabsf(y[n]), sl_y) * mag_total[n];
1382 ph = l_phase[n];
1383 TRANSFORM
1384 }
1385 break;
1386 case 7:
1387 for (int n = 0; n < rdft_size; n++) {
1388 mag = powf(.5f * (-x[n] + 1.f), sr_x) * powf(1.f - fabsf(y[n]), sr_y) * mag_total[n];
1389 ph = r_phase[n];
1390 TRANSFORM
1391 }
1392 break;
1393 }
1108 1394
1109 srcl = (float *)s->input->extended_data[0];1395 return 0;
1110 srcr = (float *)s->input->extended_data[1];1396}
1111 1397
1112 for (n = 0; n < s->buf_size / 2 + 1; n++) {1398static void filter_stereo(AVFilterContext *ctx)
1399{
1400 AudioSurroundContext *s = ctx->priv;
1401 const float *srcl = (const float *)s->input->extended_data[0];
1402 const float *srcr = (const float *)s->input->extended_data[1];
1403 const int output_lfe = s->output_lfe && s->have_lfe;
1404 const int lfe_mode = s->lfe_mode;
1405 const float highcut = s->highcut;
1406 const float lowcut = s->lowcut;
1407 const float angle = s->angle;
1408 float *magtotal = s->mag_total;
1409 float *lfemag = s->lfe_mag;
1410 float *lphase = s->l_phase;
1411 float *rphase = s->r_phase;
1412 float *cphase = s->c_phase;
1413 float *xpos = s->x_pos;
1414 float *ypos = s->y_pos;
1415
1416 for (int n = 0; n < s->rdft_size; n++) {
1113 float l_re = srcl[2 * n], r_re = srcr[2 * n];1417 float l_re = srcl[2 * n], r_re = srcr[2 * n];
1114 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];1418 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1115 float c_phase = atan2f(l_im + r_im, l_re + r_re);1419 float c_phase = atan2f(l_im + r_im, l_re + r_re);
@@ -1127,9 +1431,15 @@ static void filter_stereo(AVFilterContext *ctx) · 11 unmodified lines
1127 phase_dif = 2 * M_PI - phase_dif;1431 phase_dif = 2 * M_PI - phase_dif;
1128 1432
1129 stereo_position(mag_dif, phase_dif, &x, &y);1433 stereo_position(mag_dif, phase_dif, &x, &y);
1130 stereo_transform(&x, &y, s->angle);1434 stereo_transform(&x, &y, angle);
1131 1435 get_lfe(output_lfe, n, lowcut, highcut, &lfemag[n], &mag_total, lfe_mode);
1132 s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);1436
1437 xpos[n] = x;
1438 ypos[n] = y;
1439 lphase[n] = l_phase;
1440 rphase[n] = r_phase;
1441 cphase[n] = c_phase;
1442 magtotal[n] = mag_total;
1133 }1443 }
1134}1444}
1135 1445
@@ -1143,7 +1453,7 @@ static void filter_surround(AVFilterContext *ctx) · 7 unmodified lines
1143 srcr = (float *)s->input->extended_data[1];1453 srcr = (float *)s->input->extended_data[1];
1144 srcc = (float *)s->input->extended_data[2];1454 srcc = (float *)s->input->extended_data[2];
1145 1455
1146 for (n = 0; n < s->buf_size / 2 + 1; n++) {1456 for (n = 0; n < s->rdft_size; n++) {
1147 float l_re = srcl[2 * n], r_re = srcr[2 * n];1457 float l_re = srcl[2 * n], r_re = srcr[2 * n];
1148 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];1458 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1149 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];1459 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1179,7 +1489,7 @@ static void filter_2_1(AVFilterContext *ctx) · 29 unmodified lines
1179 srcr = (float *)s->input->extended_data[1];1489 srcr = (float *)s->input->extended_data[1];
1180 srclfe = (float *)s->input->extended_data[2];1490 srclfe = (float *)s->input->extended_data[2];
1181 1491
1182 for (n = 0; n < s->buf_size / 2 + 1; n++) {1492 for (n = 0; n < s->rdft_size; n++) {
1183 float l_re = srcl[2 * n], r_re = srcr[2 * n];1493 float l_re = srcl[2 * n], r_re = srcr[2 * n];
1184 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];1494 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
1185 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];1495 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
@@ -1216,7 +1526,7 @@ static void filter_5_0_side(AVFilterContext *ctx) · 30 unmodified lines
1216 srcsl = (float *)s->input->extended_data[3];1526 srcsl = (float *)s->input->extended_data[3];
1217 srcsr = (float *)s->input->extended_data[4];1527 srcsr = (float *)s->input->extended_data[4];
1218 1528
1219 for (n = 0; n < s->buf_size / 2 + 1; n++) {1529 for (n = 0; n < s->rdft_size; n++) {
1220 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];1530 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1221 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];1531 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1222 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];1532 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1274,7 +1584,7 @@ static void filter_5_1_side(AVFilterContext *ctx) · 51 unmodified lines
1274 srcsl = (float *)s->input->extended_data[4];1584 srcsl = (float *)s->input->extended_data[4];
1275 srcsr = (float *)s->input->extended_data[5];1585 srcsr = (float *)s->input->extended_data[5];
1276 1586
1277 for (n = 0; n < s->buf_size / 2 + 1; n++) {1587 for (n = 0; n < s->rdft_size; n++) {
1278 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];1588 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1279 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];1589 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1280 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];1590 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1333,7 +1643,7 @@ static void filter_5_1_back(AVFilterContext *ctx) · 52 unmodified lines
1333 srcbl = (float *)s->input->extended_data[4];1643 srcbl = (float *)s->input->extended_data[4];
1334 srcbr = (float *)s->input->extended_data[5];1644 srcbr = (float *)s->input->extended_data[5];
1335 1645
1336 for (n = 0; n < s->buf_size / 2 + 1; n++) {1646 for (n = 0; n < s->rdft_size; n++) {
1337 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];1647 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1338 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];1648 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1339 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];1649 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1409,48 +1719,59 @@ static av_cold int init(AVFilterContext *ctx) · 69 unmodified lines
1409 out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?1719 out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1410 s->out_channel_layout.u.mask : 0;1720 s->out_channel_layout.u.mask : 0;
1411 1721
1722 s->have_lfe = 0;
1723
1412 switch (in_channel_layout) {1724 switch (in_channel_layout) {
1413 case AV_CH_LAYOUT_STEREO:1725 case AV_CH_LAYOUT_STEREO:
1414 s->filter = filter_stereo;1726 s->filter = filter_stereo;
1415 switch (out_channel_layout) {1727 switch (out_channel_layout) {
1416 case AV_CH_LAYOUT_MONO:1728 case AV_CH_LAYOUT_MONO:
1417 s->upmix_stereo = upmix_1_0;1729 s->upmix = upmix_1_0;
1418 break;1730 break;
1419 case AV_CH_LAYOUT_STEREO:1731 case AV_CH_LAYOUT_STEREO:
1420 s->upmix_stereo = upmix_stereo;1732 s->upmix = upmix_stereo;
1421 break;1733 break;
1422 case AV_CH_LAYOUT_2POINT1:1734 case AV_CH_LAYOUT_2POINT1:
1423 s->upmix_stereo = upmix_2_1;1735 s->upmix = upmix_2_1;
1736 s->have_lfe = 1;
1424 break;1737 break;
1425 case AV_CH_LAYOUT_SURROUND:1738 case AV_CH_LAYOUT_SURROUND:
1426 s->upmix_stereo = upmix_3_0;1739 s->upmix = upmix_3_0;
1427 break;1740 break;
1428 case AV_CH_LAYOUT_3POINT1:1741 case AV_CH_LAYOUT_3POINT1:
1429 s->upmix_stereo = upmix_3_1;1742 s->upmix = upmix_3_1;
1743 s->have_lfe = 1;
1430 break;1744 break;
1431 case AV_CH_LAYOUT_4POINT0:1745 case AV_CH_LAYOUT_4POINT0:
1432 s->upmix_stereo = upmix_4_0;1746 s->upmix = upmix_4_0;
1433 break;1747 break;
1434 case AV_CH_LAYOUT_4POINT1:1748 case AV_CH_LAYOUT_4POINT1:
1435 s->upmix_stereo = upmix_4_1;1749 s->upmix = upmix_4_1;
1750 s->have_lfe = 1;
1436 break;1751 break;
1437 case AV_CH_LAYOUT_5POINT0_BACK:1752 case AV_CH_LAYOUT_5POINT0_BACK:
1438 s->upmix_stereo = upmix_5_0_back;1753 s->upmix = upmix_5_0_back;
1439 break;1754 break;
1440 case AV_CH_LAYOUT_5POINT1_BACK:1755 case AV_CH_LAYOUT_5POINT1_BACK:
1441 s->upmix_stereo = upmix_5_1_back;1756 s->upmix = upmix_5_1_back;
1757 s->have_lfe = 1;
1442 break;1758 break;
1443 case AV_CH_LAYOUT_6POINT0:1759 case AV_CH_LAYOUT_6POINT0:
1444 s->upmix_stereo = upmix_6_0;1760 s->upmix = upmix_6_0;
1445 break;1761 break;
1446 case AV_CH_LAYOUT_6POINT1:1762 case AV_CH_LAYOUT_6POINT1:
1447 s->upmix_stereo = upmix_6_1;1763 s->upmix = upmix_6_1;
1764 s->have_lfe = 1;
1448 break;1765 break;
1449 case AV_CH_LAYOUT_7POINT0:1766 case AV_CH_LAYOUT_7POINT0:
1450 s->upmix_stereo = upmix_7_0;1767 s->upmix = upmix_7_0;
1451 break;1768 break;
1452 case AV_CH_LAYOUT_7POINT1:1769 case AV_CH_LAYOUT_7POINT1:
1453 s->upmix_stereo = upmix_7_1;1770 s->upmix = upmix_7_1;
1771 s->have_lfe = 1;
1772 break;
1773 case AV_CH_LAYOUT_OCTAGONAL:
1774 s->upmix = upmix_8_0;
1454 break;1775 break;
1455 default:1776 default:
1456 goto fail;1777 goto fail;
@@ -1461,6 +1782,7 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1461 switch (out_channel_layout) {1782 switch (out_channel_layout) {
1462 case AV_CH_LAYOUT_5POINT1_BACK:1783 case AV_CH_LAYOUT_5POINT1_BACK:
1463 s->upmix_2_1 = upmix_5_1_back_2_1;1784 s->upmix_2_1 = upmix_5_1_back_2_1;
1785 s->have_lfe = 1;
1464 break;1786 break;
1465 default:1787 default:
1466 goto fail;1788 goto fail;
@@ -1471,9 +1793,11 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1471 switch (out_channel_layout) {1793 switch (out_channel_layout) {
1472 case AV_CH_LAYOUT_3POINT1:1794 case AV_CH_LAYOUT_3POINT1:
1473 s->upmix_3_0 = upmix_3_1_surround;1795 s->upmix_3_0 = upmix_3_1_surround;
1796 s->have_lfe = 1;
1474 break;1797 break;
1475 case AV_CH_LAYOUT_5POINT1_BACK:1798 case AV_CH_LAYOUT_5POINT1_BACK:
1476 s->upmix_3_0 = upmix_5_1_back_surround;1799 s->upmix_3_0 = upmix_5_1_back_surround;
1800 s->have_lfe = 1;
1477 break;1801 break;
1478 default:1802 default:
1479 goto fail;1803 goto fail;
@@ -1484,6 +1808,7 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1484 switch (out_channel_layout) {1808 switch (out_channel_layout) {
1485 case AV_CH_LAYOUT_7POINT1:1809 case AV_CH_LAYOUT_7POINT1:
1486 s->upmix_5_0 = upmix_7_1_5_0_side;1810 s->upmix_5_0 = upmix_7_1_5_0_side;
1811 s->have_lfe = 1;
1487 break;1812 break;
1488 default:1813 default:
1489 goto fail;1814 goto fail;
@@ -1494,6 +1819,7 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1494 switch (out_channel_layout) {1819 switch (out_channel_layout) {
1495 case AV_CH_LAYOUT_7POINT1:1820 case AV_CH_LAYOUT_7POINT1:
1496 s->upmix_5_1 = upmix_7_1_5_1;1821 s->upmix_5_1 = upmix_7_1_5_1;
1822 s->have_lfe = 1;
1497 break;1823 break;
1498 default:1824 default:
1499 goto fail;1825 goto fail;
@@ -1504,6 +1830,7 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1504 switch (out_channel_layout) {1830 switch (out_channel_layout) {
1505 case AV_CH_LAYOUT_7POINT1:1831 case AV_CH_LAYOUT_7POINT1:
1506 s->upmix_5_1 = upmix_7_1_5_1;1832 s->upmix_5_1 = upmix_7_1_5_1;
1833 s->have_lfe = 1;
1507 break;1834 break;
1508 default:1835 default:
1509 goto fail;1836 goto fail;
@@ -1540,35 +1867,43 @@ fail: · 30 unmodified lines
1540 return 0;1867 return 0;
1541}1868}
1542 1869
1543static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)1870static int fft_channel(AVFilterContext *ctx, AVFrame *in, int ch)
1544{1871{
1545 AudioSurroundContext *s = ctx->priv;1872 AudioSurroundContext *s = ctx->priv;
1546 float *src = (float *)s->input_in->extended_data[ch];1873 float *src = (float *)s->input_in->extended_data[ch];
1547 float *win = (float *)s->window->extended_data[ch];1874 float *win = (float *)s->window->extended_data[ch];
1548 const int offset = s->buf_size - s->hop_size;1875 const int offset = s->buf_size - s->hop_size;
1549 const float level_in = s->input_levels[ch];1876 const float level_in = s->input_levels[ch];
1550 AVFrame *in = arg;
1551 1877
1552 memmove(src, &src[s->hop_size], offset * sizeof(float));1878 memmove(src, &src[s->hop_size], offset * sizeof(float));
1553 memcpy(&src[offset], in->extended_data[ch], in->nb_samples * sizeof(float));1879 memcpy(&src[offset], in->extended_data[ch], in->nb_samples * sizeof(float));
1554 memset(&src[offset + in->nb_samples], 0, (s->hop_size - in->nb_samples) * sizeof(float));1880 memset(&src[offset + in->nb_samples], 0, (s->hop_size - in->nb_samples) * sizeof(float));
1555 1881
1556 for (int n = 0; n < s->buf_size; n++) {1882 for (int n = 0; n < s->buf_size; n++)
1557 win[n] = src[n] * s->window_func_lut[n] * level_in;1883 win[n] = src[n] * s->window_func_lut[n] * level_in;
1558 }
1559 1884
1560 s->tx_fn(s->rdft[ch], (float *)s->input->extended_data[ch], win, sizeof(float));1885 s->tx_fn(s->rdft[ch], (float *)s->input->extended_data[ch], win, sizeof(float));
1561 1886
1562 return 0;1887 return 0;
1563}1888}
1564 1889
1565static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)1890static int fft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1891{
1892 AVFrame *in = arg;
1893 const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
1894 const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
1895
1896 for (int ch = start; ch < end; ch++)
1897 fft_channel(ctx, in, ch);
1898
1899 return 0;
1900}
1901
1902static int ifft_channel(AVFilterContext *ctx, AVFrame *out, int ch)
1566{1903{
1567 AudioSurroundContext *s = ctx->priv;1904 AudioSurroundContext *s = ctx->priv;
1568 const float level_out = s->output_levels[ch];1905 const float level_out = s->output_levels[ch];
1569 AVFrame *out = arg;
1570 float *dst, *ptr;1906 float *dst, *ptr;
1571 int n;
1572 1907
1573 dst = (float *)s->output_out->extended_data[ch];1908 dst = (float *)s->output_out->extended_data[ch];
1574 ptr = (float *)s->overlap_buffer->extended_data[ch];1909 ptr = (float *)s->overlap_buffer->extended_data[ch];
@@ -1580,9 +1915,8 @@ static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 5 unmodified lines
1580 memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),1915 memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),
1581 0, s->hop_size * sizeof(float));1916 0, s->hop_size * sizeof(float));
1582 1917
1583 for (n = 0; n < s->buf_size; n++) {1918 for (int n = 0; n < s->buf_size; n++)
1584 ptr[n] += dst[n] * s->window_func_lut[n] * level_out;1919 ptr[n] += dst[n] * s->window_func_lut[n] * level_out;
1585 }
1586 1920
1587 ptr = (float *)s->overlap_buffer->extended_data[ch];1921 ptr = (float *)s->overlap_buffer->extended_data[ch];
1588 dst = (float *)out->extended_data[ch];1922 dst = (float *)out->extended_data[ch];
@@ -1591,6 +1925,18 @@ static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 2 unmodified lines
1591 return 0;1925 return 0;
1592}1926}
1593 1927
1928static int ifft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1929{
1930 AVFrame *out = arg;
1931 const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
1932 const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
1933
1934 for (int ch = start; ch < end; ch++)
1935 ifft_channel(ctx, out, ch);
1936
1937 return 0;
1938}
1939
1594static int filter_frame(AVFilterLink *inlink, AVFrame *in)1940static int filter_frame(AVFilterLink *inlink, AVFrame *in)
1595{1941{
1596 AVFilterContext *ctx = inlink->dst;1942 AVFilterContext *ctx = inlink->dst;
@@ -1598,15 +1944,20 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 1 unmodified line
1598 AudioSurroundContext *s = ctx->priv;1944 AudioSurroundContext *s = ctx->priv;
1599 AVFrame *out;1945 AVFrame *out;
1600 1946
1601 ff_filter_execute(ctx, fft_channel, in, NULL, inlink->ch_layout.nb_channels);1947 ff_filter_execute(ctx, fft_channels, in, NULL,
1948 FFMIN(inlink->ch_layout.nb_channels,
1949 ff_filter_get_nb_threads(ctx)));
1602 1950
1603 s->filter(ctx);1951 s->filter(ctx);
1952 ff_filter_execute(ctx, s->upmix, NULL, NULL, outlink->ch_layout.nb_channels);
1604 1953
1605 out = ff_get_audio_buffer(outlink, s->hop_size);1954 out = ff_get_audio_buffer(outlink, s->hop_size);
1606 if (!out)1955 if (!out)
1607 return AVERROR(ENOMEM);1956 return AVERROR(ENOMEM);
1608 1957
1609 ff_filter_execute(ctx, ifft_channel, out, NULL, outlink->ch_layout.nb_channels);1958 ff_filter_execute(ctx, ifft_channels, out, NULL,
1959 FFMIN(outlink->ch_layout.nb_channels,
1960 ff_filter_get_nb_threads(ctx)));
1610 1961
1611 out->pts = in->pts;1962 out->pts = in->pts;
1612 out->nb_samples = in->nb_samples;1963 out->nb_samples = in->nb_samples;
@@ -1670,6 +2021,14 @@ static av_cold void uninit(AVFilterContext *ctx) · 57 unmodified lines
1670 av_freep(&s->rdft);2021 av_freep(&s->rdft);
1671 av_freep(&s->irdft);2022 av_freep(&s->irdft);
1672 av_freep(&s->window_func_lut);2023 av_freep(&s->window_func_lut);
2024
2025 av_freep(&s->x_pos);
2026 av_freep(&s->y_pos);
2027 av_freep(&s->l_phase);
2028 av_freep(&s->r_phase);
2029 av_freep(&s->c_phase);
2030 av_freep(&s->mag_total);
2031 av_freep(&s->lfe_mag);
1673}2032}
1674 2033
1675#define OFFSET(x) offsetof(AudioSurroundContext, x)2034#define OFFSET(x) offsetof(AudioSurroundContext, x)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t