From 90b835758fb1584c232ec134f31371be201dc5e9 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 25 Feb 2018 12:42:15 +0000 Subject: [PATCH] decode: Fix PCM8 decoding Signal range is -32767 to 32768, not -127 to 128. --- src/audio_core/codec.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp index 81fd44b200..b91979c2e1 100644 --- a/src/audio_core/codec.cpp +++ b/src/audio_core/codec.cpp @@ -79,26 +79,24 @@ StereoBuffer16 DecodeADPCM(const u8* const data, const size_t sample_count, return ret; } -static s16 SignExtendS8(u8 x) { - // The data is actually signed PCM8. - // We sign extend this to signed PCM16. - return static_cast(static_cast(x)); -} - StereoBuffer16 DecodePCM8(const unsigned num_channels, const u8* const data, const size_t sample_count) { ASSERT(num_channels == 1 || num_channels == 2); + const auto decode_sample = [](u8 sample) { + return static_cast(static_cast(sample) << 8); + }; + StereoBuffer16 ret(sample_count); if (num_channels == 1) { for (size_t i = 0; i < sample_count; i++) { - ret[i].fill(SignExtendS8(data[i])); + ret[i].fill(decode_sample(data[i])); } } else { for (size_t i = 0; i < sample_count; i++) { - ret[i][0] = SignExtendS8(data[i * 2 + 0]); - ret[i][1] = SignExtendS8(data[i * 2 + 1]); + ret[i][0] = decode_sample(data[i * 2 + 0]); + ret[i][1] = decode_sample(data[i * 2 + 1]); } }