1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

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.
This commit is contained in:
kleines Filmröllchen 2021-08-17 00:50:34 +02:00 committed by Andreas Kling
parent d7ca60b998
commit 195d6d006f
2 changed files with 5 additions and 8 deletions

View file

@ -41,7 +41,7 @@ FlacLoaderPlugin::FlacLoaderPlugin(const StringView& path)
if (!m_valid) if (!m_valid)
return; return;
m_resampler = make<ResampleHelper<double>>(m_sample_rate, 44100); m_resampler = make<ResampleHelper<i32>>(m_sample_rate, 44100);
} }
FlacLoaderPlugin::FlacLoaderPlugin(const ByteBuffer& buffer) FlacLoaderPlugin::FlacLoaderPlugin(const ByteBuffer& buffer)
@ -59,7 +59,7 @@ FlacLoaderPlugin::FlacLoaderPlugin(const ByteBuffer& buffer)
if (!m_valid) if (!m_valid)
return; return;
m_resampler = make<ResampleHelper<double>>(m_sample_rate, 44100); m_resampler = make<ResampleHelper<i32>>(m_sample_rate, 44100);
} }
bool FlacLoaderPlugin::sniff() bool FlacLoaderPlugin::sniff()
@ -244,10 +244,6 @@ RefPtr<Buffer> FlacLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_
m_error_string = String::formatted("Frame parsing error: {}", m_error_string); m_error_string = String::formatted("Frame parsing error: {}", m_error_string);
return nullptr; 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()); samples.append(m_current_frame_data.take_first());
if (m_current_frame_data.size() == 0) { if (m_current_frame_data.size() == 0) {
@ -352,7 +348,8 @@ void FlacLoaderPlugin::next_frame()
FlacSubframeHeader new_subframe = next_subframe_header(bit_stream, i); FlacSubframeHeader new_subframe = next_subframe_header(bit_stream, i);
CHECK_ERROR_STRING; CHECK_ERROR_STRING;
Vector<i32> subframe_samples = parse_subframe(new_subframe, bit_stream); Vector<i32> 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; CHECK_ERROR_STRING;
current_subframes.append(move(subframe_samples)); current_subframes.append(move(subframe_samples));
} }

View file

@ -124,7 +124,7 @@ private:
bool m_valid { false }; bool m_valid { false };
RefPtr<Core::File> m_file; RefPtr<Core::File> m_file;
String m_error_string; String m_error_string;
OwnPtr<ResampleHelper<double>> m_resampler; OwnPtr<ResampleHelper<i32>> m_resampler;
// Data obtained directly from the FLAC metadata: many values have specific bit counts // Data obtained directly from the FLAC metadata: many values have specific bit counts
u32 m_sample_rate { 0 }; // 20 bit u32 m_sample_rate { 0 }; // 20 bit