Fix wrong read position when decoding whole file #717
Merged
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.
I've noticed exactly the same parasitic noise in the beginning of every WAV file being played with predecoding (
MIX_LoadAudio_IO(mixer, io, true, true)
). Exactly the same code works fine if I turn off predecoding.Turned out there is a bug in the IO read position in
DecodeWholeFile
. By the time it is called,io
is in the beginning of the file (after being reset inMIX_LoadAudioWithProperties
).init_track
does not do reading of its own, so PCM decoding starts at offset 0, which is a RIFF header in my case.This PR fixes the bug by seeking to frame 0 before doing any decoding, effectively skipping RIFF header. This is the same approach that
MIX_PlayTrack
uses to fine-tune the starting position.