1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

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.
This commit is contained in:
Zaggy1024 2023-08-25 19:02:57 -05:00 committed by Tim Flynn
parent 89fb4af429
commit 2dc75a37d2

View file

@ -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<u64>(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.