Read non-compressed AIFF files (raw big-endian PCM)

This commit is contained in:
Iliyas Jorio 2020-11-22 11:58:05 +01:00
parent c34626864e
commit 1c1e404d0f

View File

@ -23,6 +23,7 @@ void Pomme::Sound::ReadAIFF(std::istream& input, cmixer::WavStream& output)
// COMM chunk contents // COMM chunk contents
int nChannels = 0; int nChannels = 0;
int nPackets = 0; int nPackets = 0;
int bitDepth = 0;
int sampleRate = 0; int sampleRate = 0;
uint32_t compressionType = 'NONE'; uint32_t compressionType = 'NONE';
@ -47,7 +48,7 @@ void Pomme::Sound::ReadAIFF(std::istream& input, cmixer::WavStream& output)
{ {
nChannels = f.Read<uint16_t>(); nChannels = f.Read<uint16_t>();
nPackets = f.Read<uint32_t>(); nPackets = f.Read<uint32_t>();
f.Skip(2); // sample bit depth (UInt16) bitDepth = f.Read<uint16_t>();
sampleRate = (int)f.Read80BitFloat(); sampleRate = (int)f.Read80BitFloat();
if (formType == 'AIFC') if (formType == 'AIFC')
{ {
@ -65,15 +66,25 @@ void Pomme::Sound::ReadAIFF(std::istream& input, cmixer::WavStream& output)
// sampled sound data is here // sampled sound data is here
const int ssndSize = ckSize - 8; const int ssndSize = ckSize - 8;
auto ssnd = std::vector<char>(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) if (compressionType == 'NONE')
auto codec = Pomme::Sound::GetCodec(compressionType); {
auto spanIn = std::span(ssnd); // Raw big-endian PCM -- just init the WavStream without decoding
auto spanOut = output.GetBuffer(nChannels * nPackets * codec->SamplesPerPacket() * 2); auto spanOut = output.GetBuffer(ssndSize);
codec->Decode(nChannels, spanIn, spanOut); f.Read(spanOut.data(), ssndSize);
output.Init(sampleRate, 16, nChannels, false, spanOut); output.Init(sampleRate, bitDepth, nChannels, true, spanOut);
}
else
{
auto ssnd = std::vector<char>(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; break;
} }