History

avfilter/af_surround: refactor some code

Paul B Mahol committed 3 years ago

Commit d7704031 parent 822da7a1 file · +114 −802Browse files

Unified · Split

libavfilter/af_surround.c+114−802
@@ -275,14 +275,14 @@ static int config_input(AVFilterLink *inlink) · 274 unmodified lines
275{275{
276 AVFilterContext *ctx = inlink->dst;276 AVFilterContext *ctx = inlink->dst;
277 AudioSurroundContext *s = ctx->priv;277 AudioSurroundContext *s = ctx->priv;
278 int ch, ret;278 int ret;
279 279
280 s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft));280 s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft));
281 if (!s->rdft)281 if (!s->rdft)
282 return AVERROR(ENOMEM);282 return AVERROR(ENOMEM);
283 s->nb_in_channels = inlink->ch_layout.nb_channels;283 s->nb_in_channels = inlink->ch_layout.nb_channels;
284 284
285 for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {285 for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
286 float scale = 1.f;286 float scale = 1.f;
287 287
288 ret = av_tx_init(&s->rdft[ch], &s->tx_fn, AV_TX_FLOAT_RDFT,288 ret = av_tx_init(&s->rdft[ch], &s->tx_fn, AV_TX_FLOAT_RDFT,
@@ -318,14 +318,14 @@ static int config_output(AVFilterLink *outlink) · 29 unmodified lines
318{318{
319 AVFilterContext *ctx = outlink->src;319 AVFilterContext *ctx = outlink->src;
320 AudioSurroundContext *s = ctx->priv;320 AudioSurroundContext *s = ctx->priv;
321 int ch, ret;321 int ret;
322 322
323 s->irdft = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->irdft));323 s->irdft = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->irdft));
324 if (!s->irdft)324 if (!s->irdft)
325 return AVERROR(ENOMEM);325 return AVERROR(ENOMEM);
326 s->nb_out_channels = outlink->ch_layout.nb_channels;326 s->nb_out_channels = outlink->ch_layout.nb_channels;
327 327
328 for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {328 for (int ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
329 float iscale = 1.f;329 float iscale = 1.f;
330 330
331 ret = av_tx_init(&s->irdft[ch], &s->itx_fn, AV_TX_FLOAT_RDFT,331 ret = av_tx_init(&s->irdft[ch], &s->itx_fn, AV_TX_FLOAT_RDFT,
@@ -372,6 +372,8 @@ static float r_distance(float a) · 40 unmodified lines
372 return fminf(sqrtf(1.f + sqrf(tanf(a))), sqrtf(1.f + sqrf(1.f / tanf(a))));372 return fminf(sqrtf(1.f + sqrf(tanf(a))), sqrtf(1.f + sqrf(1.f / tanf(a))));
373}373}
374 374
375#define MIN_MAG_SUM 0.00000001f
376
375static void angle_transform(float *x, float *y, float angle)377static void angle_transform(float *x, float *y, float angle)
376{378{
377 float reference, r, a;379 float reference, r, a;
@@ -437,544 +439,150 @@ static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut, · 59 unmodified lines
437 dst[2 * n ] = mag * cosf(ph); \439 dst[2 * n ] = mag * cosf(ph); \
438 dst[2 * n + 1] = mag * sinf(ph);440 dst[2 * n + 1] = mag * sinf(ph);
439 441
440static int upmix_1_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)442static int stereo_upmix(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
441{
442 AudioSurroundContext *s = ctx->priv;
443 float *dst = (float *)s->output->extended_data[0];
444 const float *mag_total = s->mag_total;
445 const int rdft_size = s->rdft_size;
446 const float *phase = s->c_phase;
447 const float *x = s->x_pos;
448 const float *y = s->y_pos;
449 const float fc_x = s->fc_x;
450 const float fc_y = s->fc_y;
451
452 for (int n = 0; n < rdft_size; n++) {
453 float mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
454 float ph = phase[n];
455
456 TRANSFORM
457 }
458
459 return 0;
460}
461
462static int upmix_stereo(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
463{
464 AudioSurroundContext *s = ctx->priv;
465 float *dst = (float *)s->output->extended_data[ch];
466 const float *phase = ch ? s->r_phase : s->l_phase;
467 const float f_x = ch ? s->fr_x : s->fl_x;
468 const float f_y = ch ? s->fr_y : s->fl_y;
469 const float *mag_total = s->mag_total;
470 const int rdft_size = s->rdft_size;
471 const float neg = ch ? -1.f : 1.f;
472 const float *x = s->x_pos;
473 const float *y = s->y_pos;
474
475 for (int n = 0; n < rdft_size; n++) {
476 float mag = powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
477 float ph = phase[n];
478
479 TRANSFORM
480 }
481
482 return 0;
483}
484
485static int upmix_2_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
486{
487 AudioSurroundContext *s = ctx->priv;
488 float *dst = (float *)s->output->extended_data[ch];
489 const float *mag_total = s->mag_total;
490 const int rdft_size = s->rdft_size;
491 const float *phase = ch == 2 ? s->c_phase : ch == 1 ? s->r_phase : s->l_phase;
492 const float *lfe_mag = s->lfe_mag;
493 const float f_x = ch ? s->fr_x : s->fl_x;
494 const float f_y = ch ? s->fr_y : s->fl_y;
495 const float neg = ch ? -1.f : 1.f;
496 const float *x = s->x_pos;
497 const float *y = s->y_pos;
498
499 for (int n = 0; n < rdft_size; n++) {
500 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];
501 float ph = phase[n];
502
503 TRANSFORM
504 }
505
506 return 0;
507}
508
509static int upmix_3_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
510{
511 AudioSurroundContext *s = ctx->priv;
512 float *dst = (float *)s->output->extended_data[ch];
513 const float *phase = ch == 2 ? s->c_phase : ch == 1 ? s->r_phase : s->l_phase;
514 const float f_x = ch ? s->fr_x : s->fl_x;
515 const float f_y = ch ? s->fr_y : s->fl_y;
516 const float *mag_total = s->mag_total;
517 const int rdft_size = s->rdft_size;
518 const float neg = ch ? -1.f : 1.f;
519 const float fc_x = s->fc_x;
520 const float fc_y = s->fc_y;
521 const float *x = s->x_pos;
522 const float *y = s->y_pos;
523
524 for (int n = 0; n < rdft_size; n++) {
525 float mag = ch == 2 ?
526 powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n] :
527 powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
528 float ph = phase[n];
529
530 TRANSFORM
531 }
532
533 return 0;
534}
535
536static int upmix_3_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
537{
538 AudioSurroundContext *s = ctx->priv;
539 float *dst = (float *)s->output->extended_data[ch];
540 const float *phase = ch >= 2 ? s->c_phase : ch == 1 ? s->r_phase : s->l_phase;
541 const float f_x = ch ? s->fr_x : s->fl_x;
542 const float f_y = ch ? s->fr_y : s->fl_y;
543 const float *mag_total = s->mag_total;
544 const int rdft_size = s->rdft_size;
545 const float neg = ch ? -1.f : 1.f;
546 const float *lfe_mag = s->lfe_mag;
547 const float fc_x = s->fc_x;
548 const float fc_y = s->fc_y;
549 const float *x = s->x_pos;
550 const float *y = s->y_pos;
551
552 for (int n = 0; n < rdft_size; n++) {
553 float mag = ch == 3 ? lfe_mag[n] : ch == 2 ?
554 powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n] :
555 powf(.5f * (neg * x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
556 float ph = phase[n];
557
558 TRANSFORM
559 }
560
561 return 0;
562}
563
564static void upmix_3_1_surround(AVFilterContext *ctx,
565 float l_phase,
566 float r_phase,
567 float c_phase,
568 float c_mag,
569 float mag_total,
570 float x, float y,
571 int n)
572{
573 AudioSurroundContext *s = ctx->priv;
574 float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
575
576 dstl = (float *)s->output->extended_data[0];
577 dstr = (float *)s->output->extended_data[1];
578 dstc = (float *)s->output->extended_data[2];
579 dstlfe = (float *)s->output->extended_data[3];
580
581 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
582
583 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
584 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
585
586 dstl[2 * n ] = l_mag * cosf(l_phase);
587 dstl[2 * n + 1] = l_mag * sinf(l_phase);
588
589 dstr[2 * n ] = r_mag * cosf(r_phase);
590 dstr[2 * n + 1] = r_mag * sinf(r_phase);
591
592 dstc[2 * n ] = c_mag * cosf(c_phase);
593 dstc[2 * n + 1] = c_mag * sinf(c_phase);
594
595 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
596 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
597}
598
599static int upmix_4_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
600{
601 AudioSurroundContext *s = ctx->priv;
602 float *dst = (float *)s->output->extended_data[ch];
603 const float *mag_total = s->mag_total;
604 const int rdft_size = s->rdft_size;
605 const float *l_phase = s->l_phase;
606 const float *r_phase = s->r_phase;
607 const float *c_phase = s->c_phase;
608 const float fl_x = s->fl_x;
609 const float fl_y = s->fl_y;
610 const float fr_x = s->fr_x;
611 const float fr_y = s->fr_y;
612 const float fc_x = s->fc_x;
613 const float fc_y = s->fc_y;
614 const float bc_x = s->bc_x;
615 const float bc_y = s->bc_y;
616 const float *x = s->x_pos;
617 const float *y = s->y_pos;
618
619 for (int n = 0; n < rdft_size; n++) {
620 float mag, ph;
621
622 switch (ch) {
623 case 0:
624 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
625 ph = l_phase[n];
626 break;
627 case 1:
628 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
629 ph = r_phase[n];
630 break;
631 case 2:
632 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
633 ph = c_phase[n];
634 break;
635 case 3:
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 }
640
641 TRANSFORM
642 }
643
644 return 0;
645}
646
647static int upmix_4_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
648{443{
649 AudioSurroundContext *s = ctx->priv;444 AudioSurroundContext *s = ctx->priv;
650 float *dst = (float *)s->output->extended_data[ch];445 float *dst = (float *)s->output->extended_data[ch];
651 const float *mag_total = s->mag_total;446 const float *mag_total = s->mag_total;
652 const int rdft_size = s->rdft_size;447 const int rdft_size = s->rdft_size;
653 const float *lfe_mag = s->lfe_mag;
654 const float *l_phase = s->l_phase;
655 const float *r_phase = s->r_phase;
656 const float *c_phase = s->c_phase;448 const float *c_phase = s->c_phase;
657 const float fl_x = s->fl_x;
658 const float fl_y = s->fl_y;
659 const float fr_x = s->fr_x;
660 const float fr_y = s->fr_y;
661 const float fc_x = s->fc_x;
662 const float fc_y = s->fc_y;
663 const float bc_x = s->bc_x;
664 const float bc_y = s->bc_y;
665 const float *x = s->x_pos;
666 const float *y = s->y_pos;
667
668 for (int n = 0; n < rdft_size; n++) {
669 float mag, ph;
670
671 switch (ch) {
672 case 0:
673 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
674 ph = l_phase[n];
675 break;
676 case 1:
677 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
678 ph = r_phase[n];
679 break;
680 case 2:
681 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
682 ph = c_phase[n];
683 break;
684 case 3:
685 mag = lfe_mag[n];
686 ph = c_phase[n];
687 break;
688 case 4:
689 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
690 ph = c_phase[n];
691 break;
692 }
693
694 TRANSFORM
695 }
696
697 return 0;
698}
699
700static int upmix_5_0_back(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
701{
702 AudioSurroundContext *s = ctx->priv;
703 float *dst = (float *)s->output->extended_data[ch];
704 const float *mag_total = s->mag_total;
705 const int rdft_size = s->rdft_size;
706 const float *l_phase = s->l_phase;449 const float *l_phase = s->l_phase;
707 const float *r_phase = s->r_phase;450 const float *r_phase = s->r_phase;
708 const float *c_phase = s->c_phase;
709 const float fl_x = s->fl_x;
710 const float fl_y = s->fl_y;
711 const float fr_x = s->fr_x;
712 const float fr_y = s->fr_y;
713 const float bl_x = s->bl_x;
714 const float bl_y = s->bl_y;
715 const float br_x = s->br_x;
716 const float br_y = s->br_y;
717 const float fc_x = s->fc_x;
718 const float fc_y = s->fc_y;
719 const float *x = s->x_pos;
720 const float *y = s->y_pos;
721
722 for (int n = 0; n < rdft_size; n++) {
723 float mag, ph;
724
725 switch (ch) {
726 case 2:
727 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
728 ph = c_phase[n];
729 break;
730 case 0:
731 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
732 ph = l_phase[n];
733 break;
734 case 1:
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 break;
738 case 3:
739 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
740 ph = l_phase[n];
741 break;
742 case 4:
743 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
744 ph = r_phase[n];
745 break;
746 }
747
748 TRANSFORM
749 }
750
751 return 0;
752}
753
754static int upmix_5_1_back(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
755{
756 AudioSurroundContext *s = ctx->priv;
757 float *dst = (float *)s->output->extended_data[ch];
758 const float *mag_total = s->mag_total;
759 const float *lfe_mag = s->lfe_mag;451 const float *lfe_mag = s->lfe_mag;
760 const int rdft_size = s->rdft_size;
761 const float *l_phase = s->l_phase;
762 const float *r_phase = s->r_phase;
763 const float *c_phase = s->c_phase;
764 const float fl_x = s->fl_x;
765 const float fl_y = s->fl_y;
766 const float fr_x = s->fr_x;
767 const float fr_y = s->fr_y;
768 const float bl_x = s->bl_x;
769 const float bl_y = s->bl_y;
770 const float br_x = s->br_x;
771 const float br_y = s->br_y;
772 const float fc_x = s->fc_x;
773 const float fc_y = s->fc_y;
774 const float *x = s->x_pos;452 const float *x = s->x_pos;
775 const float *y = s->y_pos;453 const float *y = s->y_pos;
776 float mag, ph;454 const int chan = av_channel_layout_channel_from_index(&s->out_ch_layout, ch);
455 float f_x, f_y;
777 456
778 switch (ch) {457 switch (chan) {
779 case 0:458 case AV_CHAN_FRONT_CENTER:
459 f_x = s->fc_x;
460 f_y = s->fc_y;
780 for (int n = 0; n < rdft_size; n++) {461 for (int n = 0; n < rdft_size; n++) {
781 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];462 float mag = powf(1.f - fabsf(x[n]), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
782 ph = l_phase[n];463 float ph = c_phase[n];
783 TRANSFORM464
784 }
785 break;
786 case 1:
787 for (int n = 0; n < rdft_size; n++) {
788 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
789 ph = r_phase[n];
790 TRANSFORM465 TRANSFORM
791 }466 }
792 break;467 break;
793 case 2:468 case AV_CHAN_FRONT_LEFT:
469 f_x = s->fl_x;
470 f_y = s->fl_y;
794 for (int n = 0; n < rdft_size; n++) {471 for (int n = 0; n < rdft_size; n++) {
795 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];472 float mag = powf(.5f * ( x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
796 ph = c_phase[n];473 float ph = l_phase[n];
474
797 TRANSFORM475 TRANSFORM
798 }476 }
799 break;477 break;
800 case 3:478 case AV_CHAN_FRONT_RIGHT:
479 f_x = s->fr_x;
480 f_y = s->fr_y;
801 for (int n = 0; n < rdft_size; n++) {481 for (int n = 0; n < rdft_size; n++) {
802 mag = lfe_mag[n];482 float mag = powf(.5f * (-x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];
803 ph = c_phase[n];483 float ph = r_phase[n];
484
804 TRANSFORM485 TRANSFORM
805 }486 }
806 break;487 break;
807 case 4:488 case AV_CHAN_LOW_FREQUENCY:
808 for (int n = 0; n < rdft_size; n++) {489 for (int n = 0; n < rdft_size; n++) {
809 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];490 float mag = lfe_mag[n];
810 ph = l_phase[n];491 float ph = c_phase[n];
492
811 TRANSFORM493 TRANSFORM
812 }494 }
813 break;495 break;
814 case 5:496 case AV_CHAN_BACK_CENTER:
497 f_x = s->bc_x;
498 f_y = s->bc_y;
815 for (int n = 0; n < rdft_size; n++) {499 for (int n = 0; n < rdft_size; n++) {
816 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];500 float mag = powf(1.f - fabsf(x[n]), f_x) * powf((1.f - y[n]) * .5f, f_y) * mag_total[n];
817 ph = r_phase[n];501 float ph = c_phase[n];
818 TRANSFORM
819 }
820 break;
821 }
822 502
823 return 0;
824}
825
826static int upmix_6_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
827{
828 AudioSurroundContext *s = ctx->priv;
829 float *dst = (float *)s->output->extended_data[ch];
830 const float *mag_total = s->mag_total;
831 const int rdft_size = s->rdft_size;
832 const float *l_phase = s->l_phase;
833 const float *r_phase = s->r_phase;
834 const float *c_phase = s->c_phase;
835 const float fl_x = s->fl_x;
836 const float fl_y = s->fl_y;
837 const float fr_x = s->fr_x;
838 const float fr_y = s->fr_y;
839 const float bl_x = s->bl_x;
840 const float bl_y = s->bl_y;
841 const float br_x = s->br_x;
842 const float br_y = s->br_y;
843 const float bc_x = s->bc_x;
844 const float bc_y = s->bc_y;
845 const float fc_x = s->fc_x;
846 const float fc_y = s->fc_y;
847 const float *x = s->x_pos;
848 const float *y = s->y_pos;
849 float mag, ph;
850
851 switch (ch) {
852 case 0:
853 for (int n = 0; n < rdft_size; n++) {
854 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
855 ph = l_phase[n];
856 TRANSFORM503 TRANSFORM
857 }504 }
858 break;505 break;
859 case 1:506 case AV_CHAN_BACK_LEFT:
507 f_x = s->bl_x;
508 f_y = s->bl_y;
860 for (int n = 0; n < rdft_size; n++) {509 for (int n = 0; n < rdft_size; n++) {
861 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];510 float mag = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y) * mag_total[n];
862 ph = r_phase[n];511 float ph = l_phase[n];
512
863 TRANSFORM513 TRANSFORM
864 }514 }
865 break;515 break;
866 case 2:516 case AV_CHAN_BACK_RIGHT:
517 f_x = s->br_x;
518 f_y = s->br_y;
867 for (int n = 0; n < rdft_size; n++) {519 for (int n = 0; n < rdft_size; n++) {
868 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];520 float mag = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y) * mag_total[n];
869 ph = c_phase[n];521 float ph = r_phase[n];
522
870 TRANSFORM523 TRANSFORM
871 }524 }
872 break;525 break;
873 case 3:526 case AV_CHAN_SIDE_LEFT:
527 f_x = s->sl_x;
528 f_y = s->sl_y;
874 for (int n = 0; n < rdft_size; n++) {529 for (int n = 0; n < rdft_size; n++) {
875 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];530 float mag = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y) * mag_total[n];
876 ph = c_phase[n];531 float ph = l_phase[n];
532
877 TRANSFORM533 TRANSFORM
878 }534 }
879 break;535 break;
880 case 4:536 case AV_CHAN_SIDE_RIGHT:
537 f_x = s->sr_x;
538 f_y = s->sr_y;
881 for (int n = 0; n < rdft_size; n++) {539 for (int n = 0; n < rdft_size; n++) {
882 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];540 float mag = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y) * mag_total[n];
883 ph = l_phase[n];541 float ph = r_phase[n];
542
884 TRANSFORM543 TRANSFORM
885 }544 }
886 break;545 break;
887 case 5:546 default:
888 for (int n = 0; n < rdft_size; n++) {
889 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
890 ph = r_phase[n];
891 TRANSFORM
892 }
893 break;547 break;
894 }548 }
895 549
896 return 0;550 return 0;
897}551}
898 552
899static int upmix_6_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)553static void upmix_3_1_surround(AVFilterContext *ctx,
554 float l_phase,
555 float r_phase,
556 float c_phase,
557 float c_mag,
558 float mag_total,
559 float x, float y,
560 int n)
900{561{
901 AudioSurroundContext *s = ctx->priv;562 AudioSurroundContext *s = ctx->priv;
902 float *dst = (float *)s->output->extended_data[ch];563 float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
903 const float *mag_total = s->mag_total;
904 const int rdft_size = s->rdft_size;
905 const float *lfe_mag = s->lfe_mag;
906 const float *l_phase = s->l_phase;
907 const float *r_phase = s->r_phase;
908 const float *c_phase = s->c_phase;
909 const float fl_x = s->fl_x;
910 const float fl_y = s->fl_y;
911 const float fr_x = s->fr_x;
912 const float fr_y = s->fr_y;
913 const float bl_x = s->bl_x;
914 const float bl_y = s->bl_y;
915 const float br_x = s->br_x;
916 const float br_y = s->br_y;
917 const float bc_x = s->bc_x;
918 const float bc_y = s->bc_y;
919 const float fc_x = s->fc_x;
920 const float fc_y = s->fc_y;
921 const float *x = s->x_pos;
922 const float *y = s->y_pos;
923 float mag, ph;
924 564
925 switch (ch) {565 dstl = (float *)s->output->extended_data[0];
926 case 0:566 dstr = (float *)s->output->extended_data[1];
927 for (int n = 0; n < rdft_size; n++) {567 dstc = (float *)s->output->extended_data[2];
928 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];568 dstlfe = (float *)s->output->extended_data[3];
929 ph = l_phase[n];
930 TRANSFORM
931 }
932 break;
933 case 1:
934 for (int n = 0; n < rdft_size; n++) {
935 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
936 ph = r_phase[n];
937 TRANSFORM
938 }
939 break;
940 case 2:
941 for (int n = 0; n < rdft_size; n++) {
942 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
943 ph = c_phase[n];
944 TRANSFORM
945 }
946 break;
947 case 3:
948 for (int n = 0; n < rdft_size; n++) {
949 mag = lfe_mag[n];
950 ph = c_phase[n];
951 TRANSFORM
952 }
953 break;
954 case 4:
955 for (int n = 0; n < rdft_size; n++) {
956 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
957 ph = c_phase[n];
958 TRANSFORM
959 }
960 break;
961 case 5:
962 for (int n = 0; n < rdft_size; n++) {
963 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
964 ph = l_phase[n];
965 TRANSFORM
966 }
967 break;
968 case 6:
969 for (int n = 0; n < rdft_size; n++) {
970 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
971 ph = r_phase[n];
972 TRANSFORM
973 }
974 break;
975 }
976 569
977 return 0;570 get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag, s->lfe_mode);
571
572 l_mag = powf(.5f * ( x + 1.f), s->fl_x) * powf((y + 1.f) * .5f, s->fl_y) * mag_total;
573 r_mag = powf(.5f * (-x + 1.f), s->fr_x) * powf((y + 1.f) * .5f, s->fr_y) * mag_total;
574
575 dstl[2 * n ] = l_mag * cosf(l_phase);
576 dstl[2 * n + 1] = l_mag * sinf(l_phase);
577
578 dstr[2 * n ] = r_mag * cosf(r_phase);
579 dstr[2 * n + 1] = r_mag * sinf(r_phase);
580
581 dstc[2 * n ] = c_mag * cosf(c_phase);
582 dstc[2 * n + 1] = c_mag * sinf(c_phase);
583
584 dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
585 dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
978}586}
979 587
980static void upmix_5_1_back_surround(AVFilterContext *ctx,588static void upmix_5_1_back_surround(AVFilterContext *ctx,
@@ -1069,178 +677,6 @@ static void upmix_5_1_back_2_1(AVFilterContext *ctx, · 88 unmodified lines
1069 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);677 dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
1070}678}
1071 679
1072static int upmix_7_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1073{
1074 AudioSurroundContext *s = ctx->priv;
1075 float *dst = (float *)s->output->extended_data[ch];
1076 const float *mag_total = s->mag_total;
1077 const int rdft_size = s->rdft_size;
1078 const float *l_phase = s->l_phase;
1079 const float *r_phase = s->r_phase;
1080 const float *c_phase = s->c_phase;
1081 const float fl_x = s->fl_x;
1082 const float fl_y = s->fl_y;
1083 const float fr_x = s->fr_x;
1084 const float fr_y = s->fr_y;
1085 const float fc_x = s->fc_x;
1086 const float fc_y = s->fc_y;
1087 const float bl_x = s->bl_x;
1088 const float bl_y = s->bl_y;
1089 const float br_x = s->br_x;
1090 const float br_y = s->br_y;
1091 const float sl_x = s->sl_x;
1092 const float sl_y = s->sl_y;
1093 const float sr_x = s->sr_x;
1094 const float sr_y = s->sr_y;
1095 const float *x = s->x_pos;
1096 const float *y = s->y_pos;
1097 float mag, ph;
1098
1099 switch (ch) {
1100 case 0:
1101 for (int n = 0; n < rdft_size; n++) {
1102 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
1103 ph = l_phase[n];
1104 TRANSFORM
1105 }
1106 break;
1107 case 1:
1108 for (int n = 0; n < rdft_size; n++) {
1109 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
1110 ph = r_phase[n];
1111 TRANSFORM
1112 }
1113 break;
1114 case 2:
1115 for (int n = 0; n < rdft_size; n++) {
1116 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
1117 ph = c_phase[n];
1118 TRANSFORM
1119 }
1120 break;
1121 case 3:
1122 for (int n = 0; n < rdft_size; n++) {
1123 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
1124 ph = l_phase[n];
1125 TRANSFORM
1126 }
1127 break;
1128 case 4:
1129 for (int n = 0; n < rdft_size; n++) {
1130 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
1131 ph = r_phase[n];
1132 TRANSFORM
1133 }
1134 break;
1135 case 5:
1136 for (int n = 0; n < rdft_size; n++) {
1137 mag = powf(.5f * ( x[n] + 1.f), sl_x) * powf(1.f - fabsf(y[n]), sl_y) * mag_total[n];
1138 ph = l_phase[n];
1139 TRANSFORM
1140 }
1141 break;
1142 case 6:
1143 for (int n = 0; n < rdft_size; n++) {
1144 mag = powf(.5f * (-x[n] + 1.f), sr_x) * powf(1.f - fabsf(y[n]), sr_y) * mag_total[n];
1145 ph = r_phase[n];
1146 TRANSFORM
1147 }
1148 break;
1149 }
1150
1151 return 0;
1152}
1153
1154static int upmix_7_1(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1155{
1156 AudioSurroundContext *s = ctx->priv;
1157 float *dst = (float *)s->output->extended_data[ch];
1158 const float *mag_total = s->mag_total;
1159 const int rdft_size = s->rdft_size;
1160 const float *lfe_mag = s->lfe_mag;
1161 const float *l_phase = s->l_phase;
1162 const float *r_phase = s->r_phase;
1163 const float *c_phase = s->c_phase;
1164 const float fl_x = s->fl_x;
1165 const float fl_y = s->fl_y;
1166 const float fr_x = s->fr_x;
1167 const float fr_y = s->fr_y;
1168 const float fc_x = s->fc_x;
1169 const float fc_y = s->fc_y;
1170 const float bl_x = s->bl_x;
1171 const float bl_y = s->bl_y;
1172 const float br_x = s->br_x;
1173 const float br_y = s->br_y;
1174 const float sl_x = s->sl_x;
1175 const float sl_y = s->sl_y;
1176 const float sr_x = s->sr_x;
1177 const float sr_y = s->sr_y;
1178 const float *x = s->x_pos;
1179 const float *y = s->y_pos;
1180 float mag, ph;
1181
1182 switch (ch) {
1183 case 0:
1184 for (int n = 0; n < rdft_size; n++) {
1185 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
1186 ph = l_phase[n];
1187 TRANSFORM
1188 }
1189 break;
1190 case 1:
1191 for (int n = 0; n < rdft_size; n++) {
1192 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
1193 ph = r_phase[n];
1194 TRANSFORM
1195 }
1196 break;
1197 case 2:
1198 for (int n = 0; n < rdft_size; n++) {
1199 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
1200 ph = c_phase[n];
1201 TRANSFORM
1202 }
1203 break;
1204 case 3:
1205 for (int n = 0; n < rdft_size; n++) {
1206 mag = lfe_mag[n];
1207 ph = c_phase[n];
1208 TRANSFORM
1209 }
1210 break;
1211 case 4:
1212 for (int n = 0; n < rdft_size; n++) {
1213 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
1214 ph = l_phase[n];
1215 TRANSFORM
1216 }
1217 break;
1218 case 5:
1219 for (int n = 0; n < rdft_size; n++) {
1220 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
1221 ph = r_phase[n];
1222 TRANSFORM
1223 }
1224 break;
1225 case 6:
1226 for (int n = 0; n < rdft_size; n++) {
1227 mag = powf(.5f * ( x[n] + 1.f), sl_x) * powf(1.f - fabsf(y[n]), sl_y) * mag_total[n];
1228 ph = l_phase[n];
1229 TRANSFORM
1230 }
1231 break;
1232 case 7:
1233 for (int n = 0; n < rdft_size; n++) {
1234 mag = powf(.5f * (-x[n] + 1.f), sr_x) * powf(1.f - fabsf(y[n]), sr_y) * mag_total[n];
1235 ph = r_phase[n];
1236 TRANSFORM
1237 }
1238 break;
1239 }
1240
1241 return 0;
1242}
1243
1244static void upmix_7_1_5_0_side(AVFilterContext *ctx,680static void upmix_7_1_5_0_side(AVFilterContext *ctx,
1245 float c_re, float c_im,681 float c_re, float c_im,
1246 float mag_totall, float mag_totalr,682 float mag_totall, float mag_totalr,
@@ -1357,97 +793,6 @@ static void upmix_7_1_5_1(AVFilterContext *ctx, · 110 unmodified lines
1357 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);793 dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
1358}794}
1359 795
1360static int upmix_8_0(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
1361{
1362 AudioSurroundContext *s = ctx->priv;
1363 float *dst = (float *)s->output->extended_data[ch];
1364 const float *mag_total = s->mag_total;
1365 const int rdft_size = s->rdft_size;
1366 const float *l_phase = s->l_phase;
1367 const float *r_phase = s->r_phase;
1368 const float *c_phase = s->c_phase;
1369 const float fl_x = s->fl_x;
1370 const float fl_y = s->fl_y;
1371 const float fr_x = s->fr_x;
1372 const float fr_y = s->fr_y;
1373 const float fc_x = s->fc_x;
1374 const float fc_y = s->fc_y;
1375 const float bl_x = s->bl_x;
1376 const float bl_y = s->bl_y;
1377 const float br_x = s->br_x;
1378 const float br_y = s->br_y;
1379 const float sl_x = s->sl_x;
1380 const float sl_y = s->sl_y;
1381 const float sr_x = s->sr_x;
1382 const float sr_y = s->sr_y;
1383 const float bc_x = s->bc_x;
1384 const float bc_y = s->bc_y;
1385 const float *x = s->x_pos;
1386 const float *y = s->y_pos;
1387 float mag, ph;
1388
1389 switch (ch) {
1390 case 0:
1391 for (int n = 0; n < rdft_size; n++) {
1392 mag = powf(.5f * ( x[n] + 1.f), fl_x) * powf((y[n] + 1.f) * .5f, fl_y) * mag_total[n];
1393 ph = l_phase[n];
1394 TRANSFORM
1395 }
1396 break;
1397 case 1:
1398 for (int n = 0; n < rdft_size; n++) {
1399 mag = powf(.5f * (-x[n] + 1.f), fr_x) * powf((y[n] + 1.f) * .5f, fr_y) * mag_total[n];
1400 ph = r_phase[n];
1401 TRANSFORM
1402 }
1403 break;
1404 case 2:
1405 for (int n = 0; n < rdft_size; n++) {
1406 mag = powf(1.f - fabsf(x[n]), fc_x) * powf((y[n] + 1.f) * .5f, fc_y) * mag_total[n];
1407 ph = c_phase[n];
1408 TRANSFORM
1409 }
1410 break;
1411 case 3:
1412 for (int n = 0; n < rdft_size; n++) {
1413 mag = powf(.5f * ( x[n] + 1.f), bl_x) * powf(1.f - ((y[n] + 1.f) * .5f), bl_y) * mag_total[n];
1414 ph = l_phase[n];
1415 TRANSFORM
1416 }
1417 break;
1418 case 4:
1419 for (int n = 0; n < rdft_size; n++) {
1420 mag = powf(.5f * (-x[n] + 1.f), br_x) * powf(1.f - ((y[n] + 1.f) * .5f), br_y) * mag_total[n];
1421 ph = r_phase[n];
1422 TRANSFORM
1423 }
1424 break;
1425 case 5:
1426 for (int n = 0; n < rdft_size; n++) {
1427 mag = powf(1.f - fabsf(x[n]), bc_x) * powf((1.f - y[n]) * .5f, bc_y) * mag_total[n];
1428 ph = l_phase[n];
1429 TRANSFORM
1430 }
1431 break;
1432 case 6:
1433 for (int n = 0; n < rdft_size; n++) {
1434 mag = powf(.5f * ( x[n] + 1.f), sl_x) * powf(1.f - fabsf(y[n]), sl_y) * mag_total[n];
1435 ph = l_phase[n];
1436 TRANSFORM
1437 }
1438 break;
1439 case 7:
1440 for (int n = 0; n < rdft_size; n++) {
1441 mag = powf(.5f * (-x[n] + 1.f), sr_x) * powf(1.f - fabsf(y[n]), sr_y) * mag_total[n];
1442 ph = r_phase[n];
1443 TRANSFORM
1444 }
1445 break;
1446 }
1447
1448 return 0;
1449}
1450
1451static void filter_stereo(AVFilterContext *ctx)796static void filter_stereo(AVFilterContext *ctx)
1452{797{
1453 AudioSurroundContext *s = ctx->priv;798 AudioSurroundContext *s = ctx->priv;
@@ -1473,14 +818,15 @@ static void filter_stereo(AVFilterContext *ctx) · 19 unmodified lines
1473 float c_phase = atan2f(l_im + r_im, l_re + r_re);818 float c_phase = atan2f(l_im + r_im, l_re + r_re);
1474 float l_mag = hypotf(l_re, l_im);819 float l_mag = hypotf(l_re, l_im);
1475 float r_mag = hypotf(r_re, r_im);820 float r_mag = hypotf(r_re, r_im);
821 float mag_total = hypotf(l_mag, r_mag);
1476 float l_phase = atan2f(l_im, l_re);822 float l_phase = atan2f(l_im, l_re);
1477 float r_phase = atan2f(r_im, r_re);823 float r_phase = atan2f(r_im, r_re);
1478 float phase_dif = fabsf(l_phase - r_phase);824 float phase_dif = fabsf(l_phase - r_phase);
1479 float mag_sum = l_mag + r_mag;825 float mag_sum = l_mag + r_mag;
1480 float mag_dif = mag_sum < 0.000001f ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;826 float mag_dif, x, y;
1481 float mag_total = hypotf(l_mag, r_mag);
1482 float x, y;
1483 827
828 mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum;
829 mag_dif = (l_mag - r_mag) / mag_sum;
1484 if (phase_dif > M_PI)830 if (phase_dif > M_PI)
1485 phase_dif = 2.f * M_PI - phase_dif;831 phase_dif = 2.f * M_PI - phase_dif;
1486 832
@@ -1516,14 +862,15 @@ static void filter_surround(AVFilterContext *ctx) · 29 unmodified lines
1516 float c_phase = atan2f(c_im, c_re);862 float c_phase = atan2f(c_im, c_re);
1517 float l_mag = hypotf(l_re, l_im);863 float l_mag = hypotf(l_re, l_im);
1518 float r_mag = hypotf(r_re, r_im);864 float r_mag = hypotf(r_re, r_im);
865 float mag_total = hypotf(l_mag, r_mag);
1519 float l_phase = atan2f(l_im, l_re);866 float l_phase = atan2f(l_im, l_re);
1520 float r_phase = atan2f(r_im, r_re);867 float r_phase = atan2f(r_im, r_re);
1521 float phase_dif = fabsf(l_phase - r_phase);868 float phase_dif = fabsf(l_phase - r_phase);
1522 float mag_sum = l_mag + r_mag;869 float mag_sum = l_mag + r_mag;
1523 float mag_dif = mag_sum < 0.000001f ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;870 float mag_dif, x, y;
1524 float mag_total = hypotf(l_mag, r_mag);
1525 float x, y;
1526 871
872 mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum;
873 mag_dif = (l_mag - r_mag) / mag_sum;
1527 if (phase_dif > M_PI)874 if (phase_dif > M_PI)
1528 phase_dif = 2.f * M_PI - phase_dif;875 phase_dif = 2.f * M_PI - phase_dif;
1529 876
@@ -1551,14 +898,15 @@ static void filter_2_1(AVFilterContext *ctx) · 21 unmodified lines
1551 float c_phase = atan2f(l_im + r_im, l_re + r_re);898 float c_phase = atan2f(l_im + r_im, l_re + r_re);
1552 float l_mag = hypotf(l_re, l_im);899 float l_mag = hypotf(l_re, l_im);
1553 float r_mag = hypotf(r_re, r_im);900 float r_mag = hypotf(r_re, r_im);
901 float mag_total = hypotf(l_mag, r_mag);
1554 float l_phase = atan2f(l_im, l_re);902 float l_phase = atan2f(l_im, l_re);
1555 float r_phase = atan2f(r_im, r_re);903 float r_phase = atan2f(r_im, r_re);
1556 float phase_dif = fabsf(l_phase - r_phase);904 float phase_dif = fabsf(l_phase - r_phase);
1557 float mag_sum = l_mag + r_mag;905 float mag_sum = l_mag + r_mag;
1558 float mag_dif = mag_sum < 0.000001f ? FFDIFFSIGN(l_mag, r_mag) : (l_mag - r_mag) / mag_sum;906 float mag_dif, x, y;
1559 float mag_total = hypotf(l_mag, r_mag);
1560 float x, y;
1561 907
908 mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum;
909 mag_dif = (l_mag - r_mag) / mag_sum;
1562 if (phase_dif > M_PI)910 if (phase_dif > M_PI)
1563 phase_dif = 2.f * M_PI - phase_dif;911 phase_dif = 2.f * M_PI - phase_dif;
1564 912
@@ -1599,8 +947,8 @@ static void filter_5_0_side(AVFilterContext *ctx) · 34 unmodified lines
1599 float phase_difr = fabsf(fr_phase - sr_phase);947 float phase_difr = fabsf(fr_phase - sr_phase);
1600 float magl_sum = fl_mag + sl_mag;948 float magl_sum = fl_mag + sl_mag;
1601 float magr_sum = fr_mag + sr_mag;949 float magr_sum = fr_mag + sr_mag;
1602 float mag_difl = magl_sum < 0.000001f ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;950 float mag_difl = magl_sum < MIN_MAG_SUM ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1603 float mag_difr = magr_sum < 0.000001f ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;951 float mag_difr = magr_sum < MIN_MAG_SUM ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1604 float mag_totall = hypotf(fl_mag, sl_mag);952 float mag_totall = hypotf(fl_mag, sl_mag);
1605 float mag_totalr = hypotf(fr_mag, sr_mag);953 float mag_totalr = hypotf(fr_mag, sr_mag);
1606 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);954 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
@@ -1658,8 +1006,8 @@ static void filter_5_1_side(AVFilterContext *ctx) · 51 unmodified lines
1658 float phase_difr = fabsf(fr_phase - sr_phase);1006 float phase_difr = fabsf(fr_phase - sr_phase);
1659 float magl_sum = fl_mag + sl_mag;1007 float magl_sum = fl_mag + sl_mag;
1660 float magr_sum = fr_mag + sr_mag;1008 float magr_sum = fr_mag + sr_mag;
1661 float mag_difl = magl_sum < 0.000001f ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;1009 float mag_difl = magl_sum < MIN_MAG_SUM ? FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1662 float mag_difr = magr_sum < 0.000001f ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;1010 float mag_difr = magr_sum < MIN_MAG_SUM ? FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1663 float mag_totall = hypotf(fl_mag, sl_mag);1011 float mag_totall = hypotf(fl_mag, sl_mag);
1664 float mag_totalr = hypotf(fr_mag, sr_mag);1012 float mag_totalr = hypotf(fr_mag, sr_mag);
1665 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);1013 float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
@@ -1717,8 +1065,8 @@ static void filter_5_1_back(AVFilterContext *ctx) · 51 unmodified lines
1717 float phase_difr = fabsf(fr_phase - br_phase);1065 float phase_difr = fabsf(fr_phase - br_phase);
1718 float magl_sum = fl_mag + bl_mag;1066 float magl_sum = fl_mag + bl_mag;
1719 float magr_sum = fr_mag + br_mag;1067 float magr_sum = fr_mag + br_mag;
1720 float mag_difl = magl_sum < 0.000001f ? FFDIFFSIGN(fl_mag, bl_mag) : (fl_mag - bl_mag) / magl_sum;1068 float mag_difl = magl_sum < MIN_MAG_SUM ? FFDIFFSIGN(fl_mag, bl_mag) : (fl_mag - bl_mag) / magl_sum;
1721 float mag_difr = magr_sum < 0.000001f ? FFDIFFSIGN(fr_mag, br_mag) : (fr_mag - br_mag) / magr_sum;1069 float mag_difr = magr_sum < MIN_MAG_SUM ? FFDIFFSIGN(fr_mag, br_mag) : (fr_mag - br_mag) / magr_sum;
1722 float mag_totall = hypotf(fl_mag, bl_mag);1070 float mag_totall = hypotf(fl_mag, bl_mag);
1723 float mag_totalr = hypotf(fr_mag, br_mag);1071 float mag_totalr = hypotf(fr_mag, br_mag);
1724 float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);1072 float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
@@ -1786,59 +1134,29 @@ static av_cold int init(AVFilterContext *ctx) · 61 unmodified lines
1786 out_channel_layout = s->out_ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?1134 out_channel_layout = s->out_ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1787 s->out_ch_layout.u.mask : 0;1135 s->out_ch_layout.u.mask : 0;
1788 1136
1789 s->have_lfe = 0;1137 s->have_lfe = av_channel_layout_index_from_channel(&s->out_ch_layout,
1138 AV_CHAN_LOW_FREQUENCY) >= 0;
1790 1139
1791 switch (in_channel_layout) {1140 switch (in_channel_layout) {
1792 case AV_CH_LAYOUT_STEREO:1141 case AV_CH_LAYOUT_STEREO:
1793 s->filter = filter_stereo;1142 s->filter = filter_stereo;
1143 s->upmix = stereo_upmix;
1794 switch (out_channel_layout) {1144 switch (out_channel_layout) {
1795 case AV_CH_LAYOUT_MONO:1145 case AV_CH_LAYOUT_MONO:
1796 s->upmix = upmix_1_0;
1797 break;
1798 case AV_CH_LAYOUT_STEREO:1146 case AV_CH_LAYOUT_STEREO:
1799 s->upmix = upmix_stereo;
1800 break;
1801 case AV_CH_LAYOUT_2POINT1:
1802 s->upmix = upmix_2_1;
1803 s->have_lfe = 1;
1804 break;
1805 case AV_CH_LAYOUT_SURROUND:1147 case AV_CH_LAYOUT_SURROUND:
1806 s->upmix = upmix_3_0;
1807 break;
1808 case AV_CH_LAYOUT_3POINT1:1148 case AV_CH_LAYOUT_3POINT1:
1809 s->upmix = upmix_3_1;
1810 s->have_lfe = 1;
1811 break;
1812 case AV_CH_LAYOUT_4POINT0:1149 case AV_CH_LAYOUT_4POINT0:
1813 s->upmix = upmix_4_0;
1814 break;
1815 case AV_CH_LAYOUT_4POINT1:1150 case AV_CH_LAYOUT_4POINT1:
1816 s->upmix = upmix_4_1;1151 case AV_CH_LAYOUT_5POINT0:
1817 s->have_lfe = 1;1152 case AV_CH_LAYOUT_5POINT1:
1818 break;
1819 case AV_CH_LAYOUT_5POINT0_BACK:1153 case AV_CH_LAYOUT_5POINT0_BACK:
1820 s->upmix = upmix_5_0_back;
1821 break;
1822 case AV_CH_LAYOUT_5POINT1_BACK:1154 case AV_CH_LAYOUT_5POINT1_BACK:
1823 s->upmix = upmix_5_1_back;
1824 s->have_lfe = 1;
1825 break;
1826 case AV_CH_LAYOUT_6POINT0:1155 case AV_CH_LAYOUT_6POINT0:
1827 s->upmix = upmix_6_0;
1828 break;
1829 case AV_CH_LAYOUT_6POINT1:1156 case AV_CH_LAYOUT_6POINT1:
1830 s->upmix = upmix_6_1;
1831 s->have_lfe = 1;
1832 break;
1833 case AV_CH_LAYOUT_7POINT0:1157 case AV_CH_LAYOUT_7POINT0:
1834 s->upmix = upmix_7_0;
1835 break;
1836 case AV_CH_LAYOUT_7POINT1:1158 case AV_CH_LAYOUT_7POINT1:
1837 s->upmix = upmix_7_1;
1838 s->have_lfe = 1;
1839 break;
1840 case AV_CH_LAYOUT_OCTAGONAL:1159 case AV_CH_LAYOUT_OCTAGONAL:
1841 s->upmix = upmix_8_0;
1842 break;1160 break;
1843 default:1161 default:
1844 goto fail;1162 goto fail;
@@ -1849,7 +1167,6 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1849 switch (out_channel_layout) {1167 switch (out_channel_layout) {
1850 case AV_CH_LAYOUT_5POINT1_BACK:1168 case AV_CH_LAYOUT_5POINT1_BACK:
1851 s->upmix_2_1 = upmix_5_1_back_2_1;1169 s->upmix_2_1 = upmix_5_1_back_2_1;
1852 s->have_lfe = 1;
1853 break;1170 break;
1854 default:1171 default:
1855 goto fail;1172 goto fail;
@@ -1860,11 +1177,9 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1860 switch (out_channel_layout) {1177 switch (out_channel_layout) {
1861 case AV_CH_LAYOUT_3POINT1:1178 case AV_CH_LAYOUT_3POINT1:
1862 s->upmix_3_0 = upmix_3_1_surround;1179 s->upmix_3_0 = upmix_3_1_surround;
1863 s->have_lfe = 1;
1864 break;1180 break;
1865 case AV_CH_LAYOUT_5POINT1_BACK:1181 case AV_CH_LAYOUT_5POINT1_BACK:
1866 s->upmix_3_0 = upmix_5_1_back_surround;1182 s->upmix_3_0 = upmix_5_1_back_surround;
1867 s->have_lfe = 1;
1868 break;1183 break;
1869 default:1184 default:
1870 goto fail;1185 goto fail;
@@ -1875,7 +1190,6 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1875 switch (out_channel_layout) {1190 switch (out_channel_layout) {
1876 case AV_CH_LAYOUT_7POINT1:1191 case AV_CH_LAYOUT_7POINT1:
1877 s->upmix_5_0 = upmix_7_1_5_0_side;1192 s->upmix_5_0 = upmix_7_1_5_0_side;
1878 s->have_lfe = 1;
1879 break;1193 break;
1880 default:1194 default:
1881 goto fail;1195 goto fail;
@@ -1886,7 +1200,6 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1886 switch (out_channel_layout) {1200 switch (out_channel_layout) {
1887 case AV_CH_LAYOUT_7POINT1:1201 case AV_CH_LAYOUT_7POINT1:
1888 s->upmix_5_1 = upmix_7_1_5_1;1202 s->upmix_5_1 = upmix_7_1_5_1;
1889 s->have_lfe = 1;
1890 break;1203 break;
1891 default:1204 default:
1892 goto fail;1205 goto fail;
@@ -1897,7 +1210,6 @@ static av_cold int init(AVFilterContext *ctx) · 4 unmodified lines
1897 switch (out_channel_layout) {1210 switch (out_channel_layout) {
1898 case AV_CH_LAYOUT_7POINT1:1211 case AV_CH_LAYOUT_7POINT1:
1899 s->upmix_5_1 = upmix_7_1_5_1;1212 s->upmix_5_1 = upmix_7_1_5_1;
1900 s->have_lfe = 1;
1901 break;1213 break;
1902 default:1214 default:
1903 goto fail;1215 goto fail;

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