History

avfilter/af_surround: add angle option

Paul B Mahol committed 7 years ago

Commit e1e0f941 parent e1cfb012 files · +29 −0Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/af_surround.c+25−0
@@ -56,6 +56,7 @@ typedef struct AudioSurroundContext { · 55 unmodified lines
5656 float lfe_in;
5757 float lfe_out;
5858 int lfe_mode;
59+ float angle;
5960 int win_size;
6061 int win_func;
6162 float overlap;
@@ -312,6 +313,26 @@ static int config_output(AVFilterLink *outlink) · 250 unmodified lines
312313 return 0;
313314 }
314315
316+static void stereo_transform(float *x, float *y, float angle)
317+{
318+ float reference, r, a;
319+
320+ if (angle == 90.f)
321+ return;
322+
323+ reference = angle * M_PI / 180.f;
324+ r = hypotf(*x, *y);
325+ a = atan2f(*x, *y);
326+
327+ if (fabsf(a) <= M_PI_4)
328+ a *= reference / M_PI_2;
329+ else
330+ a = M_PI + 2 * (-2 * M_PI + reference) * (M_PI - fabsf(a)) * FFDIFFSIGN(a, 0) / (3 * M_PI);
331+
332+ *x = av_clipf(sinf(a) * r, -1, 1);
333+ *y = av_clipf(cosf(a) * r, -1, 1);
334+}
335+
315336 static void stereo_position(float a, float p, float *x, float *y)
316337 {
317338 *x = av_clipf(a+FFMAX(0, sinf(p-M_PI_2))*FFDIFFSIGN(a,0), -1, 1);
@@ -1096,6 +1117,7 @@ static void filter_stereo(AVFilterContext *ctx) · 778 unmodified lines
10961117 phase_dif = 2 * M_PI - phase_dif;
10971118
10981119 stereo_position(mag_dif, phase_dif, &x, &y);
1120+ stereo_transform(&x, &y, s->angle);
10991121
11001122 s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);
11011123 }
@@ -1131,6 +1153,7 @@ static void filter_surround(AVFilterContext *ctx) · 29 unmodified lines
11311153 phase_dif = 2 * M_PI - phase_dif;
11321154
11331155 stereo_position(mag_dif, phase_dif, &x, &y);
1156+ stereo_transform(&x, &y, s->angle);
11341157
11351158 s->upmix_3_0(ctx, l_phase, r_phase, c_phase, c_mag, mag_total, x, y, n);
11361159 }
@@ -1165,6 +1188,7 @@ static void filter_2_1(AVFilterContext *ctx) · 28 unmodified lines
11651188 phase_dif = 2 * M_PI - phase_dif;
11661189
11671190 stereo_position(mag_dif, phase_dif, &x, &y);
1191+ stereo_transform(&x, &y, s->angle);
11681192
11691193 s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
11701194 }
@@ -1674,6 +1698,7 @@ static const AVOption surround_options[] = { · 503 unmodified lines
16741698 { "lfe_mode", "set LFE channel mode", OFFSET(lfe_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
16751699 { "add", "just add LFE channel", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 1, FLAGS, "lfe_mode" },
16761700 { "sub", "substract LFE channel with others", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 1, FLAGS, "lfe_mode" },
1701+ { "angle", "set soundfield transform angle", OFFSET(angle), AV_OPT_TYPE_FLOAT, {.dbl=90}, 0, 360, FLAGS },
16771702 { "fc_in", "set front center channel input level", OFFSET(fc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
16781703 { "fc_out", "set front center channel output level", OFFSET(fc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
16791704 { "fl_in", "set front left channel input level", OFFSET(fl_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },

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