From 1c1e404d0f7c0f4411cdb783bd2b64808d53a03d Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Sun, 22 Nov 2020 11:58:05 +0100 Subject: [PATCH] Read non-compressed AIFF files (raw big-endian PCM) --- src/Sound/AIFF.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Sound/AIFF.cpp b/src/Sound/AIFF.cpp index 048eb67..5c5842b 100644 --- a/src/Sound/AIFF.cpp +++ b/src/Sound/AIFF.cpp @@ -23,6 +23,7 @@ void Pomme::Sound::ReadAIFF(std::istream& input, cmixer::WavStream& output) // COMM chunk contents int nChannels = 0; int nPackets = 0; + int bitDepth = 0; int sampleRate = 0; uint32_t compressionType = 'NONE'; @@ -47,7 +48,7 @@ void Pomme::Sound::ReadAIFF(std::istream& input, cmixer::WavStream& output) { nChannels = f.Read(); nPackets = f.Read(); - f.Skip(2); // sample bit depth (UInt16) + bitDepth = f.Read(); sampleRate = (int)f.Read80BitFloat(); if (formType == 'AIFC') { @@ -65,15 +66,25 @@ void Pomme::Sound::ReadAIFF(std::istream& input, cmixer::WavStream& output) // sampled sound data is here const int ssndSize = ckSize - 8; - auto ssnd = std::vector(ssndSize); - f.Read(ssnd.data(), ssndSize); - // TODO: if the compression type is 'NONE' (raw PCM), just init the WavStream without decoding (not needed for Nanosaur though) - auto codec = Pomme::Sound::GetCodec(compressionType); - auto spanIn = std::span(ssnd); - auto spanOut = output.GetBuffer(nChannels * nPackets * codec->SamplesPerPacket() * 2); - codec->Decode(nChannels, spanIn, spanOut); - output.Init(sampleRate, 16, nChannels, false, spanOut); + if (compressionType == 'NONE') + { + // Raw big-endian PCM -- just init the WavStream without decoding + auto spanOut = output.GetBuffer(ssndSize); + f.Read(spanOut.data(), ssndSize); + output.Init(sampleRate, bitDepth, nChannels, true, spanOut); + } + else + { + auto ssnd = std::vector(ssndSize); + f.Read(ssnd.data(), ssndSize); + auto codec = Pomme::Sound::GetCodec(compressionType); + auto spanIn = std::span(ssnd); + auto spanOut = output.GetBuffer(nChannels * nPackets * codec->SamplesPerPacket() * 2); + codec->Decode(nChannels, spanIn, spanOut); + output.Init(sampleRate, 16, nChannels, false, spanOut); + } + break; }