129 float c_re,
float c_im,
130 float mag_totall,
float mag_totalr,
131 float fl_phase,
float fr_phase,
132 float bl_phase,
float br_phase,
133 float sl_phase,
float sr_phase,
138 float c_re,
float c_im,
139 float lfe_re,
float lfe_im,
140 float mag_totall,
float mag_totalr,
141 float fl_phase,
float fr_phase,
142 float bl_phase,
float br_phase,
143 float sl_phase,
float sr_phase,
191 for (
int ch = 0; ch <
s->nb_in_channels &&
s->level_in >= 0.f; ch++)
192 s->input_levels[ch] =
s->level_in;
195 for (
int n = 0; n <
SC_NB; n++) {
198 s->input_levels[ch] =
s->f_i[n];
206 for (
int ch = 0; ch <
s->nb_out_channels &&
s->level_out >= 0.f; ch++)
207 s->output_levels[ch] =
s->level_out;
210 for (
int n = 0; n <
SC_NB; n++) {
213 s->output_levels[ch] =
s->f_o[n];
232 0,
s->win_size, &
scale, 0);
238 if (!
s->input_levels)
255 s->lowcut = 1.f *
s->lowcutf / (inlink->
sample_rate * 0.5) * (
s->win_size / 2);
256 s->highcut = 1.f *
s->highcutf / (inlink->
sample_rate * 0.5) * (
s->win_size / 2);
276 1,
s->win_size, &iscale, 0);
282 if (!
s->output_levels)
294 if (!
s->overlap_buffer || !
s->output || !
s->output_out || !
s->output_mag ||
295 !
s->output_ph || !
s->factors || !
s->sfactors)
298 s->rdft_size =
s->win_size / 2 + 1;
302 s->l_phase =
av_calloc(
s->rdft_size,
sizeof(*
s->l_phase));
303 s->r_phase =
av_calloc(
s->rdft_size,
sizeof(*
s->r_phase));
305 s->c_phase =
av_calloc(
s->rdft_size,
sizeof(*
s->c_phase));
306 s->mag_total =
av_calloc(
s->rdft_size,
sizeof(*
s->mag_total));
307 s->lfe_mag =
av_calloc(
s->rdft_size,
sizeof(*
s->lfe_mag));
308 s->lfe_phase =
av_calloc(
s->rdft_size,
sizeof(*
s->lfe_phase));
309 if (!
s->x_pos || !
s->y_pos || !
s->l_phase || !
s->r_phase || !
s->lfe_phase ||
310 !
s->c_phase || !
s->mag_total || !
s->lfe_mag || !
s->c_mag)
326#define MIN_MAG_SUM 0.00000001f
330 float reference,
r,
a;
335 reference = angle *
M_PIf / 180.f;
361 r =
av_clipf(hypotf(*x, *y) / ra, 0.f, 1.f);
362 r = focus > 0.f ? 1.f -
powf(1.f -
r, 1.f + focus * 20.f) :
powf(
r, 1.f - focus * 20.f);
376static inline void get_lfe(
int output_lfe,
int n,
float lowcut,
float highcut,
377 float *lfe_mag,
float c_mag,
float *mag_total,
int lfe_mode)
379 if (output_lfe && n < highcut) {
380 *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+
cosf(
M_PIf*(lowcut-n)/(lowcut-highcut)));
383 *mag_total -= *lfe_mag;
390 dst[2 * n ] = mag * cosf(ph); \
391 dst[2 * n + 1] = mag * sinf(ph);
396 float *
factor = (
float *)
s->factors->extended_data[ch];
397 const float f_x =
s->f_x[
sc_map[chan >= 0 ? chan : 0]];
398 const float f_y =
s->f_y[
sc_map[chan >= 0 ? chan : 0]];
399 const int rdft_size =
s->rdft_size;
400 const float *x =
s->x_pos;
401 const float *y =
s->y_pos;
405 for (
int n = 0; n < rdft_size; n++)
409 for (
int n = 0; n < rdft_size; n++)
410 factor[n] =
powf(.5f * ( x[n] + 1.f), f_x) *
powf((y[n] + 1.f) * .5f, f_y);
413 for (
int n = 0; n < rdft_size; n++)
414 factor[n] =
powf(.5f * (-x[n] + 1.f), f_x) *
powf((y[n] + 1.f) * .5f, f_y);
417 for (
int n = 0; n < rdft_size; n++)
421 for (
int n = 0; n < rdft_size; n++)
425 for (
int n = 0; n < rdft_size; n++)
426 factor[n] =
powf(.5f * ( x[n] + 1.f), f_x) *
powf(1.f - ((y[n] + 1.f) * .5f), f_y);
429 for (
int n = 0; n < rdft_size; n++)
430 factor[n] =
powf(.5f * (-x[n] + 1.f), f_x) *
powf(1.f - ((y[n] + 1.f) * .5f), f_y);
433 for (
int n = 0; n < rdft_size; n++)
437 for (
int n = 0; n < rdft_size; n++)
441 for (
int n = 0; n < rdft_size; n++)
450 float *sfactor = (
float *)
s->sfactors->extended_data[ch];
451 float *
factor = (
float *)
s->factors->extended_data[ch];
452 float *omag = (
float *)
s->output_mag->extended_data[ch];
453 float *oph = (
float *)
s->output_ph->extended_data[ch];
454 float *
dst = (
float *)
s->output->extended_data[ch];
455 const int rdft_size =
s->rdft_size;
456 const float smooth =
s->smooth;
459 for (
int n = 0; n < rdft_size; n++)
465 for (
int n = 0; n < rdft_size; n++)
468 for (
int n = 0; n < rdft_size; n++) {
469 const float mag = omag[n];
470 const float ph = oph[n];
479 float *omag = (
float *)
s->output_mag->extended_data[ch];
480 float *oph = (
float *)
s->output_ph->extended_data[ch];
481 const float *mag_total =
s->mag_total;
482 const int rdft_size =
s->rdft_size;
483 const float *c_phase =
s->c_phase;
484 const float *l_phase =
s->l_phase;
485 const float *r_phase =
s->r_phase;
486 const float *lfe_mag =
s->lfe_mag;
487 const float *c_mag =
s->c_mag;
491 memcpy(omag, c_mag, rdft_size *
sizeof(*omag));
494 memcpy(omag, lfe_mag, rdft_size *
sizeof(*omag));
503 memcpy(omag, mag_total, rdft_size *
sizeof(*omag));
513 memcpy(oph, c_phase, rdft_size *
sizeof(*oph));
518 memcpy(oph, l_phase, rdft_size *
sizeof(*oph));
523 memcpy(oph, r_phase, rdft_size *
sizeof(*oph));
546 float *omag = (
float *)
s->output_mag->extended_data[ch];
547 float *oph = (
float *)
s->output_ph->extended_data[ch];
548 const float *mag_total =
s->mag_total;
549 const float *lfe_phase =
s->lfe_phase;
550 const int rdft_size =
s->rdft_size;
551 const float *c_phase =
s->c_phase;
552 const float *l_phase =
s->l_phase;
553 const float *r_phase =
s->r_phase;
554 const float *lfe_mag =
s->lfe_mag;
555 const float *c_mag =
s->c_mag;
568 memcpy(omag, c_mag, rdft_size *
sizeof(*omag));
571 memcpy(omag, lfe_mag, rdft_size *
sizeof(*omag));
580 memcpy(omag, mag_total, rdft_size *
sizeof(*omag));
588 memcpy(oph, lfe_phase, rdft_size *
sizeof(*oph));
592 memcpy(oph, c_phase, rdft_size *
sizeof(*oph));
597 memcpy(oph, l_phase, rdft_size *
sizeof(*oph));
602 memcpy(oph, r_phase, rdft_size *
sizeof(*oph));
631 float c_re,
float c_im,
632 float mag_totall,
float mag_totalr,
633 float fl_phase,
float fr_phase,
634 float bl_phase,
float br_phase,
635 float sl_phase,
float sr_phase,
640 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
641 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
642 float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5f;
645 dstl = (
float *)
s->output->extended_data[0];
646 dstr = (
float *)
s->output->extended_data[1];
647 dstc = (
float *)
s->output->extended_data[2];
648 dstlfe = (
float *)
s->output->extended_data[3];
649 dstlb = (
float *)
s->output->extended_data[4];
650 dstrb = (
float *)
s->output->extended_data[5];
651 dstls = (
float *)
s->output->extended_data[6];
652 dstrs = (
float *)
s->output->extended_data[7];
654 c_phase =
atan2f(c_im, c_re);
656 get_lfe(
s->output_lfe, n,
s->lowcut,
s->highcut, &lfe_mag, hypotf(c_re, c_im), &mag_total,
s->lfe_mode);
658 fl_mag =
powf(.5f * (xl + 1.f),
s->f_x[
SC_FL]) *
powf((yl + 1.f) * .5f,
s->f_y[
SC_FL]) * mag_totall;
659 fr_mag =
powf(.5f * (xr + 1.f),
s->f_x[
SC_FR]) *
powf((yr + 1.f) * .5f,
s->f_y[
SC_FR]) * mag_totalr;
660 lb_mag =
powf(.5f * (-xl + 1.f),
s->f_x[
SC_BL]) *
powf((yl + 1.f) * .5f,
s->f_y[
SC_BL]) * mag_totall;
661 rb_mag =
powf(.5f * (-xr + 1.f),
s->f_x[
SC_BR]) *
powf((yr + 1.f) * .5f,
s->f_y[
SC_BR]) * mag_totalr;
665 dstl[2 * n ] = fl_mag *
cosf(fl_phase);
666 dstl[2 * n + 1] = fl_mag *
sinf(fl_phase);
668 dstr[2 * n ] = fr_mag *
cosf(fr_phase);
669 dstr[2 * n + 1] = fr_mag *
sinf(fr_phase);
672 dstc[2 * n + 1] = c_im;
674 dstlfe[2 * n ] = lfe_mag *
cosf(c_phase);
675 dstlfe[2 * n + 1] = lfe_mag *
sinf(c_phase);
677 dstlb[2 * n ] = lb_mag *
cosf(bl_phase);
678 dstlb[2 * n + 1] = lb_mag *
sinf(bl_phase);
680 dstrb[2 * n ] = rb_mag *
cosf(br_phase);
681 dstrb[2 * n + 1] = rb_mag *
sinf(br_phase);
683 dstls[2 * n ] = ls_mag *
cosf(sl_phase);
684 dstls[2 * n + 1] = ls_mag *
sinf(sl_phase);
686 dstrs[2 * n ] = rs_mag *
cosf(sr_phase);
687 dstrs[2 * n + 1] = rs_mag *
sinf(sr_phase);
691 float c_re,
float c_im,
692 float lfe_re,
float lfe_im,
693 float mag_totall,
float mag_totalr,
694 float fl_phase,
float fr_phase,
695 float bl_phase,
float br_phase,
696 float sl_phase,
float sr_phase,
701 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
702 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
705 dstl = (
float *)
s->output->extended_data[0];
706 dstr = (
float *)
s->output->extended_data[1];
707 dstc = (
float *)
s->output->extended_data[2];
708 dstlfe = (
float *)
s->output->extended_data[3];
709 dstlb = (
float *)
s->output->extended_data[4];
710 dstrb = (
float *)
s->output->extended_data[5];
711 dstls = (
float *)
s->output->extended_data[6];
712 dstrs = (
float *)
s->output->extended_data[7];
714 fl_mag =
powf(.5f * (xl + 1.f),
s->f_x[
SC_FL]) *
powf((yl + 1.f) * .5f,
s->f_y[
SC_FL]) * mag_totall;
715 fr_mag =
powf(.5f * (xr + 1.f),
s->f_x[
SC_FR]) *
powf((yr + 1.f) * .5f,
s->f_y[
SC_FR]) * mag_totalr;
716 lb_mag =
powf(.5f * (-xl + 1.f),
s->f_x[
SC_BL]) *
powf((yl + 1.f) * .5f,
s->f_y[
SC_BL]) * mag_totall;
717 rb_mag =
powf(.5f * (-xr + 1.f),
s->f_x[
SC_BR]) *
powf((yr + 1.f) * .5f,
s->f_y[
SC_BR]) * mag_totalr;
721 dstl[2 * n ] = fl_mag *
cosf(fl_phase);
722 dstl[2 * n + 1] = fl_mag *
sinf(fl_phase);
724 dstr[2 * n ] = fr_mag *
cosf(fr_phase);
725 dstr[2 * n + 1] = fr_mag *
sinf(fr_phase);
728 dstc[2 * n + 1] = c_im;
730 dstlfe[2 * n ] = lfe_re;
731 dstlfe[2 * n + 1] = lfe_im;
733 dstlb[2 * n ] = lb_mag *
cosf(bl_phase);
734 dstlb[2 * n + 1] = lb_mag *
sinf(bl_phase);
736 dstrb[2 * n ] = rb_mag *
cosf(br_phase);
737 dstrb[2 * n + 1] = rb_mag *
sinf(br_phase);
739 dstls[2 * n ] = ls_mag *
cosf(sl_phase);
740 dstls[2 * n + 1] = ls_mag *
sinf(sl_phase);
742 dstrs[2 * n ] = rs_mag *
cosf(sr_phase);
743 dstrs[2 * n + 1] = rs_mag *
sinf(sr_phase);
749 const float *srcl = (
const float *)
s->input->extended_data[0];
750 const float *srcr = (
const float *)
s->input->extended_data[1];
751 const int output_lfe =
s->output_lfe &&
s->create_lfe;
752 const int rdft_size =
s->rdft_size;
753 const int lfe_mode =
s->lfe_mode;
754 const float highcut =
s->highcut;
755 const float lowcut =
s->lowcut;
756 const float angle =
s->angle;
757 const float focus =
s->focus;
758 float *magtotal =
s->mag_total;
759 float *lfemag =
s->lfe_mag;
760 float *lphase =
s->l_phase;
761 float *rphase =
s->r_phase;
762 float *cphase =
s->c_phase;
763 float *cmag =
s->c_mag;
764 float *xpos =
s->x_pos;
765 float *ypos =
s->y_pos;
767 for (
int n = 0; n < rdft_size; n++) {
768 float l_re = srcl[2 * n], r_re = srcr[2 * n];
769 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
770 float c_phase =
atan2f(l_im + r_im, l_re + r_re);
771 float l_mag = hypotf(l_re, l_im);
772 float r_mag = hypotf(r_re, r_im);
773 float mag_total = hypotf(l_mag, r_mag);
774 float l_phase =
atan2f(l_im, l_re);
775 float r_phase =
atan2f(r_im, r_re);
776 float phase_dif =
fabsf(l_phase - r_phase);
777 float mag_sum = l_mag + r_mag;
778 float c_mag = mag_sum * 0.5f;
782 mag_dif = (l_mag - r_mag) / mag_sum;
783 if (phase_dif >
M_PIf)
784 phase_dif = 2.f *
M_PIf - phase_dif;
789 get_lfe(output_lfe, n, lowcut, highcut, &lfemag[n], c_mag, &mag_total, lfe_mode);
797 magtotal[n] = mag_total;
804 const float *srcl = (
const float *)
s->input->extended_data[0];
805 const float *srcr = (
const float *)
s->input->extended_data[1];
806 const float *srclfe = (
const float *)
s->input->extended_data[2];
807 const int rdft_size =
s->rdft_size;
808 const float angle =
s->angle;
809 const float focus =
s->focus;
810 float *magtotal =
s->mag_total;
811 float *lfephase =
s->lfe_phase;
812 float *lfemag =
s->lfe_mag;
813 float *lphase =
s->l_phase;
814 float *rphase =
s->r_phase;
815 float *cphase =
s->c_phase;
816 float *cmag =
s->c_mag;
817 float *xpos =
s->x_pos;
818 float *ypos =
s->y_pos;
820 for (
int n = 0; n < rdft_size; n++) {
821 float l_re = srcl[2 * n], r_re = srcr[2 * n];
822 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
823 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
824 float c_phase =
atan2f(l_im + r_im, l_re + r_re);
825 float l_mag = hypotf(l_re, l_im);
826 float r_mag = hypotf(r_re, r_im);
827 float lfe_mag = hypotf(lfe_re, lfe_im);
828 float lfe_phase =
atan2f(lfe_im, lfe_re);
829 float mag_total = hypotf(l_mag, r_mag);
830 float l_phase =
atan2f(l_im, l_re);
831 float r_phase =
atan2f(r_im, r_re);
832 float phase_dif =
fabsf(l_phase - r_phase);
833 float mag_sum = l_mag + r_mag;
834 float c_mag = mag_sum * 0.5f;
838 mag_dif = (l_mag - r_mag) / mag_sum;
839 if (phase_dif >
M_PIf)
840 phase_dif = 2.f *
M_PIf - phase_dif;
853 lfephase[n] = lfe_phase;
854 magtotal[n] = mag_total;
861 const float *srcl = (
const float *)
s->input->extended_data[0];
862 const float *srcr = (
const float *)
s->input->extended_data[1];
863 const float *srcc = (
const float *)
s->input->extended_data[2];
864 const int output_lfe =
s->output_lfe &&
s->create_lfe;
865 const int rdft_size =
s->rdft_size;
866 const int lfe_mode =
s->lfe_mode;
867 const float highcut =
s->highcut;
868 const float lowcut =
s->lowcut;
869 const float angle =
s->angle;
870 const float focus =
s->focus;
871 float *magtotal =
s->mag_total;
872 float *lfemag =
s->lfe_mag;
873 float *lphase =
s->l_phase;
874 float *rphase =
s->r_phase;
875 float *cphase =
s->c_phase;
876 float *cmag =
s->c_mag;
877 float *xpos =
s->x_pos;
878 float *ypos =
s->y_pos;
880 for (
int n = 0; n < rdft_size; n++) {
881 float l_re = srcl[2 * n], r_re = srcr[2 * n];
882 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
883 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
884 float c_phase =
atan2f(c_im, c_re);
885 float c_mag = hypotf(c_re, c_im);
886 float l_mag = hypotf(l_re, l_im);
887 float r_mag = hypotf(r_re, r_im);
888 float mag_total = hypotf(l_mag, r_mag);
889 float l_phase =
atan2f(l_im, l_re);
890 float r_phase =
atan2f(r_im, r_re);
891 float phase_dif =
fabsf(l_phase - r_phase);
892 float mag_sum = l_mag + r_mag;
896 mag_dif = (l_mag - r_mag) / mag_sum;
897 if (phase_dif >
M_PIf)
898 phase_dif = 2.f *
M_PIf - phase_dif;
903 get_lfe(output_lfe, n, lowcut, highcut, &lfemag[n], c_mag, &mag_total, lfe_mode);
911 magtotal[n] = mag_total;
918 const int rdft_size =
s->rdft_size;
919 float *srcl, *srcr, *srcc, *srcsl, *srcsr;
922 srcl = (
float *)
s->input->extended_data[0];
923 srcr = (
float *)
s->input->extended_data[1];
924 srcc = (
float *)
s->input->extended_data[2];
925 srcsl = (
float *)
s->input->extended_data[3];
926 srcsr = (
float *)
s->input->extended_data[4];
928 for (n = 0; n < rdft_size; n++) {
929 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
930 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
931 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
932 float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
933 float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
934 float fl_mag = hypotf(fl_re, fl_im);
935 float fr_mag = hypotf(fr_re, fr_im);
936 float fl_phase =
atan2f(fl_im, fl_re);
937 float fr_phase =
atan2f(fr_im, fr_re);
938 float sl_mag = hypotf(sl_re, sl_im);
939 float sr_mag = hypotf(sr_re, sr_im);
940 float sl_phase =
atan2f(sl_im, sl_re);
941 float sr_phase =
atan2f(sr_im, sr_re);
942 float phase_difl =
fabsf(fl_phase - sl_phase);
943 float phase_difr =
fabsf(fr_phase - sr_phase);
944 float magl_sum = fl_mag + sl_mag;
945 float magr_sum = fr_mag + sr_mag;
948 float mag_totall = hypotf(fl_mag, sl_mag);
949 float mag_totalr = hypotf(fr_mag, sr_mag);
950 float bl_phase =
atan2f(fl_im + sl_im, fl_re + sl_re);
951 float br_phase =
atan2f(fr_im + sr_im, fr_re + sr_re);
955 if (phase_difl >
M_PIf)
956 phase_difl = 2.f *
M_PIf - phase_difl;
958 if (phase_difr >
M_PIf)
959 phase_difr = 2.f *
M_PIf - phase_difr;
964 s->upmix_5_0(
ctx, c_re, c_im,
965 mag_totall, mag_totalr,
976 const int rdft_size =
s->rdft_size;
977 float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
980 srcl = (
float *)
s->input->extended_data[0];
981 srcr = (
float *)
s->input->extended_data[1];
982 srcc = (
float *)
s->input->extended_data[2];
983 srclfe = (
float *)
s->input->extended_data[3];
984 srcsl = (
float *)
s->input->extended_data[4];
985 srcsr = (
float *)
s->input->extended_data[5];
987 for (n = 0; n < rdft_size; n++) {
988 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
989 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
990 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
991 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
992 float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
993 float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
994 float fl_mag = hypotf(fl_re, fl_im);
995 float fr_mag = hypotf(fr_re, fr_im);
996 float fl_phase =
atan2f(fl_im, fl_re);
997 float fr_phase =
atan2f(fr_im, fr_re);
998 float sl_mag = hypotf(sl_re, sl_im);
999 float sr_mag = hypotf(sr_re, sr_im);
1000 float sl_phase =
atan2f(sl_im, sl_re);
1001 float sr_phase =
atan2f(sr_im, sr_re);
1002 float phase_difl =
fabsf(fl_phase - sl_phase);
1003 float phase_difr =
fabsf(fr_phase - sr_phase);
1004 float magl_sum = fl_mag + sl_mag;
1005 float magr_sum = fr_mag + sr_mag;
1006 float mag_difl = magl_sum <
MIN_MAG_SUM ?
FFDIFFSIGN(fl_mag, sl_mag) : (fl_mag - sl_mag) / magl_sum;
1007 float mag_difr = magr_sum <
MIN_MAG_SUM ?
FFDIFFSIGN(fr_mag, sr_mag) : (fr_mag - sr_mag) / magr_sum;
1008 float mag_totall = hypotf(fl_mag, sl_mag);
1009 float mag_totalr = hypotf(fr_mag, sr_mag);
1010 float bl_phase =
atan2f(fl_im + sl_im, fl_re + sl_re);
1011 float br_phase =
atan2f(fr_im + sr_im, fr_re + sr_re);
1015 if (phase_difl >
M_PIf)
1016 phase_difl = 2.f *
M_PIf - phase_difl;
1018 if (phase_difr >
M_PIf)
1019 phase_difr = 2.f *
M_PIf - phase_difr;
1024 s->upmix_5_1(
ctx, c_re, c_im, lfe_re, lfe_im,
1025 mag_totall, mag_totalr,
1036 const int rdft_size =
s->rdft_size;
1037 float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
1040 srcl = (
float *)
s->input->extended_data[0];
1041 srcr = (
float *)
s->input->extended_data[1];
1042 srcc = (
float *)
s->input->extended_data[2];
1043 srclfe = (
float *)
s->input->extended_data[3];
1044 srcbl = (
float *)
s->input->extended_data[4];
1045 srcbr = (
float *)
s->input->extended_data[5];
1047 for (n = 0; n < rdft_size; n++) {
1048 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
1049 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
1050 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
1051 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
1052 float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
1053 float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
1054 float fl_mag = hypotf(fl_re, fl_im);
1055 float fr_mag = hypotf(fr_re, fr_im);
1056 float fl_phase =
atan2f(fl_im, fl_re);
1057 float fr_phase =
atan2f(fr_im, fr_re);
1058 float bl_mag = hypotf(bl_re, bl_im);
1059 float br_mag = hypotf(br_re, br_im);
1060 float bl_phase =
atan2f(bl_im, bl_re);
1061 float br_phase =
atan2f(br_im, br_re);
1062 float phase_difl =
fabsf(fl_phase - bl_phase);
1063 float phase_difr =
fabsf(fr_phase - br_phase);
1064 float magl_sum = fl_mag + bl_mag;
1065 float magr_sum = fr_mag + br_mag;
1066 float mag_difl = magl_sum <
MIN_MAG_SUM ?
FFDIFFSIGN(fl_mag, bl_mag) : (fl_mag - bl_mag) / magl_sum;
1067 float mag_difr = magr_sum <
MIN_MAG_SUM ?
FFDIFFSIGN(fr_mag, br_mag) : (fr_mag - br_mag) / magr_sum;
1068 float mag_totall = hypotf(fl_mag, bl_mag);
1069 float mag_totalr = hypotf(fr_mag, br_mag);
1070 float sl_phase =
atan2f(fl_im + bl_im, fl_re + bl_re);
1071 float sr_phase =
atan2f(fr_im + br_im, fr_re + br_re);
1075 if (phase_difl >
M_PIf)
1076 phase_difl = 2.f *
M_PIf - phase_difl;
1078 if (phase_difr >
M_PIf)
1079 phase_difr = 2.f *
M_PIf - phase_difr;
1084 s->upmix_5_1(
ctx, c_re, c_im, lfe_re, lfe_im,
1085 mag_totall, mag_totalr,
1097 if (
s->all_x >= 0.f)
1098 for (
int n = 0; n <
SC_NB; n++)
1099 s->f_x[n] =
s->all_x;
1101 if (
s->all_y >= 0.f)
1102 for (
int n = 0; n <
SC_NB; n++)
1103 s->f_y[n] =
s->all_y;
1110 int64_t in_channel_layout, out_channel_layout;
1111 char in_name[128], out_name[128];
1114 if (
s->lowcutf >=
s->highcutf) {
1116 s->lowcutf,
s->highcutf);
1121 s->in_ch_layout.u.mask : 0;
1123 s->out_ch_layout.u.mask : 0;
1128 switch (out_channel_layout) {
1153 switch (in_channel_layout) {
1168 switch (out_channel_layout) {
1178 switch (out_channel_layout) {
1188 switch (out_channel_layout) {
1205 s->window_func_lut =
av_calloc(
s->win_size,
sizeof(*
s->window_func_lut));
1206 if (!
s->window_func_lut)
1210 if (
s->overlap == 1)
1211 s->overlap = overlap;
1213 for (
int i = 0;
i <
s->win_size;
i++)
1214 s->window_func_lut[
i] =
sqrtf(
s->window_func_lut[
i] /
s->win_size);
1215 s->hop_size =
FFMAX(1,
s->win_size * (1. -
s->overlap));
1218 float max = 0.f, *temp_lut =
av_calloc(
s->win_size,
sizeof(*temp_lut));
1222 for (
int j = 0; j <
s->win_size; j +=
s->hop_size) {
1223 for (
int i = 0;
i <
s->win_size;
i++)
1224 temp_lut[(
i + j) %
s->win_size] +=
s->window_func_lut[
i];
1227 for (
int i = 0;
i <
s->win_size;
i++)
1231 s->win_gain = 1.f / (
max *
sqrtf(
s->win_size));
1242 float *
src = (
float *)
s->input_in->extended_data[ch];
1243 float *
win = (
float *)
s->window->extended_data[ch];
1244 const float *window_func_lut =
s->window_func_lut;
1245 const int offset =
s->win_size -
s->hop_size;
1246 const float level_in =
s->input_levels[ch];
1247 const int win_size =
s->win_size;
1253 for (
int n = 0; n < win_size; n++)
1254 win[n] =
src[n] * window_func_lut[n] * level_in;
1256 s->tx_fn(
s->rdft[ch], (
float *)
s->input->extended_data[ch],
win,
sizeof(
float));
1267 for (
int ch = start; ch < end; ch++)
1276 const float level_out =
s->output_levels[ch] *
s->win_gain;
1277 const float *window_func_lut =
s->window_func_lut;
1278 const int win_size =
s->win_size;
1281 dst = (
float *)
s->output_out->extended_data[ch];
1282 ptr = (
float *)
s->overlap_buffer->extended_data[ch];
1285 memmove(
s->overlap_buffer->extended_data[ch],
1286 s->overlap_buffer->extended_data[ch] +
s->hop_size *
sizeof(
float),
1287 s->win_size *
sizeof(
float));
1288 memset(
s->overlap_buffer->extended_data[ch] +
s->win_size *
sizeof(
float),
1289 0,
s->hop_size *
sizeof(
float));
1291 for (
int n = 0; n < win_size; n++)
1292 ptr[n] +=
dst[n] * window_func_lut[n] * level_out;
1294 ptr = (
float *)
s->overlap_buffer->extended_data[ch];
1295 dst = (
float *)
out->extended_data[ch];
1296 memcpy(
dst, ptr,
s->hop_size *
sizeof(
float));
1305 const int start =
ff_slice_pos(
out->ch_layout.nb_channels, jobnr, nb_jobs);
1306 const int end =
ff_slice_pos(
out->ch_layout.nb_channels, jobnr + 1, nb_jobs);
1308 for (
int ch = start; ch < end; ch++) {
1351 int ret = 0, status;
1395 for (
int ch = 0; ch <
s->nb_in_channels; ch++)
1397 for (
int ch = 0; ch <
s->nb_out_channels; ch++)
1417 char *res,
int res_len,
int flags)
1426 s->hop_size =
FFMAX(1,
s->win_size * (1. -
s->overlap));
1435#define OFFSET(x) offsetof(AudioSurroundContext, x)
1436#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1437#define TFLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1449 {
"sub",
"subtract LFE channel with others", 0,
AV_OPT_TYPE_CONST, {.i64=1}, 0, 1,
TFLAGS, .unit =
"lfe_mode" },
1514 .p.name =
"surround",
1516 .p.priv_class = &surround_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static float win(SuperEqualizerContext *s, float n, int N)
static void focus_transform(float *x, float *y, float focus)
static void do_transform(AVFilterContext *ctx, int ch)
static void filter_2_1(AVFilterContext *ctx)
static void filter_5_0_side(AVFilterContext *ctx)
static int ifft_channel(AVFilterContext *ctx, AVFrame *out, int ch)
static void upmix_7_1_5_1(AVFilterContext *ctx, float c_re, float c_im, float lfe_re, float lfe_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
static const int sc_map[16]
static void stereo_position(float a, float p, float *x, float *y)
static void filter_5_1_back(AVFilterContext *ctx)
static int ifft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void stereo_copy(AVFilterContext *ctx, int ch, int chan)
static void set_input_levels(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
static void filter_5_1_side(AVFilterContext *ctx)
static void l2_1_upmix(AVFilterContext *ctx, int ch)
const FFFilter ff_af_surround
static float sqrf(float x)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int fft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void set_output_levels(AVFilterContext *ctx)
static void get_lfe(int output_lfe, int n, float lowcut, float highcut, float *lfe_mag, float c_mag, float *mag_total, int lfe_mode)
static void filter_surround(AVFilterContext *ctx)
static float r_distance(float a)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption surround_options[]
static void angle_transform(float *x, float *y, float angle)
static void stereo_upmix(AVFilterContext *ctx, int ch)
static int config_output(AVFilterLink *outlink)
static const int ch_map[SC_NB]
static void filter_stereo(AVFilterContext *ctx)
static void calculate_factors(AVFilterContext *ctx, int ch, int chan)
static void surround_upmix(AVFilterContext *ctx, int ch)
static void upmix_7_1_5_0_side(AVFilterContext *ctx, float c_re, float c_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
static int fft_channel(AVFilterContext *ctx, AVFrame *in, int ch)
static void allchannels_spread(AVFilterContext *ctx)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_inlink_queued_samples(AVFilterLink *link)
Main libavfilter public API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Public libavutil channel layout APIs header.
static __device__ float sqrtf(float a)
static __device__ float fabsf(float a)
static const uint16_t channel_layouts[7]
float fminf(float, float)
float fmaxf(float, float)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CH_LAYOUT_2POINT1
#define AV_CH_LAYOUT_QUAD
#define AV_CH_LAYOUT_6POINT1
#define AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_6POINT0
#define AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_7POINT1
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_OCTAGONAL
#define AV_CH_LAYOUT_5POINT0_BACK
#define AV_CH_LAYOUT_7POINT0
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_4POINT1
#define AV_CH_LAYOUT_3POINT1
#define AV_CH_LAYOUT_5POINT1_BACK
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
static const int factor[16]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FFDIFFSIGN(x, y)
Comparator.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
enum MovChannelLayoutTag * layouts
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
AVFilterContext * src
source filter
int sample_rate
samples per second
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
AVChannelLayout ch_layout
Channel layout of the audio data.
uint8_t ** extended_data
pointers to the data planes/channels.
void(* filter)(AVFilterContext *ctx)
AVChannelLayout in_ch_layout
void(* upmix_5_0)(AVFilterContext *ctx, float c_re, float c_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
void(* upmix)(AVFilterContext *ctx, int ch)
void(* upmix_5_1)(AVFilterContext *ctx, float c_re, float c_im, float lfe_re, float lfe_im, float mag_totall, float mag_totalr, float fl_phase, float fr_phase, float bl_phase, float br_phase, float sl_phase, float sr_phase, float xl, float yl, float xr, float yr, int n)
AVChannelLayout out_ch_layout
#define av_malloc_array(a, b)
static AVFormatContext * ctx
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *values)
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
static void generate_window_func(float *lut, int N, int win_func, float *overlap)