Repository navigation
fix: seek disk-streamed MP3s from a seek table instead of decoding from the start - #634
Merged
Merged
Conversation
2 tasks done
Owner
|
Thanks @Fmarschall, this fixes a long-standing limit, and the test made it easy to check: it fails on main and passes with your change, and the seeks are sample-exact on every MP3 I tried. Your branch is in a fork owned by an organization, and GitHub does not let maintainers push to those, so I could not add my commits to this PR. I opened #636 instead: your commit is the first one there, unchanged. What I added on top:
|
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.
Description
A
WavStreamvoice of an MP3 (LoadMode.disk) seeks withdrmp3_seek_to_pcm_frame, and no seek table was bound to the decoder. dr_mp3 then seeks backwards by decoding the file from its first frame up to the target, under the audio mutex. A seek near the end of a song read most of the file, so a seek slider stuttered and every voice dropped out until the seek finished. The docs worked around it by advisingLoadMode.memoryfor MP3s that are sought.When a voice opens an MP3, it now builds a seek table with
drmp3_calculate_seek_pointsand binds it withdrmp3_bind_seek_table. Building the table parses the frame headers, without decoding the audio, increateInstance, which runs outside the audio mutex. The table holds four points a second, at most 16384 (one every 0.7 s for a 3-hour file), 24 bytes each: about 17 KB for a 3-minute song. A seek then decodes at most a quarter of a second. dr_mp3 itself is unchanged; the change is a marked local patch insoloud_wavstream.cpp/.h. Without memory for the table, the voice seeks as before.wavstream_seek_testnow also covers MP3, with8_bit_mentality.mp3. It does 19 backward seeks from near the end and checks that the voice then plays exactly what a voice reading from the start plays there:Creating a voice of that file (206 s) takes about 1.4 ms on an M-series Mac. We found this in an app that plays six disk-streamed MP3 stems of a song in sync. With a first version of this patch, which kept one point per frame, scrubbing on a Pixel 8 became as smooth as with WAVs.
The notes advising
LoadMode.memoryfor sought MP3s are removed from the dartdoc,bindings.hand the generated bindings (comments only), and from the loading and playback skills (versions bumped). There is a CHANGELOG entry under "Unreleased".Ran:
./test/common/wavstream_seek_test.sh, also with--asanvoice_allocation_failure_test.sh,wavstream_missing_file_test.shflutter test test/common/play_seek_pause_test.dart test/common/audio_source_test.dart test/common/ffigen_bindings_sync_test.dartflutter analyze,dart formatNot run: the full native suites, and the Android and iOS native tests. I did not rebuild the WASM, since I have no Emscripten here. On the web
LoadMode.diskis ignored, so the change is not reachable there until #633.Type of Change