aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel
diff options
context:
space:
mode:
authorFilippos Karapetis2012-07-09 01:31:25 +0300
committerFilippos Karapetis2012-07-09 01:33:40 +0300
commitb8354e27ae1c81578d9ac279dcba9bf09ccec058 (patch)
tree0f147948c06a786280644d3fa9bef9bbedf4abfc /engines/tinsel
parent078c09c13e5ffa2266bccfd85c38a93d730a02e6 (diff)
downloadscummvm-rg350-b8354e27ae1c81578d9ac279dcba9bf09ccec058.tar.gz
scummvm-rg350-b8354e27ae1c81578d9ac279dcba9bf09ccec058.tar.bz2
scummvm-rg350-b8354e27ae1c81578d9ac279dcba9bf09ccec058.zip
TINSEL: Fix bug #3541230 - "DW: PSX version locks up after using the book"
Removed the superfluous MIDI offset storing code. Now, the MIDI buffer is re-read when the music loops. This removes a static variable and also fixes another bug in the SEQ decoder.
Diffstat (limited to 'engines/tinsel')
-rw-r--r--engines/tinsel/music.cpp95
1 files changed, 43 insertions, 52 deletions
diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp
index fa5334a033..a226feb656 100644
--- a/engines/tinsel/music.cpp
+++ b/engines/tinsel/music.cpp
@@ -140,7 +140,6 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) {
}
// the index and length of the last tune loaded
- static uint32 dwLastMidiIndex = 0; // FIXME: Avoid non-const global vars
uint32 dwSeqLen = 0; // length of the sequence
// Support for external music from the music enhancement project
@@ -181,61 +180,53 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) {
if (dwFileOffset == 0)
return true;
- if (dwFileOffset != dwLastMidiIndex) {
- Common::File midiStream;
-
- // open MIDI sequence file in binary mode
- if (!midiStream.open(MIDI_FILE))
- error(CANNOT_FIND_FILE, MIDI_FILE);
-
- // update index of last tune loaded
- dwLastMidiIndex = dwFileOffset;
-
- // move to correct position in the file
- midiStream.seek(dwFileOffset, SEEK_SET);
-
- // read the length of the sequence
- dwSeqLen = midiStream.readUint32LE();
-
- // make sure buffer is large enough for this sequence
- assert(dwSeqLen > 0 && dwSeqLen <= g_midiBuffer.size);
-
- // stop any currently playing tune
- _vm->_midiMusic->stop();
-
- // read the sequence
- if (midiStream.read(g_midiBuffer.pDat, dwSeqLen) != dwSeqLen)
- error(FILE_IS_CORRUPT, MIDI_FILE);
-
- midiStream.close();
-
- // WORKAROUND for bug #2820054 "DW1: No intro music at first start on Wii",
- // which actually affects all ports, since it's specific to the GRA version.
- //
- // The GRA version does not seem to set the channel volume at all for the first
- // intro track, thus we need to do that here. We only initialize the channels
- // used in that sequence. And we are using 127 as default channel volume.
- //
- // Only in the GRA version dwFileOffset can be "38888", just to be sure, we
- // check for the SCN files feature flag not being set though.
- if (_vm->getGameID() == GID_DW1 && dwFileOffset == 38888 && !(_vm->getFeatures() & GF_SCNFILES)) {
- _vm->_midiMusic->send(0x7F07B0 | 3);
- _vm->_midiMusic->send(0x7F07B0 | 5);
- _vm->_midiMusic->send(0x7F07B0 | 8);
- _vm->_midiMusic->send(0x7F07B0 | 10);
- _vm->_midiMusic->send(0x7F07B0 | 13);
- }
+ Common::File midiStream;
+
+ // open MIDI sequence file in binary mode
+ if (!midiStream.open(MIDI_FILE))
+ error(CANNOT_FIND_FILE, MIDI_FILE);
- _vm->_midiMusic->playMIDI(dwSeqLen, bLoop);
+ // move to correct position in the file
+ midiStream.seek(dwFileOffset, SEEK_SET);
- // Store the length
- //dwLastSeqLen = dwSeqLen;
- } else {
- // dwFileOffset == dwLastMidiIndex
- _vm->_midiMusic->stop();
- _vm->_midiMusic->playMIDI(dwSeqLen, bLoop);
+ // read the length of the sequence
+ dwSeqLen = midiStream.readUint32LE();
+
+ // make sure buffer is large enough for this sequence
+ assert(dwSeqLen > 0 && dwSeqLen <= g_midiBuffer.size);
+
+ // stop any currently playing tune
+ _vm->_midiMusic->stop();
+
+ // read the sequence. This needs to be read again before playSEQ() is
+ // called even if the music is restarting, as playSEQ() reads the file
+ // name off the buffer itself. However, that function adds SMF headers
+ // to the buffer, thus if it's read again, the SMF headers will be read
+ // and the filename will always be 'MThd'.
+ if (midiStream.read(g_midiBuffer.pDat, dwSeqLen) != dwSeqLen)
+ error(FILE_IS_CORRUPT, MIDI_FILE);
+
+ midiStream.close();
+
+ // WORKAROUND for bug #2820054 "DW1: No intro music at first start on Wii",
+ // which actually affects all ports, since it's specific to the GRA version.
+ //
+ // The GRA version does not seem to set the channel volume at all for the first
+ // intro track, thus we need to do that here. We only initialize the channels
+ // used in that sequence. And we are using 127 as default channel volume.
+ //
+ // Only in the GRA version dwFileOffset can be "38888", just to be sure, we
+ // check for the SCN files feature flag not being set though.
+ if (_vm->getGameID() == GID_DW1 && dwFileOffset == 38888 && !(_vm->getFeatures() & GF_SCNFILES)) {
+ _vm->_midiMusic->send(0x7F07B0 | 3);
+ _vm->_midiMusic->send(0x7F07B0 | 5);
+ _vm->_midiMusic->send(0x7F07B0 | 8);
+ _vm->_midiMusic->send(0x7F07B0 | 10);
+ _vm->_midiMusic->send(0x7F07B0 | 13);
}
+ _vm->_midiMusic->playMIDI(dwSeqLen, bLoop);
+
return true;
}