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

AndywinXp noreply at scummvm.org
Sun Dec 29 21:05:07 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:
bc8e3b5280 SCUMM: MI1SE: Implement speech playback


Commit: bc8e3b52804395e0c6e59ddd3a594666b6577924
    https://github.com/scummvm/scummvm/commit/bc8e3b52804395e0c6e59ddd3a594666b6577924
Author: AndywinXp (andywinxp at gmail.com)
Date: 2024-12-29T22:05:02+01:00

Commit Message:
SCUMM: MI1SE: Implement speech playback

What is now missing is the delay time between phrases.
Some of the code will be refactored, since this was
hacked in for mantaining compatibility with stuff outside
of MI1:SE.

Changed paths:
    engines/scumm/script_v5.cpp
    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/script_v5.cpp b/engines/scumm/script_v5.cpp
index aa03436cafa..32581a8eafe 100644
--- a/engines/scumm/script_v5.cpp
+++ b/engines/scumm/script_v5.cpp
@@ -1942,20 +1942,14 @@ void ScummEngine_v5::o5_pickupObject() {
 	runInventoryScript(1);
 }
 
-// Inject the speech from the SE version in the classic one, for MI1SE
+// Inject the speech from the SE version in the classic one, for MI1SE.
 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)
-	// - Add handling for speech delay
 	if (_game.id == GID_MONKEY && (_game.features & GF_DOUBLEFINE_PAK) && _sound->useRemasteredAudio()) {
 		_currentScriptSavedForSpeechMI = vm.slot[_currentScript].number;
 		uint16 localScriptOffset;
 
-		int numGlobalScripts = _numGlobalScripts - 1; // It has to be 199 instead of 200
-
-		if (_currentScriptSavedForSpeechMI >= numGlobalScripts) {
-			int16 localScriptNumber = _currentScriptSavedForSpeechMI - numGlobalScripts;
+		if (_currentScriptSavedForSpeechMI >= _numGlobalScripts) {
+			int16 localScriptNumber = _currentScriptSavedForSpeechMI - _numGlobalScripts;
 			if (localScriptNumber > 56)
 				localScriptOffset = 0;
 			else
@@ -1964,12 +1958,8 @@ void ScummEngine_v5::injectMISESpeech() {
 			localScriptOffset = 8;
 		}
 
-		// TODO: This doesn't work for all scripts, e.g. object scripts
-		//_currentScriptOffsetSavedForSpeechMI = _scriptPointer - _scriptOrgPointer - 1 - localScriptOffset;
-		_currentScriptOffsetSavedForSpeechMI = vm.slot[_currentScript].offs - localScriptOffset; // from disasm
+		_currentScriptOffsetSavedForSpeechMI = vm.slot[_currentScript].offs - localScriptOffset;
 		_currentSpeechIndexMI = 0;
-
-		// debug("injectMISESpeech: room %d, script %d, offset %d", _currentRoom, _currentScriptSavedForSpeechMI, _currentScriptOffsetSavedForSpeechMI);
 	}
 }
 
diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index b2282783e5d..5ee7a29bb7d 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -613,7 +613,7 @@ void Sound::startTalkSound(uint32 offset, uint32 length, int mode, Audio::SoundH
 		// MI1 and MI2 SE
 		if (_soundSE && !_soundsPaused && _mixer->isReady()) {
 			Audio::AudioStream *input = _soundSE->getAudioStream(
-				offset,
+				_currentMISpeechIndex,
 				mode == DIGI_SND_MODE_SFX ? kSoundSETypeSFX : kSoundSETypeSpeech);
 
 			_digiSndMode |= mode;
@@ -2196,7 +2196,12 @@ void Sound::startRemasteredSpeech(const char *msgString, uint16 roomNumber, uint
 	// Crudely adapted from the disasm of MI1SE...
 	// TODO: Apply the various speech-line substitutions performed per-game
 
-	_soundSE->handleRemasteredSpeech(msgString, nullptr, roomNumber, actorTalking, currentScriptNum, currentScriptOffset, numWaits);
+	int32 soundIndex = _soundSE->handleRemasteredSpeech(msgString, nullptr, roomNumber, actorTalking, currentScriptNum, currentScriptOffset, numWaits);
+
+	if (soundIndex >= 0) {
+		_currentMISpeechIndex = soundIndex;
+		talkSound(0, 0, DIGI_SND_MODE_TALKIE);
+	}
 }
 
 } // End of namespace Scumm
diff --git a/engines/scumm/sound.h b/engines/scumm/sound.h
index 8d3f65b79de..cd44f1f3280 100644
--- a/engines/scumm/sound.h
+++ b/engines/scumm/sound.h
@@ -103,6 +103,8 @@ protected:
 	SoundSE *_soundSE = nullptr;
 	bool _useRemasteredAudio = false;
 
+	int32 _currentMISpeechIndex = -1;
+
 public:
 	Audio::SoundHandle *_talkChannelHandle;	// Handle of mixer channel actor is talking on
 
diff --git a/engines/scumm/soundse.cpp b/engines/scumm/soundse.cpp
index e2c54bf396d..f7ffcbacffe 100644
--- a/engines/scumm/soundse.cpp
+++ b/engines/scumm/soundse.cpp
@@ -191,12 +191,14 @@ void SoundSE::indexXWBFile(const Common::String &filename, AudioIndex *audioInde
 
 		if (!_audioNameToOriginalOffsetMap.contains(name)) {
 			// warning("indexXWBFile: name %s not found in speech.info", name.c_str());
+			_nameToIndex[name] = i;
 			continue;
 		}
-
+		
 		const uint32 origOffset = _audioNameToOriginalOffsetMap[name];
 		_offsetToIndex[origOffset] = i;
 		// debug("indexXWBFile: %s -> offset %d, index %d", name.c_str(), origOffset, i);
+		_nameToIndex[name] = i;
 	}
 
 	f->close();
@@ -468,7 +470,7 @@ void SoundSE::initAudioMappingMI() {
 		entry.textSpanish = f->readString(0, 256);
 
 		entry.speechFile  = f->readString(0, 32);
-		//entry.speechFile.toLowercase();
+		entry.speechFile.toLowercase();
 
 		entry.hashFourCharString = calculate4CharStringHash(entry.textEnglish.c_str()); // From disasm
 
@@ -570,29 +572,20 @@ Audio::SeekableAudioStream *SoundSE::createSoundStream(Common::SeekableSubReadSt
 int32 SoundSE::getSoundIndexFromOffset(uint32 offset) {
 	uint32 offsetToCheck = offset;
 
-	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:
+	if (_vm->_game.id == GID_MONKEY || _vm->_game.id == GID_MONKEY2) {
+		return offset;
+	} else if (_vm->_game.id == 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))
+			return _offsetToIndex[offsetToCheck];
+		else
+			return -1;
 	}
 
-	if (_offsetToIndex.contains(offsetToCheck))
-		return _offsetToIndex[offsetToCheck];
-	else
-		return -1;
+	return -1;
 }
 
 SoundSE::AudioEntryMI *SoundSE::getAppropriateSpeechCue(const char *msgString, const char *speechFilenameSubstitution,
@@ -806,15 +799,19 @@ Common::String calculateCurrentString(const char *msgString) {
 	return result;
 }
 
-void SoundSE::handleRemasteredSpeech(const char *msgString, const char *speechFilenameSubstitution,
+int32 SoundSE::handleRemasteredSpeech(const char *msgString, const char *speechFilenameSubstitution,
 								     uint16 roomNumber, uint16 actorTalking, uint16 scriptNum, uint16 scriptOffset, uint16 numWaits) {
 
 	// Get the string without the various control codes and special characters...
 	Common::String currentString = calculateCurrentString(msgString);
 	AudioEntryMI *entry = getAppropriateSpeechCue(currentString.c_str(), speechFilenameSubstitution, roomNumber, actorTalking, scriptNum, scriptOffset, numWaits);
-	if (entry)
+	if (entry) {
 		debug("Selected entry: %s (%s)", entry->textEnglish.c_str(), entry->speechFile.c_str());
 
+		return _nameToIndex[entry->speechFile];
+	}
+
+	return -1;
 }
 
 } // End of namespace Scumm
diff --git a/engines/scumm/soundse.h b/engines/scumm/soundse.h
index 42d344ee502..26fc4cc9594 100644
--- a/engines/scumm/soundse.h
+++ b/engines/scumm/soundse.h
@@ -77,7 +77,7 @@ public:
 	Audio::AudioStream *getAudioStream(uint32 offset, SoundSEType type);
 	uint32 getAudioOffsetForMI(int32 room, int32 script, int32 localScriptOffset, int32 messageIndex);
 
-	void handleRemasteredSpeech(const char *msgString,
+	int32 handleRemasteredSpeech(const char *msgString,
 								const char *speechFilenameSubstitution,
 								uint16 roomNumber,
 								uint16 actorTalking,
@@ -125,8 +125,10 @@ private:
 
 	typedef Common::Array<AudioEntry> AudioIndex;
 	typedef Common::HashMap<uint32, uint32> OffsetToIndexMap;
+	typedef Common::HashMap<Common::String, int32> NameToIndexMap;
 
 	OffsetToIndexMap _offsetToIndex;
+	NameToIndexMap _nameToIndex;
 
 	AudioIndex _musicEntries;
 	Common::String _musicFilename;
diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp
index 36384a88d6c..cb0ba8b2afc 100644
--- a/engines/scumm/string.cpp
+++ b/engines/scumm/string.cpp
@@ -1114,8 +1114,7 @@ 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);
+	if ((_game.features & GF_DOUBLEFINE_PAK) && (_game.id == GID_MONKEY || _game.id == GID_MONKEY2) && _sound->useRemasteredAudio()) {
 		int numberOfWaits = countNumberOfWaits();
 		int32 currentActor = VAR_TALK_ACTOR != 0xFF ? VAR(VAR_TALK_ACTOR) : 0;
 




More information about the Scummvm-git-logs mailing list