From 2dc75a37d258f943a671f20a938cfd97c64001ca Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Fri, 25 Aug 2023 19:02:57 -0500 Subject: [PATCH] LibAudio: Set MP3 seek points to their frame's first sample Seek points were being created after adding to the sample count in `build_seek_table()`, meaning that they would be offset forward by `MP3::frame_size` samples. This also allows us to remove the hardcoded sample 0 seek point that was previously added, since a seek point at sample 0 will now be added by the loop. --- Userland/Libraries/LibAudio/MP3Loader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 0d22d2417a..5c029a0112 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.cpp +++ b/Userland/Libraries/LibAudio/MP3Loader.cpp @@ -146,7 +146,6 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table() int sample_count = 0; size_t frame_count = 0; m_seek_table = {}; - TRY(m_seek_table.insert_seek_point({ 0, 0 })); m_bitstream->align_to_byte_boundary(); @@ -157,12 +156,13 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table() if (error_or_header.is_error() || error_or_header.value().id != 1 || error_or_header.value().layer != 3) { continue; } - frame_count++; - sample_count += MP3::frame_size; if (frame_count % 10 == 0) TRY(m_seek_table.insert_seek_point({ static_cast(sample_count), frame_pos })); + frame_count++; + sample_count += MP3::frame_size; + TRY(m_stream->seek(error_or_header.value().frame_size - 6, SeekMode::FromCurrentPosition)); // TODO: This is just here to clear the bitstream buffer.