[Scummvm-git-logs] scummvm master -> 497ff53c949e3825d999594a3d832ab53c931a78

somaen einarjohants at gmail.com
Mon Mar 1 20:52:36 UTC 2021


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

Summary:
483ead52dd TINSEL: Implement music playback for Discworld Noir
497ff53c94 TINSEL: Map SHOWMENU


Commit: 483ead52dd5caa446191af4827a2bbb3d5f3b94d
    https://github.com/scummvm/scummvm/commit/483ead52dd5caa446191af4827a2bbb3d5f3b94d
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2021-03-01T21:52:25+01:00

Commit Message:
TINSEL: Implement music playback for Discworld Noir

Changed paths:
    engines/tinsel/music.cpp
    engines/tinsel/music.h
    engines/tinsel/tinlib.cpp


diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp
index f5b904ff47..9c812b3064 100644
--- a/engines/tinsel/music.cpp
+++ b/engines/tinsel/music.cpp
@@ -29,6 +29,8 @@
 #include "audio/midiparser.h"
 // Miles Audio for Discworld 1
 #include "audio/miles.h"
+// Discworld Noir
+#include "audio/decoders/mp3.h"
 
 #include "backends/audiocd/audiocd.h"
 
@@ -757,6 +759,26 @@ int PCMMusicPlayer::readBuffer(int16 *buffer, const int numSamples) {
 	return (numSamples - samplesLeft);
 }
 
+bool PCMMusicPlayer::isStereo() const {
+	if (TinselV3) {
+		return true;
+	} else {
+		return false;
+	}
+}
+
+int PCMMusicPlayer::getRate() const {
+	if (TinselV3) {
+		if (_curChunk) {
+			return _curChunk->getRate();
+		} else {
+			return 0;
+		}
+	} else {
+		return 22050;
+	}
+}
+
 bool PCMMusicPlayer::isPlaying() const {
 	return ((_state != S_IDLE) && (_state != S_STOP));
 }
