summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2023-03-18 14:23:39 +0100
committerLinus Groh <mail@linusgroh.de>2023-03-19 00:28:02 +0000
commit27d9ed0224d19e71917701e685c33f90a74e5694 (patch)
tree94b3a040b00df76d079e80255d387a9f6d11d6df /Userland
parent0cd0565abc5a0abf8df41268b890d59dc5a92f06 (diff)
downloadserenity-27d9ed0224d19e71917701e685c33f90a74e5694.zip
LibAudio: Use new generic seek table for MP3
MP3 had the exact same data structure, except less readable and less efficient.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.cpp14
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.h2
2 files changed, 7 insertions, 9 deletions
diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp
index ffdb8e5508..f3131ea2e7 100644
--- a/Userland/Libraries/LibAudio/MP3Loader.cpp
+++ b/Userland/Libraries/LibAudio/MP3Loader.cpp
@@ -75,12 +75,10 @@ MaybeLoaderError MP3LoaderPlugin::reset()
MaybeLoaderError MP3LoaderPlugin::seek(int const position)
{
- for (auto const& seek_entry : m_seek_table) {
- if (seek_entry.get<1>() >= position) {
- LOADER_TRY(m_stream->seek(seek_entry.get<0>(), SeekMode::SetPosition));
- m_loaded_samples = seek_entry.get<1>();
- break;
- }
+ auto seek_entry = m_seek_table.seek_point_before(position);
+ if (seek_entry.has_value()) {
+ LOADER_TRY(m_stream->seek(seek_entry->byte_offset, SeekMode::SetPosition));
+ m_loaded_samples = seek_entry->sample_index;
}
m_current_frame = {};
m_synthesis_buffer = {};
@@ -135,7 +133,7 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table()
{
int sample_count = 0;
size_t frame_count = 0;
- m_seek_table.clear();
+ m_seek_table = {};
m_bitstream->align_to_byte_boundary();
@@ -150,7 +148,7 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table()
sample_count += MP3::frame_size;
if (frame_count % 10 == 0)
- m_seek_table.append({ frame_pos, sample_count });
+ LOADER_TRY(m_seek_table.insert_seek_point({ static_cast<u64>(sample_count), frame_pos }));
LOADER_TRY(m_stream->seek(error_or_header.value().frame_size - 6, SeekMode::FromCurrentPosition));
diff --git a/Userland/Libraries/LibAudio/MP3Loader.h b/Userland/Libraries/LibAudio/MP3Loader.h
index 4db9cbbfd0..610ae21b3c 100644
--- a/Userland/Libraries/LibAudio/MP3Loader.h
+++ b/Userland/Libraries/LibAudio/MP3Loader.h
@@ -57,7 +57,7 @@ private:
static void synthesis(Array<float, 1024>& V, Array<float, 32>& samples, Array<float, 32>& result);
static ReadonlySpan<MP3::Tables::ScaleFactorBand> get_scalefactor_bands(MP3::Granule const&, int samplerate);
- AK::Vector<AK::Tuple<size_t, int>> m_seek_table;
+ SeekTable m_seek_table;
AK::Array<AK::Array<AK::Array<float, 18>, 32>, 2> m_last_values {};
AK::Array<AK::Array<float, 1024>, 2> m_synthesis_buffer {};
static DSP::MDCT<36> s_mdct_36;