From 195d6d006f5798943c5072966a17f05ccb8ff4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Tue, 17 Aug 2021 00:50:34 +0200 Subject: [PATCH] LibAudio: Resample FLAC audio data FlacLoader initialized, but never used its resampler; this is now fixed and all subframes are resampled before decorrelation occurs. FLAC files with non-44100-Hz sample rates now play properly. --- Userland/Libraries/LibAudio/FlacLoader.cpp | 11 ++++------- Userland/Libraries/LibAudio/FlacLoader.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index a2baf1aaa7..019633c446 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -41,7 +41,7 @@ FlacLoaderPlugin::FlacLoaderPlugin(const StringView& path) if (!m_valid) return; - m_resampler = make>(m_sample_rate, 44100); + m_resampler = make>(m_sample_rate, 44100); } FlacLoaderPlugin::FlacLoaderPlugin(const ByteBuffer& buffer) @@ -59,7 +59,7 @@ FlacLoaderPlugin::FlacLoaderPlugin(const ByteBuffer& buffer) if (!m_valid) return; - m_resampler = make>(m_sample_rate, 44100); + m_resampler = make>(m_sample_rate, 44100); } bool FlacLoaderPlugin::sniff() @@ -244,10 +244,6 @@ RefPtr FlacLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_ m_error_string = String::formatted("Frame parsing error: {}", m_error_string); return nullptr; } - // HACK: Test the start of the next subframe - // auto input = m_stream->bit_stream(); - // u64 next = input.read_bits_big_endian(64); - // dbgln("After frame end: {}", next); } samples.append(m_current_frame_data.take_first()); if (m_current_frame_data.size() == 0) { @@ -352,7 +348,8 @@ void FlacLoaderPlugin::next_frame() FlacSubframeHeader new_subframe = next_subframe_header(bit_stream, i); CHECK_ERROR_STRING; Vector subframe_samples = parse_subframe(new_subframe, bit_stream); - // HACK: Test the start of the next subframe + m_resampler->reset(); + subframe_samples = m_resampler->resample(subframe_samples); CHECK_ERROR_STRING; current_subframes.append(move(subframe_samples)); } diff --git a/Userland/Libraries/LibAudio/FlacLoader.h b/Userland/Libraries/LibAudio/FlacLoader.h index 1542ae3911..b593804385 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.h +++ b/Userland/Libraries/LibAudio/FlacLoader.h @@ -124,7 +124,7 @@ private: bool m_valid { false }; RefPtr m_file; String m_error_string; - OwnPtr> m_resampler; + OwnPtr> m_resampler; // Data obtained directly from the FLAC metadata: many values have specific bit counts u32 m_sample_rate { 0 }; // 20 bit