@@ -804,11 +826,6 @@ void PCMMusicPlayer::restoreThatTune(void *voidPtr) {
 void PCMMusicPlayer::setMusicSceneDetails(SCNHANDLE hScript,
 		SCNHANDLE hSegment, const char *fileName) {
 
-	if (TinselV3) {
-		warning("TODO: Implement music handling for Noir");
-		return;
-	}
-
 	Common::StackLock lock(_mutex);
 
 	stop();
@@ -933,15 +950,80 @@ void PCMMusicPlayer::fadeOutIteration() {
 	_vm->_mixer->setChannelVolume(_handle, _fadeOutVolume);
 }
 
+Common::MemoryReadStream *readSampleData(const Common::String &filename, uint32 sampleOffset, uint32 sampleLength) {
+	Common::File file;
+	if (!file.open(filename))
+		error(CANNOT_FIND_FILE, filename.c_str());
+
+	file.seek(sampleOffset);
+	if (file.eos() || file.err() || (uint32)file.pos() != sampleOffset)
+		error(FILE_IS_CORRUPT, filename.c_str());
+
+	byte *buffer = (byte *) malloc(sampleLength);
+	assert(buffer);
+
+	// read all of the sample
+	if (file.read(buffer, sampleLength) != sampleLength)
+		error(FILE_IS_CORRUPT, filename.c_str());
+
+	return new Common::MemoryReadStream(buffer, sampleLength, DisposeAfterUse::YES);
+}
+
+struct MusicSegment {
+	uint32 numChannels;
+	uint32 bitsPerSec;
+	uint32 bitsPerSample;
+	uint32 sampleLength;
+	uint32 sampleOffset;
+};
+
+void PCMMusicPlayer::loadADPCMMusicFromSegment(int segmentNum) {
+	MusicSegment *musicSegments = (MusicSegment *)_vm->_handle->LockMem(_hSegment);
+
+	assert(FROM_32(musicSegments[segmentNum].numChannels) == 1);
+	assert(FROM_32(musicSegments[segmentNum].bitsPerSample) == 16);
+
+	uint32 sampleOffset = FROM_32(musicSegments[segmentNum].sampleOffset);
+	uint32 sampleLength = FROM_32(musicSegments[segmentNum].sampleLength);
+	uint32 sampleCLength = (((sampleLength + 63) & ~63)*33)/64;
+
+	debugC(DEBUG_DETAILED, kTinselDebugMusic, "Creating ADPCM music chunk with size %d, "
+			"offset %d (script %d.%d)",
+			sampleCLength, sampleOffset, _scriptNum, _scriptIndex - 1);
+
+	Common::SeekableReadStream *sampleStream = readSampleData(_filename, sampleOffset, sampleCLength);
+
+	delete _curChunk;
+	_curChunk = new Tinsel8_ADPCMStream(sampleStream, DisposeAfterUse::YES, sampleCLength, 22050, 1, 32);
+}
+
+struct MusicSegmentNoir {
+	uint32 sampleLength;
+	uint32 sampleOffset;
+};
+
+void PCMMusicPlayer::loadMP3MusicFromSegment(int segmentNum) {
+	MusicSegmentNoir *musicSegments = (MusicSegmentNoir *)_vm->_handle->LockMem(_hSegment);
+
+	Common::SeekableReadStream *sampleStream = readSampleData(_filename, musicSegments[segmentNum].sampleOffset, 
+			musicSegments[segmentNum].sampleLength);
+
+	delete _curChunk;
+	_curChunk = Audio::makeMP3Stream(sampleStream, DisposeAfterUse::YES);
+}
+
+void PCMMusicPlayer::loadMusicFromSegment(int segmentNum) {
+	if (TinselV3) {
+		loadMP3MusicFromSegment(segmentNum);
+	} else {
+		loadADPCMMusicFromSegment(segmentNum);
+	}
+}
+
 bool PCMMusicPlayer::getNextChunk() {
-	MusicSegment *musicSegments;
 	int32 *script, *scriptBuffer;
 	int id;
 	int snum;
-	uint32 sampleOffset, sampleLength, sampleCLength;
-	Common::File file;
-	byte *buffer;
-	Common::SeekableReadStream *sampleStream;
 
 	switch (_state) {
 	case S_NEW:
@@ -964,38 +1046,7 @@ bool PCMMusicPlayer::getNextChunk() {
 			break;
 		}
 
-		musicSegments = (MusicSegment *)_vm->_handle->LockMem(_hSegment);
-
-		assert(FROM_32(musicSegments[snum].numChannels) == 1);
-		assert(FROM_32(musicSegments[snum].bitsPerSample) == 16);
-
-		sampleOffset = FROM_32(musicSegments[snum].sampleOffset);
-		sampleLength = FROM_32(musicSegments[snum].sampleLength);
-		sampleCLength = (((sampleLength + 63) & ~63)*33)/64;
-
-		if (!file.open(_filename))
-			error(CANNOT_FIND_FILE, _filename.c_str());
-
-		file.seek(sampleOffset);
-		if (file.eos() || file.err() || (uint32)file.pos() != sampleOffset)
-			error(FILE_IS_CORRUPT, _filename.c_str());
-
-		buffer = (byte *) malloc(sampleCLength);
-		assert(buffer);
-
-		// read all of the sample
-		if (file.read(buffer, sampleCLength) != sampleCLength)
-			error(FILE_IS_CORRUPT, _filename.c_str());
-
-		debugC(DEBUG_DETAILED, kTinselDebugMusic, "Creating ADPCM music chunk with size %d, "
-				"offset %d (script %d.%d)", sampleCLength, sampleOffset,
-				_scriptNum, _scriptIndex - 1);
-
-		sampleStream = new Common::MemoryReadStream(buffer, sampleCLength, DisposeAfterUse::YES);
-
-		delete _curChunk;
-		_curChunk = new Tinsel8_ADPCMStream(sampleStream, DisposeAfterUse::YES, sampleCLength,
-				22050, 1, 32);
+		loadMusicFromSegment(snum);
 
 		_state = S_MID;
 		return true;
diff --git a/engines/tinsel/music.h b/engines/tinsel/music.h
index 2b204247ae..95535b0792 100644
--- a/engines/tinsel/music.h
+++ b/engines/tinsel/music.h
@@ -147,10 +147,10 @@ public:
 	void fadeOutIteration();
 
 	int readBuffer(int16 *buffer, const int numSamples) override;
-	bool isStereo() const override { return false; }
+	bool isStereo() const override;
 	bool endOfData() const override { return _end; }
 	bool endOfStream() const override { return false; }
-	int getRate() const override { return 22050; }
+	int getRate() const override;
 
 protected:
 	enum State {
@@ -164,14 +164,6 @@ protected:
 		S_STOP
 	};
 
-	struct MusicSegment {
-		uint32 numChannels;
-		uint32 bitsPerSec;
-		uint32 bitsPerSample;
-		uint32 sampleLength;
-		uint32 sampleOffset;
-	};
-
 	Audio::SoundHandle _handle;
 	Audio::AudioStream *_curChunk;
 	Common::Mutex _mutex;
@@ -204,6 +196,10 @@ protected:
 	void setVol(uint8 volume);
 
 	bool getNextChunk();
+
+	void loadMusicFromSegment(int segmentNum);
+	void loadADPCMMusicFromSegment(int segmentNum);
+	void loadMP3MusicFromSegment(int segmentNum);
 };
 
 } // End of namespace Tinsel
diff --git a/engines/tinsel/tinlib.cpp b/engines/tinsel/tinlib.cpp
index cec18966dc..a9c0542258 100644
--- a/engines/tinsel/tinlib.cpp
+++ b/engines/tinsel/tinlib.cpp
@@ -1661,10 +1661,6 @@ static void PlayMovie(CORO_PARAM, SCNHANDLE hFileStem, int myEscape) {
  * Play some music
  */
 static void PlayMusic(int tune) {
-	if (TinselV3) {
-		warning("TODO: Implement PLAYMUSIC(%d) for Noir", tune);
-		return;
-	}
 	_vm->_pcmMusic->startPlay(tune);
 }
 


Commit: 497ff53c949e3825d999594a3d832ab53c931a78
    https://github.com/scummvm/scummvm/commit/497ff53c949e3825d999594a3d832ab53c931a78
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2021-03-01T21:52:25+01:00

Commit Message:
TINSEL: Map SHOWMENU

Changed paths:
    engines/tinsel/tinlib.cpp


diff --git a/engines/tinsel/tinlib.cpp b/engines/tinsel/tinlib.cpp
index a9c0542258..9fc1ffa05b 100644
--- a/engines/tinsel/tinlib.cpp
+++ b/engines/tinsel/tinlib.cpp
@@ -4341,6 +4341,10 @@ NoirMapping translateNoirLibCode(int libCode, int32 *pp) {
 		pp -= mapping.numArgs - 1;
 		debug(7, "%s(%d)", mapping.name, pp[0]);
 		break;
+	case 159:
+		mapping = NoirMapping{"SHOWMENU", SHOWMENU, 0};
+		debug(7, "%s()", mapping.name);
+		break;
 	case 167:
 		mapping = NoirMapping{"STARTPROCESS", STARTPROCESS, 1};
 		pp -= mapping.numArgs - 1;
@@ -5505,7 +5509,7 @@ int CallLibraryRoutine(CORO_PARAM, int operand, int32 *pp, const INT_CONTEXT *pi
 		return -1;
 
 	case SHOWMENU:
-		// DW2 only
+		// DW2 / Noir
 		ShowMenu();
 		return 0;
 




More information about the Scummvm-git-logs mailing list