diff options
Diffstat (limited to 'Userland/Libraries/LibAudio/FlacLoader.cpp')
-rw-r--r-- | Userland/Libraries/LibAudio/FlacLoader.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index ab74865e27..baef59d7eb 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -118,13 +118,20 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() md5_checksum.bytes().copy_to({ m_md5_checksum, sizeof(m_md5_checksum) }); // Parse other blocks - // TODO: For a simple first implementation, all other blocks are skipped as allowed by the FLAC specification. - // Especially the SEEKTABLE block may become useful in a more sophisticated version. [[maybe_unused]] u16 meta_blocks_parsed = 1; [[maybe_unused]] u16 total_meta_blocks = meta_blocks_parsed; FlacRawMetadataBlock block = streaminfo; while (!block.is_last_block) { block = TRY(next_meta_block(*bit_input)); + switch (block.type) { + case (FlacMetadataBlockType::SEEKTABLE): + TRY(load_seektable(block)); + break; + default: + // TODO: Parse the remaining metadata block types. + // Currently only STREAMINFO and SEEKTABLE are handled. + break; + } ++total_meta_blocks; } @@ -133,6 +140,21 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() return {}; } +MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block) +{ + auto memory_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(block.data.bytes())); + auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(*memory_stream)); + for (size_t i = 0; i < block.length / 18; ++i) { + FlacSeekPoint seekpoint { + .sample_index = LOADER_TRY(seektable_bytes->read_bits<u64>(64)), + .byte_offset = LOADER_TRY(seektable_bytes->read_bits<u64>(64)), + .num_samples = LOADER_TRY(seektable_bytes->read_bits<u16>(16)) + }; + m_seektable.append(seekpoint); + } + return {}; +} + ErrorOr<FlacRawMetadataBlock, LoaderError> FlacLoaderPlugin::next_meta_block(BigEndianInputBitStream& bit_input) { |