PR #25711 opened by romainhedouin URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25711 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25711.patch
noise_band_auto_var is only written, never read. Remove it, the loops that fill it, and the update_auto_var argument of set_parameters(). noise_band_auto_var was used in Paul Mahol's original implementation in 2018 and has been unused since ccb81acc3d (2022) when its last readers were removed. -O3 does not currently optimize this: with GCC, this patch makes set_parameters() go from 34 exp() call sites to 4. With tn=1:tr=1 on 5.1 audio that is about 16,000 fewer exp() calls per second of audio. The encoded output is byte-identical in 1662 option cells on 52 inputs. | configuration | RAM before | RAM after | RAM saved | |---|---|---|---| | mono 16 kHz, defaults | 8.88 MB | 8.70 MB | 0.18 MB (2.0%) | | mono 16 kHz, tn=1 | 8.90 MB | 8.70 MB | 0.20 MB (2.2%) | | stereo 48 kHz, tn=1:tr=1 | 11.80 MB | 11.76 MB | 0.03 MB (0.3%) | | 5.1 48 kHz dbl, tn=1:tr=1 | 18.09 MB | 17.89 MB | 0.20 MB (1.1%) | Noticed during a review sweep of ffmpeg using an LLM. Signed-off-by: romainhedouin <[email protected]> <!-- If this PR requires new FATE test samples, attach them to the PR and list their target paths below (relative to the fate-suite root). Attached filenames must match the sample's filename: ```fate-samples # e.g. vorbis/new-sample.ogg ``` --> >From 69c4a260a9b1ead06cb127cd8543ce8ec23cf3cd Mon Sep 17 00:00:00 2001 From: romainhedouin <[email protected]> Date: Tue, 3 Nov 2026 12:15:11 +0100 Subject: [PATCH] avfilter/af_afftdn: remove the unused noise_band_auto_var noise_band_auto_var is only written, never read. Remove it, the loops that fill it, and the update_auto_var argument of set_parameters() that only controlled those loops. The output is unchanged. Noticed during a review sweep of ffmpeg using an LLM. Signed-off-by: romainhedouin <[email protected]> --- libavfilter/af_afftdn.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/libavfilter/af_afftdn.c b/libavfilter/af_afftdn.c index 6486517781e..3e6e6f1e31f 100644 --- a/libavfilter/af_afftdn.c +++ b/libavfilter/af_afftdn.c @@ -66,7 +66,6 @@ enum NoiseType { typedef struct DeNoiseChannel { double band_noise[NB_PROFILE_BANDS]; - double noise_band_auto_var[NB_PROFILE_BANDS]; double noise_band_sample[NB_PROFILE_BANDS]; double *amt; double *band_amt; @@ -335,7 +334,7 @@ static void spectral_flatness(AudioFFTDeNoiseContext *s, const double *const spe *rden = den; } -static void set_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int update_var, int update_auto_var); +static void set_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int update_var); static double floor_offset(const double *S, int size, double mean) { @@ -403,7 +402,7 @@ static void process_frame(AVFilterContext *ctx, const double new_floor = av_clipd(10.0 * log10(den) - 100.0 + offset, -90., -20.); dnch->noise_floor = 0.1 * new_floor + dnch->noise_floor * 0.9; - set_parameters(s, dnch, 1, 1); + set_parameters(s, dnch, 1); } } @@ -536,9 +535,6 @@ static void set_band_parameters(AudioFFTDeNoiseContext *s, d4 = (m - i) / d2; dnch->rel_var[m] = exp((d5 * d3 + band_noise * d4) * C); } - - for (i = 0; i < NB_PROFILE_BANDS; i++) - dnch->noise_band_auto_var[i] = dnch->max_var * exp((process_get_band_noise(s, dnch, i) - 2.0) * C); } static void read_custom_noise(AVFilterContext *ctx, int ch) @@ -577,7 +573,7 @@ static void read_custom_noise(AVFilterContext *ctx, int ch) memcpy(dnch->band_noise, band_noise, sizeof(band_noise)); } -static void set_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int update_var, int update_auto_var) +static void set_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int update_var) { if (dnch->last_noise_floor != dnch->noise_floor) dnch->last_noise_floor = dnch->noise_floor; @@ -586,10 +582,6 @@ static void set_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int dnch->last_noise_floor = fmax(dnch->last_noise_floor, dnch->residual_floor); dnch->max_var = s->floor * exp((100.0 + dnch->last_noise_floor) * C); - if (update_auto_var) { - for (int i = 0; i < NB_PROFILE_BANDS; i++) - dnch->noise_band_auto_var[i] = dnch->max_var * exp((process_get_band_noise(s, dnch, i) - 2.0) * C); - } if (s->track_residual) { if (update_var || dnch->last_residual_floor != dnch->residual_floor) { @@ -880,7 +872,7 @@ static int config_input(AVFilterLink *inlink) dnch->noise_floor = s->noise_floor; dnch->residual_floor = s->residual_floor; - set_parameters(s, dnch, 1, 1); + set_parameters(s, dnch, 1); } s->noise_band_edge[0] = FFMIN(s->fft_length2, s->fft_length * get_band_edge(s, 0) / s->sample_rate); @@ -1001,7 +993,6 @@ static void finish_sample_noise(AudioFFTDeNoiseContext *s, dnch->noise_band_var[i] /= dnch->noise_band_norm[i]; dnch->noise_band_var[i] -= dnch->noise_band_avr[i] * dnch->noise_band_avr[i] + dnch->noise_band_avi[i] * dnch->noise_band_avi[i]; - dnch->noise_band_auto_var[i] = dnch->noise_band_var[i]; sample_noise[i] = 10.0 * log10(dnch->noise_band_var[i] / s->floor) - 100.0; } if (s->noise_band_count < NB_PROFILE_BANDS) { @@ -1152,7 +1143,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) } if (dnch->noise_floor != dnch->last_noise_floor) - set_parameters(s, dnch, 1, 0); + set_parameters(s, dnch, 1); } } @@ -1185,7 +1176,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) break; finish_sample_noise(s, dnch, sample_noise); set_noise_profile(ctx, dnch, sample_noise); - set_parameters(s, dnch, 1, 1); + set_parameters(s, dnch, 1); } s->sample_noise = 0; s->sample_noise_blocks = 0; @@ -1351,7 +1342,7 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar dnch->noise_floor = s->noise_floor; dnch->residual_floor = s->residual_floor; - set_parameters(s, dnch, 1, 1); + set_parameters(s, dnch, 1); } return 0; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
