aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamieson Christian2003-07-24 04:19:42 +0000
committerJamieson Christian2003-07-24 04:19:42 +0000
commit17a888b65a9fb700099b65688d0c8dcfcc95de3f (patch)
treeab97c7845af33172bbf2369d7c178b9fb1da47ff
parent03e720dabee20a7eee2e9c1534ac0178d3d9dc43 (diff)
downloadscummvm-rg350-17a888b65a9fb700099b65688d0c8dcfcc95de3f.tar.gz
scummvm-rg350-17a888b65a9fb700099b65688d0c8dcfcc95de3f.tar.bz2
scummvm-rg350-17a888b65a9fb700099b65688d0c8dcfcc95de3f.zip
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. svn-id: r9155
-rw-r--r--simon/midi.cpp52
1 files changed, 41 insertions, 11 deletions
diff --git a/simon/midi.cpp b/simon/midi.cpp
index dc4ac95cf8..ae562a58a8 100644
--- a/simon/midi.cpp
+++ b/simon/midi.cpp
@@ -129,10 +129,11 @@ void MidiPlayer::send (uint32 b) {
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 @@ void MidiPlayer::clearConstructs (MusicInfo &info) {
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 @@ void MidiPlayer::loadSMF (File *in, int song, bool sfx) {
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 @@ void MidiPlayer::loadSMF (File *in, int song, bool sfx) {
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();