Repository navigation
Drop encoder priming and padding for gapless playback - #144
Open
chrizzchrizz wants to merge 3 commits into
Open
chrizzchrizz wants to merge 3 commits into
chrizzchrizz wants to merge 3 commits into
Conversation
Decoders output the encoder delay (priming) and padding (remainder) of formats like AAC and MP3 as audio. The packet table info was only used for the duration, so consecutive entries were separated by a short silence (2112 + remainder frames, about 50 ms, for AAC). - Keep only the decoded frames in [priming, priming + valid) while the decoded position is exact (decoding from the start of the stream) - After a seek, drop the remainder at the end of the stream instead - Frame counts are converted to the output sample rate
chrizzchrizz
marked this pull request as draft
October 15, 2026 08:07
- Mark the decoded position as inexact when re-reading from a seek offset (reset(decodedPositionExact:)), so mid-stream data isn't trimmed as the start - Fall back to trailing-only trimming when packet table info arrives late - Account for frames after a fully filled decode so they aren't overwritten - Pass the EOF entry to trimTrailingGaplessPadding instead of looking it up - Extract the trim math into GaplessTrim and add unit tests
- Keep the decoded position exact when seeking to the start of the data - Ignore repeated packet table info once the gapless values are set - Round the end of the kept range once to avoid an off-by-one with resampling
Author
|
Audio streaming isn't my area of expertise. So I had to rely on Claude Code to fix the issue. In my opinion, it worked well and the gap is gone, but I need your expertise for the final assessment. Thx |
chrizzchrizz
marked this pull request as ready for review
October 19, 2026 10:46
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.
Problem
Decoders output the encoder delay (priming) and padding (remainder) of AAC and MP3 as if they were audio.
processPacketTableInfoalready readskAudioFileStreamProperty_PacketTableInfo, but only uses it for the duration. So between two queued entries there is a short silence: for AAC 2112 priming frames plus the remainder of the previous file, about 50 ms. On continuous material (DJ mixes, live albums) this is audible as a stumble at every transition.Change
processPacketTableInfostores priming, valid and remainder frames on the entry.[priming, priming + valid)are kept. Leading frames are dropped by moving the kept frames to the start of the decoded segment in the ring buffer.trimTrailingGaplessPadding(), called inendOfFileOccurredafter the final flush; same lock order as the renderer). The same fallback applies when an entry is re-read from a seek offset, or when the packet table info arrives after decoding has started. A seek to the start of the data keeps the exact position, so the priming is still dropped.GaplessTrimand is covered by unit tests (GaplessTrimTests: chunks inside the priming, straddling the start, inside the valid range, straddling the end, after the end), plus a test for the decoded position afterreset.Measurement
Two files cut from one continuous 440 Hz sine (66273 + 66027 frames at 44.1 kHz), played with
play+queue, output captured throughframeFiltering:The short silence at the seek position itself is the same with and without this change (it varies between runs). A seek to 0 also plays the transition without silence. The full test suite passes (71 tests, including the new ones). The measurement itself relies on real-time playback, so it is not part of the test suite; I can add it if you want it in the repo.
Also verified on device (iOS) in an app that uses AudioStreaming: the stumble between tracks of an AAC DJ mix is gone.