Commit 89d34d66a6 for ffmpeg
commit 89d34d66a638b52d56023d547e785291f67efb2f
Author: romainhedouin <romain.hedouin@epitech.eu>
Date: Wed Oct 14 20:42:24 2026 +0200
avcodec/aacpsy: fix spread energy index for short windows
In psy_3gpp_analyze_channel(), the spread energy of the first band was
always stored in spread_en[0] instead of spread_en[w], unlike every
other access to spread_en[w+g]. For short windows, windows 1-7 thus
started spreading from an unset value instead of their own first band
energy. This only affects the hole avoidance decision.
Tested: make fate passes (5875 tests). Encoder output was bit-identical
before and after on luckynight_2ch_44kHz_s16.wav and on a synthetic
transient signal at 24k, 32k, 48k, 64k and 128k, so the practical
effect seems small.
Found with the help of an AI code review; verified by hand.
Signed-off-by: romainhedouin <romain.hedouin@epitech.eu>
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index ac0e17de5b..e730e621b9 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -769,7 +769,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel,
AacPsyBand *bands = &pch->band[w];
/* 5.4.2.3 "Spreading" & 5.4.3 "Spread Energy Calculation" */
- spread_en[0] = bands[0].energy;
+ spread_en[w] = bands[0].energy;
for (g = 1; g < num_bands; g++) {
bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * coeffs[g].spread_hi[0]);
spread_en[w+g] = FFMAX(bands[g].energy, spread_en[w+g-1] * coeffs[g].spread_hi[1]);