mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:31:29 +02:00
Fix WAV file support
The previous implementation assumed the file only contained RIFF, WAVE, fmt, and data chunks. It is valid for other chunks to appear, so I updated it to skip any chunks until it finds the "data" chunk.
This commit is contained in:
parent
13366d9ba1
commit
aa47043d57
1 changed files with 15 additions and 12 deletions
|
@ -237,27 +237,30 @@ void Sound::interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& ou
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip any extra data in the WAVE chunk
|
||||||
|
waveStream.skipRawData(fileHeader.wave.descriptor.size - (sizeof(WAVEHeader) - sizeof(chunk)));
|
||||||
|
|
||||||
// Read off remaining header information
|
// Read off remaining header information
|
||||||
DATAHeader dataHeader;
|
DATAHeader dataHeader;
|
||||||
if (waveStream.readRawData(reinterpret_cast<char *>(&dataHeader), sizeof(DATAHeader)) == sizeof(DATAHeader)) {
|
while (true) {
|
||||||
if (strncmp(dataHeader.descriptor.id, "data", 4) != 0) {
|
// Read chunks until the "data" chunk is found
|
||||||
qDebug() << "Invalid wav audio data header.";
|
if (waveStream.readRawData(reinterpret_cast<char *>(&dataHeader), sizeof(DATAHeader)) == sizeof(DATAHeader)) {
|
||||||
|
if (strncmp(dataHeader.descriptor.id, "data", 4) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
waveStream.skipRawData(dataHeader.descriptor.size);
|
||||||
|
} else {
|
||||||
|
qDebug() << "Could not read wav audio data header.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qDebug() << "Could not read wav audio data header.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qFromLittleEndian<quint32>(fileHeader.riff.descriptor.size) != qFromLittleEndian<quint32>(dataHeader.descriptor.size) + 36) {
|
|
||||||
qDebug() << "Did not read audio file chank headers correctly.";
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now pull out the data
|
// Now pull out the data
|
||||||
quint32 outputAudioByteArraySize = qFromLittleEndian<quint32>(dataHeader.descriptor.size);
|
quint32 outputAudioByteArraySize = qFromLittleEndian<quint32>(dataHeader.descriptor.size);
|
||||||
outputAudioByteArray.resize(outputAudioByteArraySize);
|
outputAudioByteArray.resize(outputAudioByteArraySize);
|
||||||
waveStream.readRawData(outputAudioByteArray.data(), outputAudioByteArraySize);
|
if (waveStream.readRawData(outputAudioByteArray.data(), outputAudioByteArraySize) != outputAudioByteArraySize) {
|
||||||
|
qDebug() << "Error reading WAV file";
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Could not read wav audio file header.";
|
qDebug() << "Could not read wav audio file header.";
|
||||||
|
|
Loading…
Reference in a new issue