pns: fix decoding window offset clamping for short sequences - #237
Merged
Conversation
In pns_decode(), band offsets (begin/end) were clamped against ics->swb_offset_max. For EIGHT_SHORT_SEQUENCE frames, swb_offset_max represents the offset limit of a single short window (frame_len / 8), rather than the entire spectral buffer. Because `base = group * nshort` exceeds swb_offset_max for all window groups past the first, clamping against swb_offset_max collapsed (base + swb_offset[sfb]) to swb_offset_max regardless of sfb. This resulted in `begin == end`, silently dropping PNS noise generation for 7 out of 8 window groups in short-window frames. Fix this by clamping band offsets against frame_len instead, matching the actual memory bound of the target spectrum buffer.
nschimme
force-pushed
the
fix-pns-noise-dropout
branch
from
August 27, 2026 03:35
631c903 to
dade5fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug in
pns_decode()where Perceptual Noise Substitution (PNS) band bounds (begin/end) were incorrectly clamped againstics->swb_offset_maxinstead of the full buffer size (frame_len).For
EIGHT_SHORT_SEQUENCEframes,swb_offset_maxspans only a single short window (frame_len / 8). As a result,base = group * nshortevaluated to>= swb_offset_maxfor every window group after the first. Clamping againstswb_offset_maxcausedmin(base + swb_offset[sfb], swb_offset_max)to collapse toswb_offset_max, resulting inbegin == endand silently skipping PNS noise generation across 7 of the 8 window groups in short frames.Fix: Clamp band offsets against
frame_len(already passed intopns_decode()) to reflect the actual bounds of the spectral array.Fixes #191
Verification & Benchmark Results
Tested on a low-bitrate FAAC-encoded AAC-LC stream (32kbps, PNS enabled, using short-window block switching):
afconvert(ref)ffmpegand Appleafconvert).--pns 0) yields identical PCM output betweenfaad2andffmpeg.Test Plan