From 801d7e8d1e6e75a7aa123c4685f8288383c8b3af Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Sun, 15 May 2022 10:47:52 +0200 Subject: [PATCH] Preprocess sound resource: Convert big-endian raw PCM to little-endian --- src/SoundFormats/SoundFormats.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/SoundFormats/SoundFormats.cpp b/src/SoundFormats/SoundFormats.cpp index ac5416c..2054aeb 100644 --- a/src/SoundFormats/SoundFormats.cpp +++ b/src/SoundFormats/SoundFormats.cpp @@ -274,11 +274,23 @@ Boolean Pomme_DecompressSoundResource(SndListHandle* sndHandlePtr, long* offsetT if (!inInfo.isCompressed) { - // Raw big-endian PCM + // Raw PCM if (inInfo.decompressedLength != inInfo.compressedLength) throw std::runtime_error("decompressedLength != compressedLength???"); memcpy(outDataStart, inDataStart, inInfo.decompressedLength); + + // If it's big endian, swap the bytes + int bytesPerSample = inInfo.codecBitDepth / 8; + if (inInfo.bigEndian && bytesPerSample > 1) + { + int nIntegers = inInfo.decompressedLength / bytesPerSample; + if (inInfo.decompressedLength != nIntegers * bytesPerSample) + throw std::runtime_error("unexpected big-endian raw PCM decompressed length"); + + ByteswapInts(bytesPerSample, nIntegers, outDataStart); + outInfo.bigEndian = false; + } } else {