citra-emu
/
citra-canary
Archived
1
0
Fork 0

decode: Fix PCM8 decoding

Signal range is -32767 to 32768, not -127 to 128.
This commit is contained in:
MerryMage 2018-02-25 12:42:15 +00:00
parent e51a642a13
commit 90b835758f
1 changed files with 7 additions and 9 deletions

View File

@ -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<s16>(static_cast<s8>(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<s16>(static_cast<u16>(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]);
}
}