[Scummvm-cvs-logs] SF.net SVN: scummvm:[55330] scummvm/trunk/engines/mohawk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Wed Jan 19 17:52:47 CET 2011


Revision: 55330
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55330&view=rev
Author:   mthreepwood
Date:     2011-01-19 16:52:47 +0000 (Wed, 19 Jan 2011)

Log Message:
-----------
MOHAWK: Use a separate SndHandle for Myst's background sound

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/sound.cpp
    scummvm/trunk/engines/mohawk/sound.h

Modified: scummvm/trunk/engines/mohawk/sound.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/sound.cpp	2011-01-19 16:36:50 UTC (rev 55329)
+++ scummvm/trunk/engines/mohawk/sound.cpp	2011-01-19 16:52:47 UTC (rev 55330)
@@ -45,6 +45,7 @@
 Sound::~Sound() {
 	stopSound();
 	stopAllSLST();
+	stopBackgroundMyst();
 
 	if (_midiParser) {
 		_midiParser->unloadMusic();
@@ -581,18 +582,16 @@
 }
 
 Audio::SoundHandle *Sound::replaceBackgroundMyst(uint16 id, uint16 volume) {
-	debug (0, "Replacing background %d", id);
+	debug(0, "Replacing background sound with %d", id);
 
 	// TODO: The original engine does fading
 
 	Common::String name = _vm->getResourceName(ID_MSND, convertMystID(id));
 
 	// Check if sound is already playing
-	for (uint32 i = 0; i < _handles.size(); i++)
-		if (_handles[i].type == kBackgroundHandle
-				&& _vm->_mixer->isSoundHandleActive(_handles[i].handle)
-				&& name.equals(_vm->getResourceName(ID_MSND, convertMystID(_handles[i].id))))
-			return &_handles[i].handle;
+	if (_mystBackgroundSound.type == kUsedHandle && _vm->_mixer->isSoundHandleActive(_mystBackgroundSound.handle)
+			&& name.equals(_vm->getResourceName(ID_MSND, convertMystID(_mystBackgroundSound.id))))
+		return &_mystBackgroundSound.handle;
 
 	// Stop old background sound
 	stopBackgroundMyst();
@@ -601,46 +600,41 @@
 	Audio::AudioStream *audStream = makeAudioStream(id);
 
 	if (audStream) {
-		SndHandle *handle = getHandle();
-		handle->type = kBackgroundHandle;
-		handle->id = id;
-		handle->samplesPerSecond = audStream->getRate();
+		_mystBackgroundSound.type = kUsedHandle;
+		_mystBackgroundSound.id = id;
+		_mystBackgroundSound.samplesPerSecond = audStream->getRate();
 
 		// Set the stream to loop
 		audStream = Audio::makeLoopingAudioStream((Audio::RewindableAudioStream *)audStream, 0);
 
-		_vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle->handle, audStream, -1, volume >> 8);
-		return &handle->handle;
+		_vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_mystBackgroundSound.handle, audStream, -1, volume >> 8);
+		return &_mystBackgroundSound.handle;
 	}
 
 	return NULL;
 }
 
 void Sound::stopBackgroundMyst() {
-	for (uint32 i = 0; i < _handles.size(); i++)
-		if (_handles[i].type == kBackgroundHandle) {
-			_vm->_mixer->stopHandle(_handles[i].handle);
-			_handles[i].type = kFreeHandle;
-			_handles[i].id = 0;
-		}
+	if (_mystBackgroundSound.type == kUsedHandle) {
+		_vm->_mixer->stopHandle(_mystBackgroundSound.handle);
+		_mystBackgroundSound.type = kFreeHandle;
+		_mystBackgroundSound.id = 0;
+	}
 }
 
 void Sound::pauseBackgroundMyst() {
-	for (uint32 i = 0; i < _handles.size(); i++)
-		if (_handles[i].type == kBackgroundHandle)
-			_vm->_mixer->pauseHandle(_handles[i].handle, true);
+	if (_mystBackgroundSound.type == kUsedHandle)
+		_vm->_mixer->pauseHandle(_mystBackgroundSound.handle, true);
 }
 
 void Sound::resumeBackgroundMyst() {
-	for (uint32 i = 0; i < _handles.size(); i++)
-		if (_handles[i].type == kBackgroundHandle)
-			_vm->_mixer->pauseHandle(_handles[i].handle, false);
+	if (_mystBackgroundSound.type == kUsedHandle)
+		_vm->_mixer->pauseHandle(_mystBackgroundSound.handle, false);
 }
 
 void Sound::changeBackgroundVolumeMyst(uint16 vol) {
-	for (uint32 i = 0; i < _handles.size(); i++)
-		if (_handles[i].type == kBackgroundHandle)
-			_vm->_mixer->setChannelVolume(_handles[i].handle, vol >> 8);
+	if (_mystBackgroundSound.type == kUsedHandle)
+		_vm->_mixer->setChannelVolume(_mystBackgroundSound.handle, vol >> 8);
 }
 
 } // End of namespace Mohawk

Modified: scummvm/trunk/engines/mohawk/sound.h
===================================================================
--- scummvm/trunk/engines/mohawk/sound.h	2011-01-19 16:36:50 UTC (rev 55329)
+++ scummvm/trunk/engines/mohawk/sound.h	2011-01-19 16:52:47 UTC (rev 55330)
@@ -59,8 +59,7 @@
 
 enum SndHandleType {
 	kFreeHandle,
-	kUsedHandle,
-	kBackgroundHandle
+	kUsedHandle
 };
 
 struct SndHandle {
@@ -163,6 +162,9 @@
 	Audio::AudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL);
 	uint16 convertMystID(uint16 id);
 
+	// Myst-specific
+	SndHandle _mystBackgroundSound;
+
 	// Riven-specific
 	void playSLSTSound(uint16 index, bool fade, bool loop, uint16 volume, int16 balance);
 	void stopSLSTSound(uint16 id, bool fade);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list