History

avfilter/af_surround: implement smooth option/support

Paul B Mahol committed 3 years ago

Commit 52291d21 parent 3d330032 files · +24 −4Browse files

Unified · Split

2 files
  1. doc/filters.texi +6 −0
  2. libavfilter/af_surround.c +18 −4
doc/filters.texi+6−0
@@ -6670,6 +6670,12 @@ In @var{add} mode, LFE channel is created from input audio and added to output. · 6669 unmodified lines
66706670 In @var{sub} mode, LFE channel is created from input audio and added to output but
66716671 also all non-LFE output channels are subtracted with output LFE channel.
66726672
6673+@item smooth
6674+Set temporal smoothness strength, used to gradually change factors when transforming
6675+stereo sound in time. Allowed range is from @var{0.0} to @var{1.0}.
6676+Useful to improve output quality with @var{focus} option values greater than @var{0.0}.
6677+Default is @var{0.0}. Only values inside this range and without edges are effective.
6678+
66736679 @item angle
66746680 Set angle of stereo surround transform, Allowed range is from @var{0} to @var{360}.
66756681 Default is @var{90}.
libavfilter/af_surround.c+18−4
@@ -69,6 +69,7 @@ typedef struct AudioSurroundContext { · 68 unmodified lines
6969 float f_i[SC_NB];
7070 float f_o[SC_NB];
7171 int lfe_mode;
72+ float smooth;
7273 float angle;
7374 float focus;
7475 int win_size;
@@ -97,6 +98,7 @@ typedef struct AudioSurroundContext { · 22 unmodified lines
9798 int nb_out_channels;
9899
99100 AVFrame *factors;
101+ AVFrame *sfactors;
100102 AVFrame *input_in;
101103 AVFrame *input;
102104 AVFrame *output;
@@ -297,13 +299,14 @@ static int config_output(AVFilterLink *outlink) · 194 unmodified lines
297299 set_output_levels(ctx);
298300
299301 s->factors = ff_get_audio_buffer(outlink, s->win_size + 2);
302+ s->sfactors = ff_get_audio_buffer(outlink, s->win_size + 2);
300303 s->output_ph = ff_get_audio_buffer(outlink, s->win_size + 2);
301304 s->output_mag = ff_get_audio_buffer(outlink, s->win_size + 2);
302305 s->output_out = ff_get_audio_buffer(outlink, s->win_size + 2);
303306 s->output = ff_get_audio_buffer(outlink, s->win_size + 2);
304307 s->overlap_buffer = ff_get_audio_buffer(outlink, s->win_size * 2);
305308 if (!s->overlap_buffer || !s->output || !s->output_out || !s->output_mag ||
306− !s->output_ph || !s->factors)
309+ !s->output_ph || !s->factors || !s->sfactors)
307310 return AVERROR(ENOMEM);
308311
309312 s->rdft_size = s->win_size / 2 + 1;
@@ -404,6 +407,7 @@ static int stereo_upmix(AVFilterContext *ctx, int ch) · 94 unmodified lines
404407 {
405408 AudioSurroundContext *s = ctx->priv;
406409 float *dst = (float *)s->output->extended_data[ch];
410+ float *sfactor = (float *)s->sfactors->extended_data[ch];
407411 float *factor = (float *)s->factors->extended_data[ch];
408412 float *omag = (float *)s->output_mag->extended_data[ch];
409413 float *oph = (float *)s->output_ph->extended_data[ch];
@@ -419,6 +423,7 @@ static int stereo_upmix(AVFilterContext *ctx, int ch) · 9 unmodified lines
419423 const int chan = av_channel_layout_channel_from_index(&s->out_ch_layout, ch);
420424 const float f_x = s->f_x[sc_map[chan]];
421425 const float f_y = s->f_y[sc_map[chan]];
426+ const float smooth = s->smooth;
422427
423428 switch (chan) {
424429 case AV_CHAN_FRONT_CENTER:
@@ -501,6 +506,13 @@ static int stereo_upmix(AVFilterContext *ctx, int ch) · 76 unmodified lines
501506 break;
502507 }
503508
509+ if (smooth > 0.f) {
510+ for (int n = 0; n < rdft_size; n++)
511+ sfactor[n] = smooth * factor[n] + (1.f - smooth) * sfactor[n];
512+
513+ factor = sfactor;
514+ }
515+
504516 for (int n = 0; n < rdft_size; n++)
505517 omag[n] *= factor[n];
506518
@@ -1076,9 +1088,9 @@ static void allchannels_spread(AVFilterContext *ctx) · 569 unmodified lines
10761088 static av_cold int init(AVFilterContext *ctx)
10771089 {
10781090 AudioSurroundContext *s = ctx->priv;
1079− float overlap;
10801091 int64_t in_channel_layout, out_channel_layout;
1081− int i, ret;
1092+ float overlap;
1093+ int ret;
10821094
10831095 if ((ret = av_channel_layout_from_string(&s->out_ch_layout, s->out_channel_layout_str)) < 0) {
10841096 av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
@@ -1203,7 +1215,7 @@ fail: · 118 unmodified lines
12031215 if (s->overlap == 1)
12041216 s->overlap = overlap;
12051217
1206− for (i = 0; i < s->win_size; i++)
1218+ for (int i = 0; i < s->win_size; i++)
12071219 s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->win_size);
12081220 s->hop_size = FFMAX(1, s->win_size * (1. - s->overlap));
12091221
@@ -1354,6 +1366,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 144 unmodified lines
13541366 AudioSurroundContext *s = ctx->priv;
13551367
13561368 av_frame_free(&s->factors);
1369+ av_frame_free(&s->sfactors);
13571370 av_frame_free(&s->window);
13581371 av_frame_free(&s->input_in);
13591372 av_frame_free(&s->input);
@@ -1417,6 +1430,7 @@ static const AVOption surround_options[] = { · 57 unmodified lines
14171430 { "lfe_mode", "set LFE channel mode", OFFSET(lfe_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, TFLAGS, "lfe_mode" },
14181431 { "add", "just add LFE channel", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 1, TFLAGS, "lfe_mode" },
14191432 { "sub", "substract LFE channel with others", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 1, TFLAGS, "lfe_mode" },
1433+ { "smooth", "set temporal smoothness strength", OFFSET(smooth), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, TFLAGS },
14201434 { "angle", "set soundfield transform angle", OFFSET(angle), AV_OPT_TYPE_FLOAT, {.dbl=90}, 0, 360, TFLAGS },
14211435 { "focus", "set soundfield transform focus", OFFSET(focus), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, TFLAGS },
14221436 { "fc_in", "set front center channel input level", OFFSET(f_i[SC_FC]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },

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