[Scummvm-cvs-logs] SF.net SVN: scummvm:[34853] scummvm/trunk/engines/sword1/sound.cpp

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sun Oct 26 16:20:24 CET 2008


Revision: 34853
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34853&view=rev
Author:   eriktorbjorn
Date:     2008-10-26 15:20:24 +0000 (Sun, 26 Oct 2008)

Log Message:
-----------
Added semi-ugly workaround for bug #2182450 ("BS1 Demo: Crash due to missing
speech segment").

Modified Paths:
--------------
    scummvm/trunk/engines/sword1/sound.cpp

Modified: scummvm/trunk/engines/sword1/sound.cpp
===================================================================
--- scummvm/trunk/engines/sword1/sound.cpp	2008-10-26 14:29:41 UTC (rev 34852)
+++ scummvm/trunk/engines/sword1/sound.cpp	2008-10-26 15:20:24 UTC (rev 34853)
@@ -262,29 +262,54 @@
 		headerPos++;
 	if (headerPos < 100) {
 		int32 resSize;
+		int16 *srcData;
+		uint32 srcPos;
+		int16 length;
+		cSize /= 2;
 		headerPos += 4; // skip 'data' tag
 		if (_cowMode != CowDemo) {
 			resSize = READ_LE_UINT32(fBuf + headerPos) >> 1;
 			headerPos += 4;
 		} else {
-			// the demo speech files have the uncompressed size embedded
-			// in the compressed stream *sigh*
-			if (READ_LE_UINT16(fBuf + headerPos) == 1) {
-				resSize = READ_LE_UINT16(fBuf + headerPos + 2);
-				resSize |= READ_LE_UINT16(fBuf + headerPos + 6) << 16;
-			} else
-				resSize = READ_LE_UINT32(fBuf + headerPos + 2);
-			resSize >>= 1;
+			// the demo speech files have the uncompressed size
+			// embedded in the compressed stream *sigh*
+			//
+			// But not always, apparently. See bug #2182450. Is
+			// there any way to figure out the size other than
+			// decoding the sound in that case?
+
+			if (fBuf[headerPos + 1] == 0) {
+				if (READ_LE_UINT16(fBuf + headerPos) == 1) {
+					resSize = READ_LE_UINT16(fBuf + headerPos + 2);
+					resSize |= READ_LE_UINT16(fBuf + headerPos + 6) << 16;
+				} else
+					resSize = READ_LE_UINT32(fBuf + headerPos + 2);
+				resSize >>= 1;
+			} else {
+				resSize = 0;
+				srcData = (int16*)fBuf;
+				srcPos = headerPos >> 1;
+				while (srcPos < cSize) {
+					length = (int16)READ_LE_UINT16(srcData + srcPos);
+					srcPos++;
+					if (length < 0) {
+						resSize -= length;
+						srcPos++;
+					} else {
+						resSize += length;
+						srcPos += length;
+					}
+				}
+			}
 		}
 		assert(!(headerPos & 1));
-		int16 *srcData = (int16*)fBuf;
-		uint32 srcPos = headerPos >> 1;
-		cSize /= 2;
+		srcData = (int16*)fBuf;
+		srcPos = headerPos >> 1;
 		uint32 dstPos = 0;
 		int16 *dstData = (int16*)malloc(resSize * 2);
 		int32 samplesLeft = resSize;
 		while (srcPos < cSize && samplesLeft > 0) {
-			int16 length = (int16)READ_LE_UINT16(srcData + srcPos);
+			length = (int16)READ_LE_UINT16(srcData + srcPos);
 			srcPos++;
 			if (length < 0) {
 				length = -length;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list