Skip to content

Commit

Permalink
TINSEL: Fix bug #3541230 - "DW: PSX version locks up after using the …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
bluegr committed Jul 8, 2012
1 parent 078c09c commit b8354e2
Showing 1 changed file with 43 additions and 52 deletions.
95 changes: 43 additions & 52 deletions engines/tinsel/music.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b8354e2

Please sign in to comment.