[Scummvm-git-logs] scummvm master -> e859f4118c9a2e4b0c99b4072af1739544f32916

bluegr noreply at scummvm.org
Wed Dec 25 11:46:19 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e859f4118c SCUMM: More work on the MI1 and MI2 remastered speech


Commit: e859f4118c9a2e4b0c99b4072af1739544f32916
    https://github.com/scummvm/scummvm/commit/e859f4118c9a2e4b0c99b4072af1739544f32916
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2024-12-25T13:45:44+02:00

Commit Message:
SCUMM: More work on the MI1 and MI2 remastered speech

- Injected the audio code in the correct place (displayDialog), from
  disasm provided by @AndyWinXP (thanks!)
- Added support for multiple speech files for the same message
- Added game flag to MI1SE, for using remastered audio

Changed paths:
    engines/scumm/detection_tables.h
    engines/scumm/script_v5.cpp
    engines/scumm/scumm.h
    engines/scumm/sound.cpp
    engines/scumm/sound.h
    engines/scumm/soundse.cpp
    engines/scumm/soundse.h
    engines/scumm/string.cpp


diff --git a/engines/scumm/detection_tables.h b/engines/scumm/detection_tables.h
index 5d64381fbd7..4297fa15c9c 100644
--- a/engines/scumm/detection_tables.h
+++ b/engines/scumm/detection_tables.h
@@ -194,7 +194,7 @@ static const GameSettings gameVariantsTable[] = {
 	{"monkey", "No AdLib", "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_PCJR,                        GF_16COLOR,     Common::kPlatformAtariST, GUIO4(GUIO_NOSPEECH, GUIO_NOMIDI, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI)},
 	{"monkey", "Demo",     "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_PCJR | MDT_CMS | MDT_ADLIB,            GF_16COLOR | GF_DEMO,     Common::kPlatformDOS, GUIO6(GUIO_NOSPEECH, GUIO_NOMIDI, GUIO_RENDERHERCGREEN, GUIO_RENDERHERCAMBER, GUIO_RENDERCGA, GAMEOPTION_ORIGINALGUI)},
 	{"monkey", "CD",           0, GID_MONKEY,     5, 0, MDT_ADLIB,                        GF_AUDIOTRACKS, UNK, GUIO5(GUIO_NOSPEECH, GUIO_NOMIDI, GUIO_RENDEREGA, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI)},
-	{"monkey", "SE",           0, GID_MONKEY,     5, 0, MDT_ADLIB,                        GF_AUDIOTRACKS | GF_DOUBLEFINE_PAK, UNK, GUIO5(GUIO_NOSPEECH, GUIO_NOMIDI, GUIO_RENDEREGA, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI)},
+	{"monkey", "SE",           0, GID_MONKEY,     5, 0, MDT_ADLIB,                        GF_AUDIOTRACKS | GF_DOUBLEFINE_PAK, UNK, GUIO6(GUIO_NOSPEECH, GUIO_NOMIDI, GUIO_RENDEREGA, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI, GAMEOPTION_USE_REMASTERED_AUDIO)},
 	{"monkey", "Mac",          0, GID_MONKEY,     5, 0, MDT_MACINTOSH,                    0, UNK, GUIO6(GUIO_NOSPEECH, GUIO_NOMIDI, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI, GAMEOPTION_COPY_PROTECTION, GUIO_NOASPECT)},
 	{"monkey", "FM-TOWNS",     0, GID_MONKEY,     5, 0, MDT_TOWNS,                        GF_AUDIOTRACKS, Common::kPlatformFMTowns, GUIO6(GUIO_NOSPEECH, GUIO_NOMIDI, GUIO_MIDITOWNS, GAMEOPTION_TRIM_FMTOWNS_TO_200_PIXELS, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI)},
 	{"monkey", "SEGA",         0, GID_MONKEY,     5, 0, MDT_NONE,                         GF_AUDIOTRACKS, Common::kPlatformSegaCD, GUIO4(GUIO_NOSPEECH, GUIO_NOMIDI, GAMEOPTION_ENHANCEMENTS, GAMEOPTION_ORIGINALGUI)},
diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp
index 387ae57619f..adc166d2660 100644
--- a/engines/scumm/script_v5.cpp
+++ b/engines/scumm/script_v5.cpp
@@ -1947,31 +1947,28 @@ void ScummEngine_v5::injectMISESpeech() {
 	// TODOs:
 	// - Correctly calculate the local script offset for all scripts
 	//   (e.g. object scripts, such as Elaine's poster in the second screen)
-	// - Handle multiple speech files for the same message
 	// - Add handling for speech delay
-#if 0
-	if (_game.id == GID_MONKEY && (_game.features & GF_DOUBLEFINE_PAK)) {
-		uint16 currentScriptNum = vm.slot[_currentScript].number;
-		// Ignore texts from global scripts
-		if (currentScriptNum < _numGlobalScripts)
-			return;
+	if (_game.id == GID_MONKEY && (_game.features & GF_DOUBLEFINE_PAK) && _sound->useRemasteredAudio()) {
+		_currentScriptSavedForSpeechMI = vm.slot[_currentScript].number;
+		uint16 localScriptOffset;
+
+		if (_currentScriptSavedForSpeechMI >= _numGlobalScripts) {
+			int16 localScriptNumber = _currentScriptSavedForSpeechMI - _numGlobalScripts;
+			if (localScriptNumber > 56)
+				localScriptOffset = 0;
+			else
+				localScriptOffset = _localScriptOffsets[localScriptNumber];
+		} else {
+			localScriptOffset = 8;
+		}
 
-		// Ignore empty texts
-		if (!memcmp(_scriptPointer, "\xFF\x01\x0F\x00", 4) ||
-			!memcmp(_scriptPointer, "\xFF\x0F\x20\x00", 4) ||
-			!memcmp(_scriptPointer, "\xFE\x01\x0F\x04\x00", 5))
-			return;
+		// TODO: This doesn't work for all scripts, e.g. object scripts
+		_currentScriptOffsetSavedForSpeechMI = _scriptPointer - _scriptOrgPointer - 1 - localScriptOffset;
+		//_currentScriptOffsetSavedForSpeech = vm.slot[_currentScript].offs - 1 - localScriptOffset;	// from disasm
+		_currentSpeechIndexMI = 0;
 
-		// TODO: This isn't calculated correctly for all scripts
-		uint32 localOffset = _scriptPointer - _scriptOrgPointer - 1;
-		if (localOffset > _localScriptOffsets[currentScriptNum - _numGlobalScripts])
-			localOffset -= _localScriptOffsets[currentScriptNum - _numGlobalScripts];
-		// Construct a unique offset for each sound
-		uint32 offset = ((_currentRoom + currentScriptNum) << 16) | (localOffset & 0xFFFF);
-		_sound->talkSound(offset, 10, DIGI_SND_MODE_TALKIE);
-		//debug("injectMISESpeech: room %d, script %d, offset %d", _currentRoom, currentScriptNum, localOffset);
+		// debug("injectMISESpeech: room %d, script %d, offset %d", _currentRoom, _currentScriptSavedForSpeechMI, _currentScriptOffsetSavedForSpeechMI);
 	}
-#endif
 }
 
 void ScummEngine_v5::o5_print() {
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index b5c470be7e9..47be119cb1f 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -883,6 +883,7 @@ protected:
 	int _numTalkies = 0;
 	int _numUnk = 0;
 	int _HEHeapSize = 0;
+
 public:
 	int _numLocalScripts = 60, _numImages = 0, _numRooms = 0, _numScripts = 0, _numSounds = 0;	// Used by HE games
 	int _numCostumes = 0;	// FIXME - should be protected, used by Actor::remapActorPalette
@@ -900,6 +901,11 @@ public:
 
 	int _NESStartStrip = 0;
 
+	/* MI SE injected speech */
+	int16 _currentScriptSavedForSpeechMI = 0;
+	int16 _currentScriptOffsetSavedForSpeechMI = 0;
+	int16 _currentSpeechIndexMI = 0;
+
 protected:
 	int _curPalIndex = 0;
 
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 2bf5ac897cb..c9f74b2aa30 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -609,20 +609,26 @@ void Sound::startTalkSound(uint32 offset, uint32 length, int mode, Audio::SoundH
 			}
 		}
 		return;
-#if 0
-	} else if ((_vm->_game.features & GF_DOUBLEFINE_PAK) && (_vm->_game.id == GID_MONKEY || _vm->_game.id == GID_MONKEY2)) {
+	} else if ((_vm->_game.id == GID_MONKEY || _vm->_game.id == GID_MONKEY2) && (_vm->_game.features & GF_DOUBLEFINE_PAK) && _useRemasteredAudio) {
 		// MI1 and MI2 SE
 		if (_soundSE && !_soundsPaused && _mixer->isReady()) {
 			Audio::AudioStream *input = _soundSE->getAudioStream(
 				offset,
 				mode == DIGI_SND_MODE_SFX ? kSoundSETypeSFX : kSoundSETypeSpeech);
 
-			if (input)
-				_mixer->playStream((mode == DIGI_SND_MODE_SFX) ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, handle, input, id);
+			_digiSndMode |= mode;
+
+			if (input) {
+				if (mode == DIGI_SND_MODE_SFX)
+					_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, input, id);
+				else
+					_mixer->playStream(Audio::Mixer::kSpeechSoundType, handle, input, id);
+			}
+
+			_vm->_currentSpeechIndexMI++;
 		}
 
 		return;
-#endif
 	} else {
 		// This has been verified for INDY4, DOTT and SAM
 		if (_vm->_voiceMode == 2 && _vm->_game.version <= 6)
diff --git a/engines/scumm/sound.h b/engines/scumm/sound.h
index 65088bf913f..d03f206bd06 100644
--- a/engines/scumm/sound.h
+++ b/engines/scumm/sound.h
@@ -150,6 +150,8 @@ public:
 
 	void updateMusicTimer();
 
+	bool useRemasteredAudio() const { return _useRemasteredAudio; }
+
 	// TODO: Duplicate this in Sound as well?
 	bool isRolandLoom() const { return _soundCD->isRolandLoom(); }
 
diff --git a/engines/scumm/soundse.cpp b/engines/scumm/soundse.cpp
index b6d9bd1130a..3849b4f535c 100644
--- a/engines/scumm/soundse.cpp
+++ b/engines/scumm/soundse.cpp
@@ -357,8 +357,12 @@ void SoundSE::initAudioMappingMI() {
 		//	  entry.localScriptOffset, entry.messageIndex, entry.isEgoTalking, entry.wait,
 		//	  entry.textEnglish.c_str(), entry.speechFile.c_str());
 
-		uint32 offset = ((entry.room + entry.script) << 16) | (entry.localScriptOffset & 0xFFFF);
-		_audioNameToOriginalOffsetMap[entry.speechFile] = offset;
+		_audioNameToOriginalOffsetMap[entry.speechFile] = getAudioOffsetForMI(
+			entry.room,
+			entry.script,
+			entry.localScriptOffset,
+			entry.messageIndex
+		);
 
 		_audioEntriesMI.push_back(entry);
 	} while (!f->eos());
@@ -446,10 +450,23 @@ Audio::SeekableAudioStream *SoundSE::createSoundStream(Common::SeekableSubReadSt
 int32 SoundSE::getSoundIndexFromOffset(uint32 offset) {
 	uint32 offsetToCheck = offset;
 
-	if (_vm->_game.id == GID_TENTACLE) {
+	switch (_vm->_game.id) {
+	case GID_MONKEY:
+		if (_vm->_currentScriptSavedForSpeechMI < 0)
+			return -1;
+
+		offsetToCheck = getAudioOffsetForMI(
+			_vm->_currentRoom,
+			_vm->_currentScriptSavedForSpeechMI,
+			offset,
+			_vm->_currentSpeechIndexMI
+		);
+		break;
+	case GID_TENTACLE:
 		// Some of the remastered sound offsets are off compared to the
 		// ones from the classic version, so we chop off the last 2 digits
 		offsetToCheck = offset & 0xFFFFFF00;
+		break;
 	}
 
 	if (_offsetToIndex.contains(offsetToCheck))
@@ -514,4 +531,8 @@ Audio::AudioStream *SoundSE::getAudioStream(uint32 offset, SoundSEType type) {
 	return createSoundStream(subStream, audioEntry);
 }
 
+uint32 SoundSE::getAudioOffsetForMI(uint16 room, uint16 script, uint16 localScriptOffset, uint16 messageIndex) {
+	return ((room + script + messageIndex) << 16) | (localScriptOffset & 0xFFFF);
+}
+
 } // End of namespace Scumm
diff --git a/engines/scumm/soundse.h b/engines/scumm/soundse.h
index 5edb5ba2cd2..8cc795c0e9a 100644
--- a/engines/scumm/soundse.h
+++ b/engines/scumm/soundse.h
@@ -56,6 +56,7 @@ public:
 
 	Audio::SeekableAudioStream *getXWBTrack(int track);
 	Audio::AudioStream *getAudioStream(uint32 offset, SoundSEType type);
+	uint32 getAudioOffsetForMI(uint16 room, uint16 script, uint16 localScriptOffset, uint16 messageIndex);
 
 private:
 	enum AudioCodec {
diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp
index 7c1272d84df..fbb054e6a90 100644
--- a/engines/scumm/string.cpp
+++ b/engines/scumm/string.cpp
@@ -1114,6 +1114,10 @@ void ScummEngine::displayDialog() {
 	if (_isRTL)
 		fakeBidiString(_charsetBuffer + _charsetBufPos, true, sizeof(_charsetBuffer) - _charsetBufPos);
 
+	if ((_game.features & GF_DOUBLEFINE_PAK) && _game.id == GID_MONKEY && _sound->useRemasteredAudio()) {
+		_sound->talkSound(_currentScriptOffsetSavedForSpeechMI, 0, DIGI_SND_MODE_TALKIE);
+	}
+
 	bool createTextBox = (_macGui && _game.id == GID_INDY3);
 	bool drawTextBox = false;
 




More information about the Scummvm-git-logs mailing list