Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-10-12 11:58:05 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-10-12 11:58:05 +0400
commit167676dbfeae96459247dcf627e34aec1c409048 (patch)
treedabc478f7291316939b865bb682a5ff111ffc325 /intern
parent40221864733a34d6096eeb5ab54b2991c762809f (diff)
read wave files block align value, rather then assuming 2 or 4.
Diffstat (limited to 'intern')
-rw-r--r--intern/SoundSystem/intern/SND_Utils.cpp34
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;