[Scummvm-cvs-logs] CVS: scummvm/simon midi.cpp,1.50,1.50.2.1

Travis Howell kirben at users.sourceforge.net
Wed Jul 23 21:51:05 CEST 2003


Update of /cvsroot/scummvm/scummvm/simon
In directory sc8-pr-cvs1:/tmp/cvs-serv2456/simon

Modified Files:
      Tag: branch-0-5-0
	midi.cpp 
Log Message:

Fix for Bug [775534] 0.5.0 RC SIMON1DOS Random sfx notes during music

Corrected a problem with resource size computation for GMF sound
effect resources. Since GMF resources have no size info, we were
computing sizes with the assumption that each GMF appears in its
own file, so the file size becomes the resource size. This is true
for simon1dos music files but not for SFX files. This fix uses the
resource offset pointers at the beginning of SFX files to properly
compute the size of SFX resources.


Index: midi.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/midi.cpp,v
retrieving revision 1.50
retrieving revision 1.50.2.1
diff -u -d -r1.50 -r1.50.2.1
--- midi.cpp	14 Jul 2003 12:15:17 -0000	1.50
+++ midi.cpp	24 Jul 2003 04:50:35 -0000	1.50.2.1
@@ -129,10 +129,11 @@
 
 void MidiPlayer::metaEvent (byte type, byte *data, uint16 length) {
 	// Only thing we care about is End of Track.
-	if (!_current || type != 0x2F || _current == &_sfx)
+	if (!_current || type != 0x2F) {
 		return;
-
-	if (_loopTrack) {
+	} else if (_current == &_sfx) {
+		clearConstructs (_sfx);
+	} else if (_loopTrack) {
 		_current->parser->jumpToTick (0);
 	} else if (_queuedTrack != 255) {
 		_currentTrack = 255;
@@ -299,11 +300,19 @@
 	if (info.num_songs > 0) {
 		for (i = 0; i < info.num_songs; ++i)
 			free (info.songs [i]);
+		info.num_songs = 0;
 	}
-	if (info.data)
+
+	if (info.data) {
 		free (info.data);
-	if (info.parser)
+		info.data = 0;
+	} // end if
+
+	if (info.parser) {
 		delete info.parser;
+		info.parser = 0;
+	}
+
 	if (_driver) {
 		for (i = 0; i < 16; ++i) {
 			if (info.channel[i]) {
@@ -327,9 +336,34 @@
 	MusicInfo *p = sfx ? &_sfx : &_music;
 	clearConstructs (*p);
 
+	uint32 startpos = in->pos();
+	byte header[4];
+	in->read (header, 4);
+	bool isGMF = !memcmp (header, "GMF\x1", 4);
+	in->seek (startpos, SEEK_SET);
+
 	uint32 size = in->size() - in->pos();
-	if (size > 64000)
-		size = 64000;
+	if (isGMF) {
+		if (sfx) {
+			// Multiple GMF resources are stored in the SFX files,
+			// but each one is referenced by a pointer at the
+			// beginning of the file. Those pointers can be used
+			// to determine file size.
+			in->seek (0, SEEK_SET);
+			uint16 value = in->readUint16LE() >> 2; // Number of resources
+			if (song != value - 1) {
+				in->seek (song * 2 + 2, SEEK_SET);
+				value = in->readUint16LE();
+				size = value - startpos;
+			}
+			in->seek (startpos, SEEK_SET);
+		} else if (size >= 64000) {
+			// For GMF resources not in separate
+			// files, we're going to have to use
+			// hardcoded size tables.
+			size = simon1_gmf_size [song];
+		}
+	}
 
 	// When allocating space, add 4 bytes in case
 	// this is a GMF and we have to tack on our own
@@ -348,10 +382,6 @@
 		if (!sfx)
 			setLoop (p->data[6] != 0);
 
-		// For GMF files, we're going to have to use
-		// hardcoded size tables.
-		if (size == 64000)
-			size = simon1_gmf_size [song];
 	}
 
 	MidiParser *parser = MidiParser::createParser_SMF();





More information about the Scummvm-git-logs mailing list