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

ysj1173886760 42030331+ysj1173886760 at users.noreply.github.com
Wed Jul 14 10:01:12 UTC 2021


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

Summary:
8a86d2bb9b DIRECTOR: amend the checking of playing repeat sound castmember.
c7dd7d6a3f DIRECTOR: set castmember to null when sprite is bitmap sprite and sprite type doesn't match cast type
154c4aaa47 DIRECTOR: amend loadStream in SNDDecoder
f2121c4f2b DIRECTOR: organize the code
f14ee99308 DIRECTOR: implement b_fsound for FPlayXObj
f27a3c74d0 DIRECTOR: implement loading STR file
8282f8556f DIRECTOR: implement loading external sound file
9ef812b0ba DIRECTOR: implement playing external sample sounds in score
fcb49bbd15 DIRECTOR: implement playExternalSound for DirectorSound, organize the code


Commit: 8a86d2bb9b85062216e83848bc9f8b15caf4157e
    https://github.com/scummvm/scummvm/commit/8a86d2bb9b85062216e83848bc9f8b15caf4157e
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:49+08:00

Commit Message:
DIRECTOR: amend the checking of playing repeat sound castmember.

Changed paths:
    engines/director/sound.cpp


diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index d1cfadf6f7..b54fa18bfc 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -104,7 +104,7 @@ void DirectorSound::playCastMember(CastMemberID memberID, uint8 soundChannel, bo
 			if (soundCast->_type != kCastSound) {
 				warning("DirectorSound::playCastMember: attempted to play a non-SoundCastMember %s", memberID.asString().c_str());
 			} else {
-				if (!allowRepeat && lastPlayingCast(soundChannel) == memberID)
+				if (!allowRepeat && lastPlayingCast(soundChannel) == memberID && isChannelActive(soundChannel))
 					return;
 				bool looping = ((SoundCastMember *)soundCast)->_looping;
 				AudioDecoder *ad = ((SoundCastMember *)soundCast)->_audio;


Commit: c7dd7d6a3f01afc1d040165a769831f38a087ae1
    https://github.com/scummvm/scummvm/commit/c7dd7d6a3f01afc1d040165a769831f38a087ae1
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:49+08:00

Commit Message:
DIRECTOR: set castmember to null when sprite is bitmap sprite and sprite type doesn't match cast type

Changed paths:
    engines/director/sprite.cpp


diff --git a/engines/director/sprite.cpp b/engines/director/sprite.cpp
index 552d73c65b..ec76a5e92f 100644
--- a/engines/director/sprite.cpp
+++ b/engines/director/sprite.cpp
@@ -222,6 +222,16 @@ void Sprite::setCast(CastMemberID memberID) {
 			_width = dims.width();
 			_height = dims.height();
 		}
+
+		// check whether the sprite type match the cast type
+		// if it doesn't match, then we treat it as transparent
+		// this happens in warlock-mac data/stambul/c up
+		if (_spriteType == kBitmapSprite && _cast->_type != kCastBitmap) {
+			warning("Sprite::setCast(): sprite type doesn't match cast type, setting cast member to null");
+			_cast = nullptr;
+			_castId = CastMemberID();
+		}
+
 	} else {
 		warning("Sprite::setCast(): %s has null member", memberID.asString().c_str());
 	}


Commit: 154c4aaa47e829dbcef8c785db66963050372414
    https://github.com/scummvm/scummvm/commit/154c4aaa47e829dbcef8c785db66963050372414
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:49+08:00

Commit Message:
DIRECTOR: amend loadStream in SNDDecoder

Changed paths:
    engines/director/sound.cpp


diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index b54fa18bfc..e8813b6ea8 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -333,8 +333,7 @@ bool SNDDecoder::processBufferCommand(Common::SeekableReadStreamEndian &stream)
 	uint16 bits = 8;
 	if (encoding == 0x00) {
 		// Standard sound header
-		uint16 dataLength = param;
-		frameCount = dataLength / _channels;
+		frameCount = param / _channels;
 	} else if (encoding == 0xff) {
 		// Extended sound header
 		_channels = param;


Commit: f2121c4f2b177c27903056f329cae11e2ff8e6c4
    https://github.com/scummvm/scummvm/commit/f2121c4f2b177c27903056f329cae11e2ff8e6c4
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:49+08:00

Commit Message:
DIRECTOR: organize the code

Changed paths:
    engines/director/castmember.cpp
    engines/director/castmember.h


diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index da091272d8..6f56217f51 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -184,6 +184,12 @@ Graphics::MacWidget *BitmapCastMember::createWidget(Common::Rect &bbox, Channel
 	Graphics::MacWidget *widget = new Graphics::MacWidget(g_director->getCurrentWindow(), bbox.left, bbox.top, bbox.width(), bbox.height(), g_director->_wm, false);
 
 	// scale for drawing a different size sprite
+	copyStretchImg(widget->getSurface()->surfacePtr(), bbox);
+
+	return widget;
+}
+
+void BitmapCastMember::copyStretchImg(Graphics::Surface *surface, const Common::Rect &bbox) {
 	if (bbox.width() != _initialRect.width() || bbox.height() != _initialRect.height()) {
 
 		int scaleX = SCALE_THRESHOLD * _initialRect.width() / bbox.width();
@@ -193,21 +199,18 @@ Graphics::MacWidget *BitmapCastMember::createWidget(Common::Rect &bbox, Channel
 			if (g_director->_wm->_pixelformat.bytesPerPixel == 1) {
 				for (int x = 0, scaleXCtr = 0; x < bbox.width(); x++, scaleXCtr += scaleX) {
 					const byte *src = (const byte *)_img->getSurface()->getBasePtr(scaleXCtr / SCALE_THRESHOLD, scaleYCtr / SCALE_THRESHOLD);
-					*(byte *)widget->getSurface()->getBasePtr(x, y) = *src;
+					*(byte *)surface->getBasePtr(x, y) = *src;
 				}
 			} else {
 				for (int x = 0, scaleXCtr = 0; x < bbox.width(); x++, scaleXCtr += scaleX) {
 					const int *src = (const int *)_img->getSurface()->getBasePtr(scaleXCtr / SCALE_THRESHOLD, scaleYCtr / SCALE_THRESHOLD);
-					*(int *)widget->getSurface()->getBasePtr(x, y) = *src;
+					*(int *)surface->getBasePtr(x, y) = *src;
 				}
 			}
 		}
-
 	} else {
-		widget->getSurface()->blitFrom(*_img->getSurface());
+		surface->copyFrom(*_img->getSurface());
 	}
-
-	return widget;
 }
 
 void BitmapCastMember::createMatte(Common::Rect &bbox) {
@@ -216,27 +219,7 @@ void BitmapCastMember::createMatte(Common::Rect &bbox) {
 	Graphics::Surface tmp;
 	tmp.create(bbox.width(), bbox.height(), g_director->_pixelformat);
 
-	if (bbox.width() != _initialRect.width() || bbox.height() != _initialRect.height()) {
-
-		int scaleX = SCALE_THRESHOLD * _initialRect.width() / bbox.width();
-		int scaleY = SCALE_THRESHOLD * _initialRect.height() / bbox.height();
-
-		for (int y = 0, scaleYCtr = 0; y < bbox.height(); y++, scaleYCtr += scaleY) {
-			if (g_director->_wm->_pixelformat.bytesPerPixel == 1) {
-				for (int x = 0, scaleXCtr = 0; x < bbox.width(); x++, scaleXCtr += scaleX) {
-					const byte *src = (const byte *)_img->getSurface()->getBasePtr(scaleXCtr / SCALE_THRESHOLD, scaleYCtr / SCALE_THRESHOLD);
-					*(byte *)tmp.getBasePtr(x, y) = *src;
-				}
-			} else {
-				for (int x = 0, scaleXCtr = 0; x < bbox.width(); x++, scaleXCtr += scaleX) {
-					const int *src = (const int *)_img->getSurface()->getBasePtr(scaleXCtr / SCALE_THRESHOLD, scaleYCtr / SCALE_THRESHOLD);
-					*(int *)tmp.getBasePtr(x, y) = *src;
-				}
-			}
-		}
-	} else {
-		tmp.copyFrom(*_img->getSurface());
-	}
+	copyStretchImg(&tmp, bbox);
 
 	_noMatte = true;
 
diff --git a/engines/director/castmember.h b/engines/director/castmember.h
index 56e43c3327..f7055167ff 100644
--- a/engines/director/castmember.h
+++ b/engines/director/castmember.h
@@ -118,6 +118,7 @@ public:
 
 	void createMatte(Common::Rect &bbox);
 	Graphics::Surface *getMatte(Common::Rect &bbox);
+	void copyStretchImg(Graphics::Surface *surface, const Common::Rect &bbox);
 
 	bool hasField(int field) override;
 	Datum getField(int field) override;


Commit: f14ee99308ab7c7c0362c5094974259f289b660f
    https://github.com/scummvm/scummvm/commit/f14ee99308ab7c7c0362c5094974259f289b660f
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:49+08:00

Commit Message:
DIRECTOR: implement b_fsound for FPlayXObj

Changed paths:
    engines/director/lingo/xlibs/fplayxobj.cpp


diff --git a/engines/director/lingo/xlibs/fplayxobj.cpp b/engines/director/lingo/xlibs/fplayxobj.cpp
index c360883378..3cf2a3bd30 100644
--- a/engines/director/lingo/xlibs/fplayxobj.cpp
+++ b/engines/director/lingo/xlibs/fplayxobj.cpp
@@ -46,10 +46,12 @@ static BuiltinProto builtins[] = {
 	{ "Volume",			FPlayXObj::b_volume,	-1,0, 200, FBLTIN },
 	{ "FileName",		FPlayXObj::b_filename,	-1,0, 200, FBLTIN },
 	{ "InputLevel",		FPlayXObj::b_inputlevel,-1,0, 200, FBLTIN },
-	{ "FSound",			FPlayXObj::b_fsound,	-1,0, 200, FBLTIN },
+	{ "FSound",			FPlayXObj::b_fsound,	 0,0, 200, FBLTIN },
 	{ 0, 0, 0, 0, 0, VOIDSYM }
 };
 
+static char currentSound[20];
+
 void FPlayXObj::initialize(int type) {
 	if (!g_lingo->_builtinCmds.contains("FPlay")) {
 		g_lingo->initBuiltIns(builtins);
@@ -124,6 +126,10 @@ void FPlayXObj::b_fplay(int nargs) {
 			warning("FPlayXObj::b_fplay: failed to get audio stream");
 			return;
 		}
+
+		// update current playing sound
+		strcpy(currentSound, sndName.c_str());
+
 		sound->playStream(*as, 1);
 		delete ad;
 	}
@@ -160,9 +166,17 @@ void FPlayXObj::b_inputlevel(int nargs) {
 }
 
 void FPlayXObj::b_fsound(int nargs) {
-	g_lingo->printSTUBWithArglist("b_fsound", nargs);
-	g_lingo->dropStack(nargs);
-	g_lingo->push(Datum());
+	if (nargs != 0) {
+		warning("FPlayXObj::b_fsound: unhandled arguments");
+		g_lingo->dropStack(nargs);
+	}
+
+	DirectorSound *sound = g_director->getSoundManager();
+	if (sound->isChannelActive(1)) {
+		g_lingo->push(Datum(Common::String(currentSound)));
+	} else {
+		g_lingo->push(Datum("done"));
+	}
 }
 
 } // End of namespace Director


Commit: f27a3c74d0ef2418d5be32f81ada17fb521286a7
    https://github.com/scummvm/scummvm/commit/f27a3c74d0ef2418d5be32f81ada17fb521286a7
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:49+08:00

Commit Message:
DIRECTOR: implement loading STR file

Changed paths:
    engines/director/cast.cpp
    engines/director/cast.h


diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index df39975099..770f1e4eee 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -369,7 +369,8 @@ void Cast::loadCast() {
 
 	// External sound files
 	if (_castArchive->hasResource(MKTAG('S', 'T', 'R', ' '), -1)) {
-		debug("STUB: Unhandled 'STR ' resource");
+		loadExternalSound(*(r = _castArchive->getFirstResource(MKTAG('S', 'T', 'R', ' '))));
+		delete r;
 	}
 
 	Common::Array<uint16> vwci = _castArchive->getResourceIDList(MKTAG('V', 'W', 'C', 'I'));
@@ -777,6 +778,24 @@ void Cast::loadCastDataVWCR(Common::SeekableReadStreamEndian &stream) {
 	}
 }
 
+void Cast::loadExternalSound(Common::SeekableReadStreamEndian &stream) {
+	Common::String str = stream.readString();
+	str.trim();
+	debugC(1, kDebugLoading, "****** Loading External Sound File %s", str.c_str());
+
+	Common::String resPath = g_director->getCurrentPath() + str;
+
+	if (!g_director->_openResFiles.contains(resPath)) {
+		MacArchive *resFile = new MacArchive();
+
+		if (resFile->openFile(resPath)) {
+			g_director->_openResFiles.setVal(resPath, resFile);
+		} else {
+			delete resFile;
+		}
+	}
+}
+
 static void readEditInfo(EditInfo *info, Common::ReadStreamEndian *stream) {
 	info->rect = Movie::readRect(*stream);
 	info->selStart = stream->readUint32();
diff --git a/engines/director/cast.h b/engines/director/cast.h
index 4c123bb432..f756ed08dd 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -82,6 +82,7 @@ public:
 	void loadCastData(Common::SeekableReadStreamEndian &stream, uint16 id, Resource *res);
 	void loadCastInfo(Common::SeekableReadStreamEndian &stream, uint16 id);
 	void loadLingoContext(Common::SeekableReadStreamEndian &stream);
+	void loadExternalSound(Common::SeekableReadStreamEndian &stream);
 
 	void loadCastChildren();
 	void loadSoundCasts();


Commit: 8282f8556f55bbe0062ed769720bc7602e25343c
    https://github.com/scummvm/scummvm/commit/8282f8556f55bbe0062ed769720bc7602e25343c
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:50+08:00

Commit Message:
DIRECTOR: implement loading external sound file

Changed paths:
    engines/director/sound.cpp
    engines/director/sound.h


diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index e8813b6ea8..78206a9594 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -130,6 +130,40 @@ void DirectorSound::playCastMember(CastMemberID memberID, uint8 soundChannel, bo
 	}
 }
 
+void SNDDecoder::loadExternalSoundStream(Common::SeekableReadStreamEndian &stream) {
+	_size = stream.readUint32BE();
+
+	uint16 sampleRateFlag = stream.readUint16();
+	/*uint16 unk2 = */ stream.readUint16();
+
+	_data = (byte *)malloc(_size);
+	stream.read(_data, _size);
+
+	switch (sampleRateFlag) {
+	case 1:
+		_rate = 22254;
+		break;
+	case 2:
+		_rate = 11127;
+		break;
+	case 3:
+		_rate = 7300;
+		break;
+	case 4:
+		_rate = 5500;
+		break;
+	default:
+		warning("DirectorSound::loadExternalSoundStream: Can't handle sampleRateFlag %d, using default one", sampleRateFlag);
+		_rate = 5500;
+		break;
+	}
+
+	// this may related to the unk2 flag
+	// TODO: figure out how to read audio flags
+	_flags = Audio::FLAG_UNSIGNED;
+	_channels = 1;
+}
+
 void DirectorSound::registerFade(uint8 soundChannel, bool fadeIn, int ticks) {
 	if (!isChannelValid(soundChannel))
 		return;
diff --git a/engines/director/sound.h b/engines/director/sound.h
index b9147065d5..c69dc6bbd6 100644
--- a/engines/director/sound.h
+++ b/engines/director/sound.h
@@ -104,6 +104,7 @@ public:
 	~SNDDecoder();
 
 	bool loadStream(Common::SeekableReadStreamEndian &stream);
+	void loadExternalSoundStream(Common::SeekableReadStreamEndian &stream);
 	bool processCommands(Common::SeekableReadStreamEndian &stream);
 	bool processBufferCommand(Common::SeekableReadStreamEndian &stream);
 	Audio::RewindableAudioStream *getAudioStream(DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);


Commit: 9ef812b0ba966ddc0929ec7bc2461a9ac7ef44e7
    https://github.com/scummvm/scummvm/commit/9ef812b0ba966ddc0929ec7bc2461a9ac7ef44e7
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:50+08:00

Commit Message:
DIRECTOR: implement playing external sample sounds in score

Changed paths:
    engines/director/score.cpp
    engines/director/score.h


diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index 1d06e8b4a1..075bb3b978 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -25,6 +25,8 @@
 #include "common/memstream.h"
 #include "common/substream.h"
 
+#include "audio/audiostream.h"
+
 #include "graphics/macgui/mactext.h"
 
 #ifdef USE_PNG
@@ -90,6 +92,9 @@ Score::~Score() {
 		for (Common::SortedArray<Label *>::iterator it = _labels->begin(); it != _labels->end(); ++it)
 			delete *it;
 
+	for (uint i = 0; i < _sampleSounds.size(); i++)
+		delete _sampleSounds[i];
+
 	delete _labels;
 }
 
@@ -663,8 +668,75 @@ void Score::playSoundChannel(uint16 frameId) {
 
 	debugC(5, kDebugLoading, "playSoundChannel(): Sound1 %s Sound2 %s", frame->_sound1.asString().c_str(), frame->_sound2.asString().c_str());
 	DirectorSound *sound = _vm->getSoundManager();
-	sound->playCastMember(frame->_sound1, 1, false);
-	sound->playCastMember(frame->_sound2, 2, false);
+
+	// 0x0f represent sample sound
+	if (frame->_soundType1 == 0x0f) {
+		if (_sampleSounds.empty())
+			loadSampleSounds(0x0f);
+
+		if ((uint)frame->_sound1.member <= _sampleSounds.size()) {
+			sound->playStream(*(_sampleSounds[frame->_sound1.member - 1]->getAudioStream()), 1);
+		}
+	} else {
+		sound->playCastMember(frame->_sound1, 1, false);
+	}
+
+	if (frame->_soundType2 == 0x0f) {
+		if (_sampleSounds.empty())
+			loadSampleSounds(0x0f);
+
+		if ((uint)frame->_sound2.member <= _sampleSounds.size())
+			sound->playStream(*(_sampleSounds[frame->_sound2.member - 1]->getAudioStream()), 2);
+	} else {
+		sound->playCastMember(frame->_sound2, 2, false);
+	}
+}
+
+void Score::loadSampleSounds(uint type) {
+	// trying to load external sample sounds
+	// lazy loading
+	uint32 tag = MKTAG('C', 'S', 'N', 'D');
+	uint id = 0xFF;
+	Archive *archive = nullptr;
+
+	for (Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = g_director->_openResFiles.begin(); it != g_director->_openResFiles.end(); ++it) {
+		Common::Array<uint16> idList = it->_value->getResourceIDList(tag);
+		for (uint j = 0; j < idList.size(); j++) {
+			if ((idList[j] & 0xFF) == type) {
+				id = idList[j];
+				archive = it->_value;
+				break;
+			}
+		}
+	}
+
+	if (id == 0xFF) {
+		warning("Score::loadSampleSounds: can not find CSND resource with id %d", type);
+		return;
+	}
+
+	Common::SeekableReadStreamEndian *csndData = archive->getResource(tag, id);
+
+	/*uint32 flag = */ csndData->readUint32();
+
+	// the flag should be 0x604E
+	// i'm not sure what's that mean, but it occurs in those csnd files
+
+	// contains how many csnd data
+	uint16 num = csndData->readUint16();
+
+	// read the offset first;
+	Common::Array<uint32> offset(num);
+	for (uint i = 0; i < num; i++)
+		offset[i] = csndData->readUint32();
+
+	for (uint i = 0; i < num; i++) {
+		csndData->seek(offset[i]);
+
+		SNDDecoder *ad = new SNDDecoder();
+		ad->loadExternalSoundStream(*csndData);
+		_sampleSounds.push_back(ad);
+	}
 }
 
 void Score::loadFrames(Common::SeekableReadStreamEndian &stream, uint16 version) {
diff --git a/engines/director/score.h b/engines/director/score.h
index 3b8ddb6601..ca8e90aa96 100644
--- a/engines/director/score.h
+++ b/engines/director/score.h
@@ -52,6 +52,7 @@ class Cursor;
 class Channel;
 class Sprite;
 class CastMember;
+class AudioDecoder;
 
 enum RenderMode {
 	kRenderModeNormal,
@@ -71,6 +72,7 @@ public:
 	void loadFrames(Common::SeekableReadStreamEndian &stream, uint16 version);
 	void loadLabels(Common::SeekableReadStreamEndian &stream);
 	void loadActions(Common::SeekableReadStreamEndian &stream);
+	void loadSampleSounds(uint type);
 
 	static int compareLabels(const void *a, const void *b);
 	uint16 getLabel(Common::String &label);
@@ -128,6 +130,7 @@ public:
 	Common::SortedArray<Label *> *_labels;
 	Common::HashMap<uint16, Common::String> _actions;
 	Common::HashMap<uint16, bool> _immediateActions;
+	Common::Array<AudioDecoder *> _sampleSounds;
 
 	byte _currentFrameRate;
 


Commit: fcb49bbd15559807cc6c585e6c08f883f45c81f7
    https://github.com/scummvm/scummvm/commit/fcb49bbd15559807cc6c585e6c08f883f45c81f7
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-14T18:00:50+08:00

Commit Message:
DIRECTOR: implement playExternalSound for DirectorSound, organize the code

Changed paths:
    engines/director/score.cpp
    engines/director/sound.cpp
    engines/director/sound.h


diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index 075bb3b978..89b914e79d 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -675,7 +675,7 @@ void Score::playSoundChannel(uint16 frameId) {
 			loadSampleSounds(0x0f);
 
 		if ((uint)frame->_sound1.member <= _sampleSounds.size()) {
-			sound->playStream(*(_sampleSounds[frame->_sound1.member - 1]->getAudioStream()), 1);
+			sound->playExternalSound(_sampleSounds[frame->_sound1.member - 1], 1, frame->_sound1.member);
 		}
 	} else {
 		sound->playCastMember(frame->_sound1, 1, false);
@@ -686,7 +686,7 @@ void Score::playSoundChannel(uint16 frameId) {
 			loadSampleSounds(0x0f);
 
 		if ((uint)frame->_sound2.member <= _sampleSounds.size())
-			sound->playStream(*(_sampleSounds[frame->_sound2.member - 1]->getAudioStream()), 2);
+			sound->playExternalSound(_sampleSounds[frame->_sound2.member - 1], 2, frame->_sound2.member);
 	} else {
 		sound->playCastMember(frame->_sound2, 2, false);
 	}
diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index 78206a9594..02bc45d223 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -228,6 +228,19 @@ bool DirectorSound::isChannelValid(uint8 soundChannel) {
 	return true;
 }
 
+void DirectorSound::playExternalSound(AudioDecoder *ad, uint8 soundChannel, uint8 externalSoundID) {
+	if (!isChannelValid(soundChannel))
+		return;
+
+	// use castMemberID info to check, castLib -1 represent for externalSound
+	// this should be amended by some kind of union which contains CastMemberID and externalSound info
+	if (isChannelActive(soundChannel) && lastPlayingCast(soundChannel) == CastMemberID(externalSoundID, -1))
+		return;
+
+	playStream(*(ad->getAudioStream()), soundChannel);
+	_channels[soundChannel - 1].lastPlayingCast = CastMemberID(externalSoundID, -1);
+}
+
 CastMemberID DirectorSound::lastPlayingCast(uint8 soundChannel) {
 	if (!isChannelValid(soundChannel))
 		return CastMemberID(0, 0);
diff --git a/engines/director/sound.h b/engines/director/sound.h
index c69dc6bbd6..1a160cb785 100644
--- a/engines/director/sound.h
+++ b/engines/director/sound.h
@@ -34,6 +34,8 @@ namespace Audio {
 
 namespace Director {
 
+class AudioDecoder;
+
 struct FadeParams {
 	int startVol;
 	int targetVol;
@@ -74,6 +76,7 @@ public:
 	void playMCI(Audio::AudioStream &stream, uint32 from, uint32 to);
 	void playStream(Audio::AudioStream &stream, uint8 soundChannel);
 	void playCastMember(CastMemberID memberID, uint8 soundChannel, bool allowRepeat = true);
+	void playExternalSound(AudioDecoder *ad, uint8 soundChannel, uint8 externalSoundID);
 	void systemBeep();
 
 	void registerFade(uint8 soundChannel, bool fadeIn, int ticks);




More information about the Scummvm-git-logs mailing list