PE: Support importing WAV files that contain "extra format bytes" in "fmt" header.

This commit is contained in:
Preben Eriksen
2022-11-10 11:19:29 +01:00
parent b02020f801
commit 29900a3cc0

View File

@@ -23,11 +23,14 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
uint32 subChunkSize = 0; uint32 subChunkSize = 0;
mStream->ReadUint32(&subChunkSize); mStream->ReadUint32(&subChunkSize);
uint32 totalread = 0;
// FMT chunk // FMT chunk
if (subChunkId[0] == 'f' && subChunkId[1] == 'm' && subChunkId[2] == 't' && subChunkId[3] == ' ') if (subChunkId[0] == 'f' && subChunkId[1] == 'm' && subChunkId[2] == 't' && subChunkId[3] == ' ')
{ {
uint16 format; uint16 format;
mStream->ReadUint16(&format); mStream->ReadUint16(&format);
totalread += 2;
if (format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT && format != WAVE_FORMAT_EXTENDED) if (format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT && format != WAVE_FORMAT_EXTENDED)
{ {
@@ -37,18 +40,23 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
uint16 numChannels = 0; uint16 numChannels = 0;
mStream->ReadUint16(&numChannels); mStream->ReadUint16(&numChannels);
totalread += 2;
uint32 sampleRate = 0; uint32 sampleRate = 0;
mStream->ReadUint32(&sampleRate); mStream->ReadUint32(&sampleRate);
totalread += 4;
uint32 byteRate = 0; uint32 byteRate = 0;
mStream->ReadUint32(&byteRate); mStream->ReadUint32(&byteRate);
totalread += 4;
uint16 blockAlign = 0; uint16 blockAlign = 0;
mStream->ReadUint16(&blockAlign); mStream->ReadUint16(&blockAlign);
totalread += 2;
uint16 bitDepth = 0; uint16 bitDepth = 0;
mStream->ReadUint16(&bitDepth); mStream->ReadUint16(&bitDepth);
totalread += 2;
if (bitDepth != 8 && bitDepth != 16 && bitDepth != 24 && bitDepth != 32) if (bitDepth != 8 && bitDepth != 16 && bitDepth != 24 && bitDepth != 32)
{ {
@@ -65,6 +73,7 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
{ {
uint16 extensionSize = 0; uint16 extensionSize = 0;
mStream->ReadUint16(&extensionSize); mStream->ReadUint16(&extensionSize);
totalread += 2;
if (extensionSize != 22) if (extensionSize != 22)
{ {
@@ -74,12 +83,15 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
uint16 validBitDepth = 0; uint16 validBitDepth = 0;
mStream->ReadUint16(&validBitDepth); mStream->ReadUint16(&validBitDepth);
totalread += 2;
uint32 channelMask = 0; uint32 channelMask = 0;
mStream->ReadUint32(&channelMask); mStream->ReadUint32(&channelMask);
totalread += 4;
uint8 subFormat[16]; uint8 subFormat[16];
mStream->Read(subFormat, sizeof(subFormat)); mStream->Read(subFormat, sizeof(subFormat));
totalread += 16;
Platform::MemoryCopy(&format, subFormat, sizeof(format)); Platform::MemoryCopy(&format, subFormat, sizeof(format));
if (format != WAVE_FORMAT_PCM) if (format != WAVE_FORMAT_PCM)
@@ -89,6 +101,14 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
} }
} }
// PE: Support wav with "extra format bytes", just ignore not needed.
while (totalread < subChunkSize)
{
uint8 singlebyte;
mStream->Read(&singlebyte, sizeof(singlebyte));
totalread++;
}
mBytesPerSample = bitDepth / 8; mBytesPerSample = bitDepth / 8;
mFormat = format; mFormat = format;
} }