History

avfilter/af_surround: scale output gain for non-default overlap

Paul B Mahol committed 3 years ago

Commit cb4e7831 parent 09cd89d1 file · +20 −2Browse files

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

Unified · Split

libavfilter/af_surround.c+20−2
@@ -74,6 +74,7 @@ typedef struct AudioSurroundContext { · 73 unmodified lines
7474 float focus;
7575 int win_size;
7676 int win_func;
77+ float win_gain;
7778 float overlap;
7879
7980 float all_x;
@@ -637,7 +638,7 @@ static void upmix_7_1_5_0_side(AVFilterContext *ctx, · 557 unmodified lines
637638 {
638639 float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
639640 float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
640− float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5;
641+ float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5f;
641642 AudioSurroundContext *s = ctx->priv;
642643
643644 dstl = (float *)s->output->extended_data[0];
@@ -1197,6 +1198,23 @@ fail: · 553 unmodified lines
11971198 s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->win_size);
11981199 s->hop_size = FFMAX(1, s->win_size * (1. - s->overlap));
11991200
1201+ {
1202+ float max = 0.f, *temp_lut = av_calloc(s->win_size, sizeof(*temp_lut));
1203+ if (!temp_lut)
1204+ return AVERROR(ENOMEM);
1205+
1206+ for (int j = 0; j < s->win_size; j += s->hop_size) {
1207+ for (int i = 0; i < s->win_size; i++)
1208+ temp_lut[(i + j) % s->win_size] += s->window_func_lut[i];
1209+ }
1210+
1211+ for (int i = 0; i < s->win_size; i++)
1212+ max = fmaxf(temp_lut[i], max);
1213+ av_freep(&temp_lut);
1214+
1215+ s->win_gain = 1.f / (max * sqrtf(s->win_size));
1216+ }
1217+
12001218 allchannels_spread(ctx);
12011219
12021220 return 0;
@@ -1237,7 +1255,7 @@ static int fft_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 34 unmodified lines
12371255 static int ifft_channel(AVFilterContext *ctx, AVFrame *out, int ch)
12381256 {
12391257 AudioSurroundContext *s = ctx->priv;
1240− const float level_out = s->output_levels[ch];
1258+ const float level_out = s->output_levels[ch] * s->win_gain;
12411259 float *dst, *ptr;
12421260
12431261 dst = (float *)s->output_out->extended_data[ch];

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