mirror of
https://github.com/jorio/Pomme.git
synced 2024-11-23 06:32:14 +00:00
Read non-compressed AIFF files (raw big-endian PCM)
This commit is contained in:
parent
c34626864e
commit
1c1e404d0f
@ -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<uint16_t>();
|
||||
nPackets = f.Read<uint32_t>();
|
||||
f.Skip(2); // sample bit depth (UInt16)
|
||||
bitDepth = f.Read<uint16_t>();
|
||||
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<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)
|
||||
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<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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user