Revision: 17038
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17038
Author:   campbellbarton
Date:     2008-10-12 09:58:05 +0200 (Sun, 12 Oct 2008)

Log Message:
-----------
read wave files block align value, rather then assuming 2 or 4.

Modified Paths:
--------------
    trunk/blender/intern/SoundSystem/intern/SND_Utils.cpp

Modified: trunk/blender/intern/SoundSystem/intern/SND_Utils.cpp
===================================================================
--- trunk/blender/intern/SoundSystem/intern/SND_Utils.cpp       2008-10-12 
06:39:47 UTC (rev 17037)
+++ trunk/blender/intern/SoundSystem/intern/SND_Utils.cpp       2008-10-12 
07:58:05 UTC (rev 17038)
@@ -287,21 +287,27 @@
 /* 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);
+               if (SND_fEndian == SND_endianBig)
+               {
+                       SWITCH_INT(chunklength);
+                       SWITCH_SHORT(block_align);
+               }
+                               
+               offset = 16 + chunklength + 4;
 
-               offset = offset + 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_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 @@
                headersize = offset + 8;
        }
 
-
        return headersize;
 }
 
 
-
 unsigned int SND_GetExtraChunk(void* sample)
 {
        unsigned int extrachunk = 0, chunklength, offset = 16;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to