aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-05-12 12:06:23 +0200
committerPaul B Mahol <onemda@gmail.com>2023-05-12 12:33:33 +0200
commitcb4e7831e704fcb3c3eba4e7c4b3b94c81aa04e2 (patch)
tree5f09811d826bbe7d00b4eee8365143159fe38a49
parent09cd89df27a97cb1946f0edacc4054f8dcb766b1 (diff)
downloadffmpeg-cb4e7831e704fcb3c3eba4e7c4b3b94c81aa04e2.tar.gz
avfilter/af_surround: scale output gain for non-default overlap
-rw-r--r--libavfilter/af_surround.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c
index 682c1f5dcb..0b88ac418b 100644
--- a/libavfilter/af_surround.c
+++ b/libavfilter/af_surround.c
@@ -74,6 +74,7 @@ typedef struct AudioSurroundContext {
float focus;
int win_size;
int win_func;
+ float win_gain;
float overlap;
float all_x;
@@ -637,7 +638,7 @@ static void upmix_7_1_5_0_side(AVFilterContext *ctx,
{
float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
- float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5;
+ float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5f;
AudioSurroundContext *s = ctx->priv;
dstl = (float *)s->output->extended_data[0];
@@ -1197,6 +1198,23 @@ fail:
s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->win_size);
s->hop_size = FFMAX(1, s->win_size * (1. - s->overlap));
+ {
+ float max = 0.f, *temp_lut = av_calloc(s->win_size, sizeof(*temp_lut));
+ if (!temp_lut)
+ return AVERROR(ENOMEM);
+
+ for (int j = 0; j < s->win_size; j += s->hop_size) {
+ for (int i = 0; i < s->win_size; i++)
+ temp_lut[(i + j) % s->win_size] += s->window_func_lut[i];
+ }
+
+ for (int i = 0; i < s->win_size; i++)
+ max = fmaxf(temp_lut[i], max);
+ av_freep(&temp_lut);
+
+ s->win_gain = 1.f / (max * sqrtf(s->win_size));
+ }
+
allchannels_spread(ctx);
return 0;
@@ -1237,7 +1255,7 @@ static int fft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int ifft_channel(AVFilterContext *ctx, AVFrame *out, int ch)
{
AudioSurroundContext *s = ctx->priv;
- const float level_out = s->output_levels[ch];
+ const float level_out = s->output_levels[ch] * s->win_gain;
float *dst, *ptr;
dst = (float *)s->output_out->extended_data[ch];