[Scummvm-cvs-logs] CVS: scummvm/sound midiparser_smf.cpp,1.18,1.19

Jamieson Christian jamieson630 at users.sourceforge.net
Sat May 1 06:17:04 CEST 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4212/scummvm/sound

Modified Files:
	midiparser_smf.cpp 
Log Message:
Fix for [945497] Possible bug in midiparser_smf.cpp

Corrected Type 0 SMF compression to properly account
for command lengths when Running Status is being used.
Also increased buffer size for Type 0 output since
Running Status can result in the Type 0 output being
larger than the source data. Needs some more work,
but at least the Wyrmkeep people can keep going in
the meantime.

Index: midiparser_smf.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/midiparser_smf.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- midiparser_smf.cpp	30 Apr 2004 17:48:20 -0000	1.18
+++ midiparser_smf.cpp	1 May 2004 13:16:45 -0000	1.19
@@ -47,7 +47,7 @@
 
 
 static const byte command_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 0 };
-static const byte special_lengths[16] = { 0, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 };
+static const byte special_lengths[16] = { 0, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 };
 
 MidiParser_SMF::~MidiParser_SMF() {
 	if (_buffer)
@@ -217,7 +217,7 @@
 	}
 
 	if (midi_type == 1) {
-		_buffer = (byte *) calloc (size, 1);
+		_buffer = (byte *) malloc (size);
 		compressToType0();
 		_num_tracks = 1;
 		_tracks[0] = _buffer;
@@ -278,12 +278,15 @@
 		}
 
 		// Process MIDI event.
+		bool implicitEvent = false;
 		copy_bytes = 0;
 		pos = track_pos[best_i];
 		do {
 			event = *(pos++);
-			if (event < 0x80)
+			if (event < 0x80) {
 				event = running_status[best_i];
+				implicitEvent = true;
+			}
 		} while (_malformedPitchBends && (event & 0xF0) == 0xE0 && pos++);
 		running_status[best_i] = event;
 
@@ -334,6 +337,10 @@
 				*output++ = (byte) (delta & 0xFF);
 
 				// Write MIDI data
+				if (!implicitEvent)
+					++track_pos[best_i];
+				--copy_bytes;
+				*output++ = running_status[best_i];
 				memcpy (output, track_pos[best_i], copy_bytes);
 				output += copy_bytes;
 			}





More information about the Scummvm-git-logs mailing list