From 2ecd115176803150b894de89750ccaadd9363304 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 3 Aug 2021 18:41:00 +0200 Subject: [PATCH] LibAudio: Make read samples signed when decoding fixed FLAC subframes Prior this change, decoding fixed subframes produced "unpleasant crackling noices". While the type doesn't appear so often when using the default settings, encoding files in flac(1) with --fast option uses fixed subframes almost every time. This also applies the logic to the constant subframes, which isn't so important, as the type is generally for the silence, but let's use it as well to avoid inconsistency. --- Userland/Libraries/LibAudio/FlacLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index b36797117b..9e604157fb 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -597,7 +597,7 @@ Vector FlacLoaderPlugin::parse_subframe(FlacSubframeHeader& subframe_header samples.ensure_capacity(m_current_frame->sample_count); for (u32 i = 0; i < m_current_frame->sample_count; ++i) { - samples.unchecked_append(constant_value); + samples.unchecked_append(sign_extend(constant_value, subframe_header.bits_per_sample)); } break; } @@ -696,7 +696,7 @@ Vector FlacLoaderPlugin::decode_fixed_lpc(FlacSubframeHeader& subframe, Inp // warm-up samples for (auto i = 0; i < subframe.order; ++i) { - decoded.unchecked_append(bit_input.read_bits_big_endian(subframe.bits_per_sample - subframe.wasted_bits_per_sample)); + decoded.unchecked_append(sign_extend(bit_input.read_bits_big_endian(subframe.bits_per_sample - subframe.wasted_bits_per_sample), subframe.bits_per_sample)); } decode_residual(decoded, subframe, bit_input);