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

Merge pull request #3459 from MerryMage/fix/pcm8-decoding

decode: Fix PCM8 decoding
This commit is contained in:
bunnei 2018-02-26 21:17:54 -08:00 committed by GitHub
commit 5b0d326166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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; 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, StereoBuffer16 DecodePCM8(const unsigned num_channels, const u8* const data,
const size_t sample_count) { const size_t sample_count) {
ASSERT(num_channels == 1 || num_channels == 2); 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); StereoBuffer16 ret(sample_count);
if (num_channels == 1) { if (num_channels == 1) {
for (size_t i = 0; i < sample_count; i++) { for (size_t i = 0; i < sample_count; i++) {
ret[i].fill(SignExtendS8(data[i])); ret[i].fill(decode_sample(data[i]));
} }
} else { } else {
for (size_t i = 0; i < sample_count; i++) { for (size_t i = 0; i < sample_count; i++) {
ret[i][0] = SignExtendS8(data[i * 2 + 0]); ret[i][0] = decode_sample(data[i * 2 + 0]);
ret[i][1] = SignExtendS8(data[i * 2 + 1]); ret[i][1] = decode_sample(data[i * 2 + 1]);
} }
} }