Obey data size field, avoid WAV clicks w/metadata
The DATA chunk has a size field that was ignored. When there was additional metadata after the chunk, however, it would try and play it leading to clicks. Store and only read that amount of data now.
This commit is contained in:
1 parent
2e348d2b1f
commit
0c002cd014
2 files changed
+7
-2
No files matched your search
@@ -62,7 +62,9 @@ bool AudioGeneratorWAV::GetBufferedData(int bytes, void *dest)
|
||||
// Potentially load next batch of data...
|
||||
if (buffPtr >= buffLen) {
|
||||
buffPtr = 0;
|
||||
buffLen = file->read( buff, buffSize );
|
||||
uint32_t toRead = availBytes > buffSize ? buffSize : availBytes;
|
||||
buffLen = file->read( buff, toRead );
|
||||
availBytes -= buffLen;
|
||||
}
|
||||
if (buffPtr >= buffLen)
|
||||
return false; // No data left!
|
||||
@@ -159,7 +161,8 @@ bool AudioGeneratorWAV::ReadWAVInfo()
|
||||
|
||||
// Skip size, read until end of file...
|
||||
if (!ReadU32(&u32)) return false;
|
||||
|
||||
availBytes = u32;
|
||||
|
||||
// Now set up the buffer or fail
|
||||
buff = reinterpret_cast<uint8_t *>(malloc(buffSize));
|
||||
if (!buff) return false;
|
||||
|
||||
@@ -48,6 +48,8 @@ class AudioGeneratorWAV : public AudioGenerator
|
||||
uint32_t sampleRate;
|
||||
uint16_t bitsPerSample;
|
||||
|
||||
uint32_t availBytes;
|
||||
|
||||
// We need to buffer some data in-RAM to avoid doing 1000s of small reads
|
||||
uint32_t buffSize;
|
||||
uint8_t *buff;
|
||||
|
||||
Reference in new issue
Block a user