Skip to content
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

The Symphonia decoder ignores the actual seek position, resulting in audible glitches in file playback #43

Open
jacobstern opened this issue Aug 26, 2023 · 1 comment · Fixed by #48 · May be fixed by #52
Open

The Symphonia decoder ignores the actual seek position, resulting in audible glitches in file playback #43

jacobstern opened this issue Aug 26, 2023 · 1 comment · Fixed by #48 · May be fixed by #52

Comments

@jacobstern
Copy link

When the Symphonia stream is seeked, it does not in general advance to the position requested, but rather to a packet boundary less than or equal to that position. However the Symphonia decoder in creek does not currently use the return value, resulting in duplicate chunks of audio in the stream.

https://docs.rs/symphonia-core/0.5.3/symphonia_core/formats/trait.FormatReader.html#tymethod.seek

Note: The FormatReader by itself cannot seek to an exact audio frame, it is only capable of seeking to the nearest Packet. Therefore, to seek to an exact frame, a Decoder must decode packets until the requested position is reached. When using the accurate SeekMode, the seeked position will always be before the requested position. If the coarse SeekMode is used, then the seek position may be after the requested position. Coarse seeking is an optional performance enhancement, therefore, a coarse seek may sometimes be an accurate seek.

In practice, this results in an audible glitch in playback at around 11 seconds into the stream if you are using a similar setup to the Player demo.

The seek offset can also be seen in debug logs from the Symphonia library, for example for this MP3 of Carlie Rae Jepsen's "Emotion":

[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] seeking to ts=0 (+0 delay = 0)
[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] found frame with ts=0 (0) @ pos=11558 with main_data_begin=0
[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] seeked to ts=0 (0) (delta=0)
[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] seeking to ts=458752 (+0 delay = 458752)
[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] found frame with ts=458496 (458496) @ pos=427427 with main_data_begin=480
[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] will seek -1 frame(s) to ts=457344 (457344) @ pos=426382 (-1045 bytes)
[2023-08-26][22:38:11][DEBUG][symphonia_bundle_mp3::demuxer] seeked to ts=457344 (457344) (delta=-1408)

I've attempted to fix this with jacobstern@10b989a in my fork, but this seems to have introduced an artifact at the end of playback for a track, probably because the bookkeeping of chunk durations is still off.

Any assistance with the fix would be appreciated. Thanks!

@jacobstern
Copy link
Author

Here's a link to the mp3 file in question to reproduce. You can hear the glitch in the Player demo if you enable mp3 support in Cargo.toml. https://1drv.ms/u/s!AgBA_GfvlEBVrod3Zqt5w7ZOp8TE3g?e=BkTqms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants