[FFmpeg-cvslog] avfilter/af_surround: scale output gain for non-default overlap
Paul B Mahol
git at videolan.org
Fri May 12 13:36:58 EEST 2023
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri May 12 12:06:23 2023 +0200| [cb4e7831e704fcb3c3eba4e7c4b3b94c81aa04e2] | committer: Paul B Mahol
avfilter/af_surround: scale output gain for non-default overlap
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cb4e7831e704fcb3c3eba4e7c4b3b94c81aa04e2
---
libavfilter/af_surround.c | 22 ++++++++++++++++++++--
1 file 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];
More information about the ffmpeg-cvslog
mailing list