[Scummvm-git-logs] scummvm master -> 2fbf32bfd3be50491799ac0efa6c8b7110aab364

bluegr noreply at scummvm.org
Wed Jan 8 09:56:56 UTC 2025


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:
2fbf32bfd3 SCUMM: Merge duplicate SE audio code. Some cleanup


Commit: 2fbf32bfd3be50491799ac0efa6c8b7110aab364
    https://github.com/scummvm/scummvm/commit/2fbf32bfd3be50491799ac0efa6c8b7110aab364
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2025-01-08T11:56:23+02:00

Commit Message:
SCUMM: Merge duplicate SE audio code. Some cleanup

Changed paths:
    engines/scumm/sound.cpp
    engines/scumm/soundcd.cpp
    engines/scumm/soundse.cpp
    engines/scumm/soundse.h


diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp
index 8cdd7e6adf0..4ba45b5b7ef 100644
--- a/engines/scumm/sound.cpp
+++ b/engines/scumm/sound.cpp
@@ -2196,7 +2196,7 @@ 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
 
-	int32 soundIndex = _soundSE->handleRemasteredSpeech(
+	int32 soundIndex = _soundSE->handleMISESpeech(
 		msgString,
 		nullptr,
 		roomNumber,
diff --git a/engines/scumm/soundcd.cpp b/engines/scumm/soundcd.cpp
index 4beabb4c42d..695dad9af95 100644
--- a/engines/scumm/soundcd.cpp
+++ b/engines/scumm/soundcd.cpp
@@ -149,7 +149,7 @@ void SoundCD::playCDTrackInternal(int track, int numLoops, int startFrame, int d
 		if (_vm->_game.id == GID_LOOM) {
 			stream = makeCDDAStream("CDDA.SOU", DisposeAfterUse::YES);
 		} else if (_soundSE) {
-			stream = _soundSE->getXWBTrack(track);
+			stream = _soundSE->getAudioStream(track, kSoundSETypeCDAudio);
 		}
 
 		if (!stream)
diff --git a/engines/scumm/soundse.cpp b/engines/scumm/soundse.cpp
index 0e9b9b10158..2b9972ca2de 100644
--- a/engines/scumm/soundse.cpp
+++ b/engines/scumm/soundse.cpp
@@ -106,29 +106,6 @@ void SoundSE::initSoundFiles() {
 	}
 }
 
-Audio::SeekableAudioStream *SoundSE::getXWBTrack(int track) {
-	if (track < 0 || track >= (int)_musicEntries.size())
-		return nullptr;
-
-	Common::File *cdAudioFile = new Common::File();
-
-	if (!cdAudioFile->open(Common::Path(_musicFilename))) {
-		delete cdAudioFile;
-		return nullptr;
-	}
-
-	AudioEntry entry = _musicEntries[track];
-
-	Common::SeekableSubReadStream *subStream = new Common::SeekableSubReadStream(
-		cdAudioFile,
-		entry.offset,
-		entry.offset + entry.length,
-		DisposeAfterUse::YES
-	);
-
-	return createSoundStream(subStream, entry, DisposeAfterUse::YES);
-}
-
 #define WARN_AND_RETURN_XWB(message)          \
 	{                                         \
 		warning("indexXWBFile: %s", message); \
@@ -140,7 +117,7 @@ Audio::SeekableAudioStream *SoundSE::getXWBTrack(int track) {
 void SoundSE::indexXWBFile(const Common::String &filename, AudioIndex *audioIndex) {
 	// This implementation is based off unxwb: https://github.com/mariodon/unxwb/
 	// as well as xwbdump: https://raw.githubusercontent.com/wiki/Microsoft/DirectXTK/xwbdump.cpp
-	// Only the parts that apply to the Doublefine releases of
+	// Only the parts that apply to the Special Editions of
 	// MI1 and MI2 have been implemented.
 
 	struct SegmentData {
@@ -220,7 +197,7 @@ void SoundSE::indexXWBFile(const Common::String &filename, AudioIndex *audioInde
 
 #define WARN_AND_RETURN_XSB(message)          \
 	{                                         \
-		warning("indexMI2SpeechFiles: %s", message); \
+		warning("indexXSBFile: %s", message); \
 		f->close();                           \
 		delete f;                             \
 		return;                               \
@@ -701,11 +678,11 @@ int32 SoundSE::getAppropriateSpeechCue(const char *msgString, const char *speech
 	return bestScoreIdx;
 }
 
-Audio::AudioStream *SoundSE::getAudioStream(uint32 offset, SoundSEType type) {
+Audio::SeekableAudioStream *SoundSE::getAudioStream(uint32 offset, SoundSEType type) {
 	Common::SeekableReadStream *stream;
 	Common::String audioFileName;
 	AudioEntry audioEntry = {};
-	int32 soundIndex = getSoundIndexFromOffset(offset);
+	int32 soundIndex = (type != kSoundSETypeCDAudio) ? getSoundIndexFromOffset(offset) : (int32)offset;
 
 	if (soundIndex == -1) {
 		warning("getAudioStream: sound index not found for offset %d", offset);
@@ -714,6 +691,7 @@ Audio::AudioStream *SoundSE::getAudioStream(uint32 offset, SoundSEType type) {
 
 	switch (type) {
 	case kSoundSETypeMusic:
+	case kSoundSETypeCDAudio:
 		audioFileName = _musicFilename;
 		audioEntry = _musicEntries[soundIndex];
 		break;
@@ -750,7 +728,7 @@ Audio::AudioStream *SoundSE::getAudioStream(uint32 offset, SoundSEType type) {
 		DisposeAfterUse::YES
 	);
 
-	return createSoundStream(subStream, audioEntry, DisposeAfterUse::YES);
+	return createSoundStream(subStream, audioEntry);
 }
 
 Common::String calculateCurrentString(const char *msgString) {
@@ -839,7 +817,7 @@ Common::String calculateCurrentString(const char *msgString) {
 	return result;
 }
 
-int32 SoundSE::handleRemasteredSpeech(const char *msgString, const char *speechFilenameSubstitution,
+int32 SoundSE::handleMISESpeech(const char *msgString, const char *speechFilenameSubstitution,
 								     uint16 roomNumber, uint16 actorTalking, uint16 numWaits) {
 
 	// Get the string without the various control codes and special characters...
diff --git a/engines/scumm/soundse.h b/engines/scumm/soundse.h
index e78e975ce6b..e74f637cf99 100644
--- a/engines/scumm/soundse.h
+++ b/engines/scumm/soundse.h
@@ -41,55 +41,24 @@ class ScummEngine;
 enum SoundSEType {
 	kSoundSETypeMusic,
 	kSoundSETypeSpeech,
-	kSoundSETypeSFX
+	kSoundSETypeSFX,
+	kSoundSETypeCDAudio
 };
 
 class SoundSE {
 
-protected:
-	// Used in MI1 + MI2
-	struct AudioEntryMI {
-		uint32 hash;
-		uint16 room;
-		uint16 script;
-		uint16 localScriptOffset;
-		uint16 messageIndex;        // message index, used in messages split with wait()
-		uint16 isEgoTalking;        // 1 if ego is talking, 0 otherwise
-		uint16 wait;                // wait time in ms
-		Common::String textEnglish; // 256 bytes, English text
-		Common::String textFrench;  // 256 bytes, French text
-		Common::String textItalian; // 256 bytes, Italian text
-		Common::String textGerman;  // 256 bytes, German text
-		Common::String textSpanish; // 256 bytes, Spanish text
-		Common::String speechFile;  // 32 bytes
-
-		int32 hashFourCharString; // Hash calculated on a four char string, from disasm
-	};
-
-	ScummEngine *_vm;
-	Audio::Mixer *_mixer;
-
 public:
 	SoundSE(ScummEngine *parent, Audio::Mixer *mixer);
 	~SoundSE() = default;
 
-	Audio::SeekableAudioStream *getXWBTrack(int track);
-	Audio::AudioStream *getAudioStream(uint32 offset, SoundSEType type);
+	Audio::SeekableAudioStream *getAudioStream(uint32 offset, SoundSEType type);
 
-	int32 handleRemasteredSpeech(const char *msgString,
+	int32 handleMISESpeech(const char *msgString,
 								const char *speechFilenameSubstitution,
 								uint16 roomNumber,
 								uint16 actorTalking,
 								uint16 numWaits);
 
-	int32 getAppropriateSpeechCue(const char *msgString,
-										  const char *speechFilenameSubstitution,
-										  uint16 roomNumber,
-										  uint16 actorTalking,
-										  uint16 scriptNum,
-										  uint16 scriptOffset,
-										  uint16 numWaits);
-
 	void setupMISEAudioParams(int32 scriptNum, int32 scriptOffset) {
 		_currentScriptSavedForSpeechMI = scriptNum;
 		_currentScriptOffsetSavedForSpeechMI = scriptOffset;
@@ -112,6 +81,25 @@ private:
 		kXWBSegmentEntryWaveData = 4
 	};
 
+	// Used in MI1 + MI2
+	struct AudioEntryMI {
+		uint32 hash;
+		uint16 room;
+		uint16 script;
+		uint16 localScriptOffset;
+		uint16 messageIndex;        // message index, used in messages split with wait()
+		uint16 isEgoTalking;        // 1 if ego is talking, 0 otherwise
+		uint16 wait;                // wait time in ms
+		Common::String textEnglish; // 256 bytes, English text
+		Common::String textFrench;  // 256 bytes, French text
+		Common::String textItalian; // 256 bytes, Italian text
+		Common::String textGerman;  // 256 bytes, German text
+		Common::String textSpanish; // 256 bytes, Spanish text
+		Common::String speechFile;  // 32 bytes
+
+		int32 hashFourCharString; // Hash calculated on a four char string, from disasm
+	};
+
 	struct AudioEntry {
 		uint64 offset;
 		uint32 length;
@@ -123,6 +111,9 @@ private:
 		Common::String name;
 	};
 
+	ScummEngine *_vm;
+	Audio::Mixer *_mixer;
+
 	typedef Common::Array<AudioEntry> AudioIndex;
 	typedef Common::HashMap<uint32, uint32> OffsetToIndexMap;
 	typedef Common::HashMap<Common::String, int32> NameToIndexMap;
@@ -147,19 +138,26 @@ private:
 	int32 _currentScriptOffsetSavedForSpeechMI = 0;
 
 	int32 getSoundIndexFromOffset(uint32 offset);
+	int32 getAppropriateSpeechCue(const char *msgString,
+								  const char *speechFilenameSubstitution,
+								  uint16 roomNumber,
+								  uint16 actorTalking,
+								  uint16 scriptNum,
+								  uint16 scriptOffset,
+								  uint16 numWaits);
 
 	void initAudioMappingMI();
 	void initAudioMappingDOTTAndFT();
 	void initSoundFiles();
 
-	// Index XWB audio files - used in MI1SE and MI2SE
+	// Index XWB audio files and XSB cue files - used in MI1SE and MI2SE
 	void indexXWBFile(const Common::String &filename, AudioIndex *audioIndex);
 	void indexXSBFile(const Common::String &filename, AudioIndex *audioIndex);
 
 	// Index FSB audio files - used in DOTT and FT
 	void indexFSBFile(const Common::String &filename, AudioIndex *audioIndex);
 
-	Audio::SeekableAudioStream *createSoundStream(Common::SeekableSubReadStream *stream, AudioEntry entry, DisposeAfterUse::Flag disposeAfterUse);
+	Audio::SeekableAudioStream *createSoundStream(Common::SeekableSubReadStream *stream, AudioEntry entry, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
 };
 
 




More information about the Scummvm-git-logs mailing list