diff options
-rw-r--r-- | engines/sci/sound/soundcmd.cpp | 31 | ||||
-rw-r--r-- | engines/sci/sound/soundcmd.h | 1 |
2 files changed, 19 insertions, 13 deletions
diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp index 4ea290ff9e..d4cff7614c 100644 --- a/engines/sci/sound/soundcmd.cpp +++ b/engines/sci/sound/soundcmd.cpp @@ -49,11 +49,22 @@ reg_t SoundCommandParser::kDoSoundInit(int argc, reg_t *argv, reg_t acc) { return acc; } -void SoundCommandParser::processInitSound(reg_t obj) { - int resourceId = readSelectorValue(_segMan, obj, SELECTOR(number)); +int SoundCommandParser::getSoundResourceId(reg_t obj) { + int resourceId = obj.segment ? readSelectorValue(_segMan, obj, SELECTOR(number)) : -1; // Modify the resourceId for the Windows versions that have an alternate MIDI soundtrack, like SSCI did. - if (g_sci && g_sci->_features->useAltWinGMSound()) - resourceId += 1000; + if (g_sci && g_sci->_features->useAltWinGMSound()) { + // Check if the alternate MIDI song actually exists... + // There are cases where it just doesn't exist (e.g. SQ4, room 530 - + // bug #3392767). In these cases, use the DOS tracks instead. + if (resourceId && _resMan->testResource(ResourceId(kResourceTypeSound, resourceId + 1000))) + resourceId += 1000; + } + + return resourceId; +} + +void SoundCommandParser::processInitSound(reg_t obj) { + int resourceId = getSoundResourceId(obj); // Check if a track with the same sound object is already playing MusicEntry *oldSound = _music->getSlot(obj); @@ -123,10 +134,7 @@ void SoundCommandParser::processPlaySound(reg_t obj) { return; } - int resourceId = obj.segment ? readSelectorValue(_segMan, obj, SELECTOR(number)) : -1; - // Modify the resourceId for the Windows versions that have an alternate MIDI soundtrack, like SSCI did. - if (g_sci && g_sci->_features->useAltWinGMSound()) - resourceId += 1000; + int resourceId = getSoundResourceId(obj); if (musicSlot->resourceId != resourceId) { // another sound loaded into struct processDisposeSound(obj); @@ -618,13 +626,10 @@ reg_t SoundCommandParser::kDoSoundSetPriority(int argc, reg_t *argv, reg_t acc) } if (value == -1) { - uint16 resourceNr = musicSlot->resourceId; - // Modify the resourceId for the Windows versions that have an alternate MIDI soundtrack, like SSCI did. - if (g_sci && g_sci->_features->useAltWinGMSound()) - resourceNr += 1000; + uint16 resourceId = musicSlot->resourceId; // Set priority from the song data - Resource *song = _resMan->findResource(ResourceId(kResourceTypeSound, resourceNr), 0); + Resource *song = _resMan->findResource(ResourceId(kResourceTypeSound, resourceId), 0); if (song->data[0] == 0xf0) _music->soundSetPriority(musicSlot, song->data[1]); else diff --git a/engines/sci/sound/soundcmd.h b/engines/sci/sound/soundcmd.h index a542a8b384..7f6e2a0fe8 100644 --- a/engines/sci/sound/soundcmd.h +++ b/engines/sci/sound/soundcmd.h @@ -113,6 +113,7 @@ private: void processInitSound(reg_t obj); void processDisposeSound(reg_t obj); void processUpdateCues(reg_t obj); + int getSoundResourceId(reg_t obj); }; } // End of namespace Sci |