diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-10-12 11:58:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-10-12 11:58:05 +0400 |
commit | 167676dbfeae96459247dcf627e34aec1c409048 (patch) | |
tree | dabc478f7291316939b865bb682a5ff111ffc325 | |
parent | 40221864733a34d6096eeb5ab54b2991c762809f (diff) |
read wave files block align value, rather then assuming 2 or 4.
-rw-r--r-- | intern/SoundSystem/intern/SND_Utils.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/intern/SoundSystem/intern/SND_Utils.cpp b/intern/SoundSystem/intern/SND_Utils.cpp index 58023dd5c50..1593dd6c794 100644 --- a/intern/SoundSystem/intern/SND_Utils.cpp +++ b/intern/SoundSystem/intern/SND_Utils.cpp @@ -287,21 +287,27 @@ unsigned int SND_GetBitRate(void* sample) /* gets the length of the actual sample data (without the header) */ unsigned int SND_GetNumberOfSamples(void* sample, int sample_length) { - unsigned int chunklength, length = 0, offset = 16; - + unsigned int chunklength, length = 0, offset; + unsigned short block_align; if (CheckSample(sample)) { - memcpy(&chunklength, ((char*)sample) + offset, 4); + memcpy(&chunklength, ((char*)sample) + 16, 4); + memcpy(&block_align, ((char*)sample) + 32, 2); /* always 2 or 4 it seems */ + /* This was endian unsafe. See top of the file for the define. */ - if (SND_fEndian == SND_endianBig) SWITCH_INT(chunklength); - - offset = offset + chunklength + 4; + if (SND_fEndian == SND_endianBig) + { + SWITCH_INT(chunklength); + SWITCH_SHORT(block_align); + } + + offset = 16 + chunklength + 4; /* This seems very unsafe, what if data is never found (f.i. corrupt file)... */ // lets find "data" while (memcmp(((char*)sample) + offset, "data", 4)) { - offset += 2; + offset += block_align; if (offset+4 > sample_length) /* save us from crashing */ return 0; @@ -322,18 +328,24 @@ unsigned int SND_GetNumberOfSamples(void* sample, int sample_length) unsigned int SND_GetHeaderSize(void* sample, int sample_length) { unsigned int chunklength, headersize = 0, offset = 16; - + unsigned short block_align; if (CheckSample(sample)) { memcpy(&chunklength, ((char*)sample) + offset, 4); + memcpy(&block_align, ((char*)sample) + 32, 2); /* always 2 or 4 it seems */ + /* This was endian unsafe. See top of the file for the define. */ - if (SND_fEndian == SND_endianBig) SWITCH_INT(chunklength); + if (SND_fEndian == SND_endianBig) + { + SWITCH_INT(chunklength); + SWITCH_SHORT(block_align); + } offset = offset + chunklength + 4; // lets find "data" while (memcmp(((char*)sample) + offset, "data", 4)) { - offset += 2; + offset += block_align; if (offset+4 > sample_length) /* save us from crashing */ return 0; @@ -341,12 +353,10 @@ unsigned int SND_GetHeaderSize(void* sample, int sample_length) headersize = offset + 8; } - return headersize; } - unsigned int SND_GetExtraChunk(void* sample) { unsigned int extrachunk = 0, chunklength, offset = 16; |