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

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Fri Aug 10 17:33:07 CEST 2007


Revision: 28514
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28514&view=rev
Author:   buddha_
Date:     2007-08-10 08:33:07 -0700 (Fri, 10 Aug 2007)

Log Message:
-----------
Added Apple IIGS sample's true size calculation (A zero byte can end the sample prematurely).

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

Modified: scummvm/trunk/engines/agi/sound.cpp
===================================================================
--- scummvm/trunk/engines/agi/sound.cpp	2007-08-10 13:04:59 UTC (rev 28513)
+++ scummvm/trunk/engines/agi/sound.cpp	2007-08-10 15:33:07 UTC (rev 28514)
@@ -179,6 +179,25 @@
 }
 
 /**
+ * Calculates an Apple IIGS sample's true size.
+ * Needed because a zero byte in the sample data ends the sample prematurely.
+ */
+uint calcTrueSampleSize(byte *sample, uint size) {
+	if (sample == NULL) { // Check for an erroneous input value
+		warning("Agi::calcTrueSampleSize: A NULL-pointer parameter");
+		return size; // Might as well return 0
+	} else { // Input values are ok
+		// Search for a zero byte in the sample data,
+		// as that would end the sample prematurely.
+		for (uint i = 0; i < size; i++)
+			if (sample[i] == 0)
+				return i;
+		// If no zero was found in the sample, then return its whole size.
+		return size;
+	}
+}
+
+/**
  * Load an Apple IIGS AGI sample resource from the given stream and
  * create an AudioStream out of it.
  *
@@ -215,6 +234,13 @@
 		byte *sampleData = (byte *) malloc(header.sampleSize);
 		uint32 readBytes = stream.read(sampleData, header.sampleSize);
 		if (readBytes == header.sampleSize) { // Check that we got all the data we requested
+			// Calculate true sample size (A zero byte ends the sample prematurely)
+			uint trueSampleSize = calcTrueSampleSize(sampleData, header.sampleSize);
+			if (trueSampleSize != header.sampleSize) {
+				debugC(3, kDebugLevelSound, "Apple IIGS sample (%d): Size changed from %d to %d (Zero byte encountered)",
+					resnum, header.sampleSize, trueSampleSize);
+			}
+			header.sampleSize = (uint16) trueSampleSize; // Set the true sample size
 			// Make an audio stream from the mono, 8 bit, unsigned input data
 			byte flags = Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED;
 			int rate = (int) (1076 * pow(SEMITONE, header.pitch));


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