Repository navigation
Drop encoder priming and padding for gapless playback - #144
Draft
chrizzchrizz wants to merge 1 commit into
Draft
chrizzchrizz wants to merge 1 commit into
chrizzchrizz wants to merge 1 commit 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
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).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). The existing test suite passes. The measurement relies on real-time playback, so it is not included as a test; 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.