From 60f147290241faf389694afbd4f87938cd6aca4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 5 Jul 2023 00:03:52 +0200 Subject: [PATCH] LibAudio: Store all available data in the FLAC frame header This will make it possible to write the header back out. --- Userland/Libraries/LibAudio/FlacLoader.cpp | 12 +++++++----- Userland/Libraries/LibAudio/FlacTypes.h | 11 ++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 8d23a8d1a5..a84c8e1343 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -440,11 +440,13 @@ LoaderSamples FlacLoaderPlugin::next_frame() dbgln_if(AFLACLOADER_DEBUG, "Frame: {} samples, {}bit {}Hz, channeltype {:x}, {} number {}, header checksum {:02x}{}", sample_count, bit_depth, frame_sample_rate, channel_type_num, blocking_strategy ? "sample" : "frame", m_current_sample_or_frame, specified_header_checksum, specified_header_checksum != calculated_header_checksum ? " (checksum error)"sv : ""sv); m_current_frame = FlacFrameHeader { - sample_count, - frame_sample_rate, - channel_type, - bit_depth, - specified_checksum, + .sample_rate = frame_sample_rate, + .sample_count = static_cast(sample_count), + .sample_or_frame_index = static_cast(m_current_sample_or_frame), + .blocking_strategy = static_cast(blocking_strategy), + .channels = channel_type, + .bit_depth = bit_depth, + .checksum = specified_header_checksum, }; u8 subframe_count = frame_channel_type_to_channel_count(channel_type); diff --git a/Userland/Libraries/LibAudio/FlacTypes.h b/Userland/Libraries/LibAudio/FlacTypes.h index 8b5d4d7eb8..e2333a7310 100644 --- a/Userland/Libraries/LibAudio/FlacTypes.h +++ b/Userland/Libraries/LibAudio/FlacTypes.h @@ -86,10 +86,19 @@ struct FlacRawMetadataBlock { ByteBuffer data; }; +enum class BlockingStrategy : u8 { + Fixed = 0, + Variable = 1, +}; + // 11.22. FRAME_HEADER struct FlacFrameHeader { - u32 sample_count; u32 sample_rate; + // Referred to as “block size” in the specification. + u16 sample_count; + // If blocking strategy is fixed, this encodes the frame index instead of the sample index. + u32 sample_or_frame_index; + BlockingStrategy blocking_strategy; FlacFrameChannelType channels; u8 bit_depth; u8 checksum;