diff options
-rw-r--r-- | src/audio/wav.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/audio/wav.cc b/src/audio/wav.cc index b6ca710..0f86a65 100644 --- a/src/audio/wav.cc +++ b/src/audio/wav.cc @@ -37,14 +37,14 @@ PCM *Wav::load(std::string const & name) return 0; } - unsigned char header[44]; + unsigned char header[44]; memset(header, 0, sizeof(header)); if (!wav_file->read(header, 44)) { con_warn << "Error reading " << filename << std::endl; filesystem::close(wav_file); return 0; } - + // header RIFF if (strncmp((char *)header, "RIFF", 4)) { con_warn << "Error reading " << filename << ": invalid RIFF header!" << std::endl; @@ -89,6 +89,20 @@ PCM *Wav::load(std::string const & name) //size_t byterate = header[28] + (header[29] << 8) + (header[30] << 16) + (header[31] << 24); //size_t blockalign = header[32] + (header[33] << 8); size_t bitspersample = header[34] + (header[35] << 8); + + if (strncmp((char *)header + 36, "LIST", 4) == 0) { + // this wav file contains meta data (author, title, ..) + // byte 40 through 43 contains the metadata length instead of the datasize + size_t metasize = header[40] + (header[41] << 8) + (header[42] << 16) + (header[43] << 24); + wav_file->skip(metasize); + + // the data header follows the meta data, we overwrite the original metadata header + if (!wav_file->read(header + 36, 8)) { + con_warn << "Error reading " << filename << ": unexpected end of file!" << std::endl; + filesystem::close(wav_file); + return 0; + } + } if (strncmp((char *)header + 36, "data", 4) != 0) { con_warn << "Error reading " << filename << ": invalid data header!" << std::endl; |