+static void filter_5_0_side(AVFilterContext *ctx)
+{
+ AudioSurroundContext *s = ctx->priv;
+ float *srcl, *srcr, *srcc, *srcsl, *srcsr;
+ int n;
+
+ srcl = (float *)s->input->extended_data[0];
+ srcr = (float *)s->input->extended_data[1];
+ srcc = (float *)s->input->extended_data[2];
+ srcsl = (float *)s->input->extended_data[3];
+ srcsr = (float *)s->input->extended_data[4];
+
+ for (n = 0; n < s->buf_size; n++) {
+ float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
+ float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
+ float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
+ float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
+ float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
+ float fl_mag = hypotf(fl_re, fl_im);
+ float fr_mag = hypotf(fr_re, fr_im);
+ float fl_phase = atan2f(fl_im, fl_re);
+ float fr_phase = atan2f(fr_im, fr_re);
+ float sl_mag = hypotf(sl_re, sl_im);
+ float sr_mag = hypotf(sr_re, sr_im);
+ float sl_phase = atan2f(sl_im, sl_re);
+ float sr_phase = atan2f(sr_im, sr_re);
+ float phase_difl = fabsf(fl_phase - sl_phase);
+ float phase_difr = fabsf(fr_phase - sr_phase);
+ float mag_difl = (fl_mag - sl_mag) / (fl_mag + sl_mag);
+ float mag_difr = (fr_mag - sr_mag) / (fr_mag + sr_mag);
+ float mag_totall = hypotf(fl_mag, sl_mag);
+ float mag_totalr = hypotf(fr_mag, sr_mag);
+ float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
+ float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
+ float xl, yl;
+ float xr, yr;
+
+ if (phase_difl > M_PI)
+ phase_difl = 2 * M_PI - phase_difl;
+
+ if (phase_difr > M_PI)
+ phase_difr = 2 * M_PI - phase_difr;
+
+ stereo_position(mag_difl, phase_difl, &xl, &yl);
+ stereo_position(mag_difr, phase_difr, &xr, &yr);
+
+ s->upmix_5_0(ctx, c_re, c_im,
+ mag_totall, mag_totalr,
+ fl_phase, fr_phase,
+ bl_phase, br_phase,
+ sl_phase, sr_phase,
+ xl, yl, xr, yr, n);
+ }
+}
+
+static void filter_5_1_side(AVFilterContext *ctx)
+{
+ AudioSurroundContext *s = ctx->priv;
+ float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
+ int n;
+
+ srcl = (float *)s->input->extended_data[0];
+ srcr = (float *)s->input->extended_data[1];
+ srcc = (float *)s->input->extended_data[2];
+ srclfe = (float *)s->input->extended_data[3];
+ srcsl = (float *)s->input->extended_data[4];
+ srcsr = (float *)s->input->extended_data[5];
+
+ for (n = 0; n < s->buf_size; n++) {
+ float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
+ float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
+ float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
+ float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
+ float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
+ float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
+ float fl_mag = hypotf(fl_re, fl_im);
+ float fr_mag = hypotf(fr_re, fr_im);
+ float fl_phase = atan2f(fl_im, fl_re);
+ float fr_phase = atan2f(fr_im, fr_re);
+ float sl_mag = hypotf(sl_re, sl_im);
+ float sr_mag = hypotf(sr_re, sr_im);
+ float sl_phase = atan2f(sl_im, sl_re);
+ float sr_phase = atan2f(sr_im, sr_re);
+ float phase_difl = fabsf(fl_phase - sl_phase);
+ float phase_difr = fabsf(fr_phase - sr_phase);
+ float mag_difl = (fl_mag - sl_mag) / (fl_mag + sl_mag);
+ float mag_difr = (fr_mag - sr_mag) / (fr_mag + sr_mag);
+ float mag_totall = hypotf(fl_mag, sl_mag);
+ float mag_totalr = hypotf(fr_mag, sr_mag);
+ float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
+ float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
+ float xl, yl;
+ float xr, yr;
+
+ if (phase_difl > M_PI)
+ phase_difl = 2 * M_PI - phase_difl;
+
+ if (phase_difr > M_PI)
+ phase_difr = 2 * M_PI - phase_difr;
+
+ stereo_position(mag_difl, phase_difl, &xl, &yl);
+ stereo_position(mag_difr, phase_difr, &xr, &yr);
+
+ s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
+ mag_totall, mag_totalr,
+ fl_phase, fr_phase,
+ bl_phase, br_phase,
+ sl_phase, sr_phase,
+ xl, yl, xr, yr, n);
+ }
+}
+