summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-08-17 00:50:34 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-18 18:16:48 +0200
commit195d6d006f5798943c5072966a17f05ccb8ff4e2 (patch)
treea35e69cfa7212f34141ebb7e8636e48e5d68d6cd /Userland/Libraries/LibAudio
parentd7ca60b998ebb0b1fb8aa418a3a6cd25609775f0 (diff)
downloadserenity-195d6d006f5798943c5072966a17f05ccb8ff4e2.zip
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.
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.cpp11
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.h2
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<ResampleHelper<double>>(m_sample_rate, 44100);
+ m_resampler = make<ResampleHelper<i32>>(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<ResampleHelper<double>>(m_sample_rate, 44100);
+ m_resampler = make<ResampleHelper<i32>>(m_sample_rate, 44100);
}
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);
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<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;
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<Core::File> m_file;
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
u32 m_sample_rate { 0 }; // 20 bit