Permalink
Browse files

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.
  • Loading branch information...
earlephilhower committed Jan 10, 2018
1 parent 2e348d2 commit 0c002cd0147f3c7105550b3eb62293428d4be935
Showing with 7 additions and 2 deletions.
  1. +5 −2 src/AudioGeneratorWAV.cpp
  2. +2 −0 src/AudioGeneratorWAV.h
@@ -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;
View
@@ -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;

0 comments on commit 0c002cd

Please sign in to comment.