Skip to content

Fix wrong read position when decoding whole file #717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2025

Conversation

alexbatalov
Copy link
Contributor

@alexbatalov alexbatalov commented Jul 27, 2025

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 in MIX_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.

@icculus
Copy link
Collaborator

icculus commented Jul 27, 2025

Good catch, thank you!

@icculus icculus merged commit a5d3a99 into libsdl-org:main Jul 27, 2025
5 checks passed
@alexbatalov alexbatalov deleted the fix-decode-whole-file branch July 29, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants