From 304efa29aeef68d4c8e2af5ab9763afe25819965 Mon Sep 17 00:00:00 2001 From: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com> Date: Sat, 5 Sep 2026 12:56:25 +0200 Subject: [PATCH] avcodec/ac3dsp: skip the inner loop for single-bin bands calculate bap directly for the first 28 bands. each contains only one coefficient. Signed-off-by: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com> --- libavcodec/ac3dsp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c index 090287e42d..385a642af1 100644 --- a/libavcodec/ac3dsp.c +++ b/libavcodec/ac3dsp.c @@ -83,8 +83,16 @@ static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, return; } - bin = start; - band = ff_ac3_bin_to_band_tab[start]; + /* the first 28 bands have one coefficient each */ + for (bin = start; bin < FFMIN(end, 28); bin++) { + int m = (FFMAX(mask[bin] - snr_offset - floor, 0) & 0x1FE0) + floor; + int address = av_clip_uintp2((psd[bin] - m) >> 5, 6); + bap[bin] = bap_tab[address]; + } + if (bin >= end) + return; + + band = ff_ac3_bin_to_band_tab[bin]; do { int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; band_end = ff_ac3_band_start_tab[++band];