[Scummvm-cvs-logs] scummvm master -> 32392c9430c80d323914ffa91d4f08272396dcd9

sev- sev at scummvm.org
Sun Jun 26 16:40:03 CEST 2011


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:
32392c9430 SWORD25: Fixed bug with concurrent sounds. Reported by criezy


Commit: 32392c9430c80d323914ffa91d4f08272396dcd9
    https://github.com/scummvm/scummvm/commit/32392c9430c80d323914ffa91d4f08272396dcd9
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2011-06-26T07:36:53-07:00

Commit Message:
SWORD25: Fixed bug with concurrent sounds. Reported by criezy

Changed paths:
    engines/sword25/sfx/soundengine.cpp
    engines/sword25/sfx/soundengine.h



diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp
index 9244137..130383f 100644
--- a/engines/sword25/sfx/soundengine.cpp
+++ b/engines/sword25/sfx/soundengine.cpp
@@ -61,6 +61,8 @@ SoundEngine::SoundEngine(Kernel *pKernel) : ResourceService(pKernel) {
 
 	_mixer = g_system->getMixer();
 
+	_maxHandleId = 1;
+
 	for (int i = 0; i < SOUND_HANDLES; i++)
 		_handles[i].type = kFreeHandle;
 }
@@ -139,19 +141,24 @@ void SoundEngine::resumeLayer(uint layer) {
 
 SndHandle *SoundEngine::getHandle(uint *id) {
 
-	// NOTE: Index 0 means error. Thus we're not using it
-	for (uint i = 1; i < SOUND_HANDLES; i++) {
+	for (uint i = 0; i < SOUND_HANDLES; i++) {
 		if (_handles[i].type != kFreeHandle && !_mixer->isSoundHandleActive(_handles[i].handle)) {
-			debugC(kDebugSound, 5, "Handle %d has finished playing", i);
+			debugC(1, kDebugSound, "Handle %d has finished playing", _handles[i].id);
 			_handles[i].type = kFreeHandle;
 		}
 	}
 
-	for (uint i = 1; i < SOUND_HANDLES; i++) {
+	for (uint i = 0; i < SOUND_HANDLES; i++) {
 		if (_handles[i].type == kFreeHandle) {
-			debugC(kDebugSound, 5, "Allocated handle %d", i);
+			debugC(1, kDebugSound, "Allocated handle %d", _handles[i].id);
+			_handles[i].id = _maxHandleId;
+			_handles[i].type = kAllocatedHandle;
+
 			if (id)
-				*id = i;
+				*id = _maxHandleId;
+
+			_maxHandleId++;
+
 			return &_handles[i];
 		}
 	}
@@ -161,6 +168,17 @@ SndHandle *SoundEngine::getHandle(uint *id) {
 	return NULL;
 }
 
+SndHandle *SoundEngine::findHandle(uint id) {
+	for (uint i = 0; i < SOUND_HANDLES; i++) {
+		if (_handles[i].id == id)
+			return &_handles[i];
+	}
+
+	error("Sound::findHandle(): Unknown handle");
+
+	return NULL;
+}
+
 Audio::Mixer::SoundType getType(SoundEngine::SOUND_TYPES type) {
 	switch (type) {
 	case SoundEngine::MUSIC:
@@ -194,6 +212,8 @@ uint SoundEngine::playSoundEx(const Common::String &fileName, SOUND_TYPES type,
 
 	debugC(1, kDebugSound, "SoundEngine::playSoundEx(%s, %d, %f, %f, %d, %d, %d, %d)", fileName.c_str(), type, volume, pan, loop, loopStart, loopEnd, layer);
 
+	handle->type = kAllocatedHandle;
+
 #ifdef USE_VORBIS
 	_mixer->playStream(getType(type), &(handle->handle), stream, -1, (byte)(volume * 255), (int8)(pan * 127));
 #endif
@@ -202,43 +222,33 @@ uint SoundEngine::playSoundEx(const Common::String &fileName, SOUND_TYPES type,
 }
 
 void SoundEngine::setSoundVolume(uint handle, float volume) {
-	assert(handle < SOUND_HANDLES);
-
 	debugC(1, kDebugSound, "SoundEngine::setSoundVolume(%d, %f)", handle, volume);
 
-	_mixer->setChannelVolume(_handles[handle].handle, (byte)(volume * 255));
+	_mixer->setChannelVolume(findHandle(handle)->handle, (byte)(volume * 255));
 }
 
 void SoundEngine::setSoundPanning(uint handle, float pan) {
-	assert(handle < SOUND_HANDLES);
-
 	debugC(1, kDebugSound, "SoundEngine::setSoundPanning(%d, %f)", handle, pan);
 
-	_mixer->setChannelBalance(_handles[handle].handle, (int8)(pan * 127));
+	_mixer->setChannelBalance(findHandle(handle)->handle, (int8)(pan * 127));
 }
 
 void SoundEngine::pauseSound(uint handle) {
-	assert(handle < SOUND_HANDLES);
-
 	debugC(1, kDebugSound, "SoundEngine::pauseSound(%d)", handle);
 
-	_mixer->pauseHandle(_handles[handle].handle, true);
+	_mixer->pauseHandle(findHandle(handle)->handle, true);
 }
 
 void SoundEngine::resumeSound(uint handle) {
-	assert(handle < SOUND_HANDLES);
-
 	debugC(1, kDebugSound, "SoundEngine::resumeSound(%d)", handle);
 
-	_mixer->pauseHandle(_handles[handle].handle, false);
+	_mixer->pauseHandle(findHandle(handle)->handle, false);
 }
 
 void SoundEngine::stopSound(uint handle) {
-	assert(handle < SOUND_HANDLES);
-
 	debugC(1, kDebugSound, "SoundEngine::stopSound(%d)", handle);
 
-	_mixer->stopHandle(_handles[handle].handle);
+	_mixer->stopHandle(findHandle(handle)->handle);
 }
 
 bool SoundEngine::isSoundPaused(uint handle) {
@@ -250,23 +260,21 @@ bool SoundEngine::isSoundPaused(uint handle) {
 }
 
 bool SoundEngine::isSoundPlaying(uint handle) {
-	assert(handle < SOUND_HANDLES);
-
 	debugC(1, kDebugSound, "SoundEngine::isSoundPlaying(%d)", handle);
 
-	return _mixer->isSoundHandleActive(_handles[handle].handle);
+	return _mixer->isSoundHandleActive(findHandle(handle)->handle);
 }
 
 float SoundEngine::getSoundVolume(uint handle) {
 	debugC(1, kDebugSound, "SoundEngine::getSoundVolume(%d)", handle);
 
-	return (float)_mixer->getChannelVolume(_handles[handle].handle) / 255.0;
+	return (float)_mixer->getChannelVolume(findHandle(handle)->handle) / 255.0;
 }
 
 float SoundEngine::getSoundPanning(uint handle) {
 	debugC(1, kDebugSound, "SoundEngine::getSoundPanning(%d)", handle);
 
-	return (float)_mixer->getChannelBalance(_handles[handle].handle) / 127.0;
+	return (float)_mixer->getChannelBalance(findHandle(handle)->handle) / 127.0;
 }
 
 Resource *SoundEngine::loadResource(const Common::String &fileName) {
diff --git a/engines/sword25/sfx/soundengine.h b/engines/sword25/sfx/soundengine.h
index 4dbd475..71f1602 100644
--- a/engines/sword25/sfx/soundengine.h
+++ b/engines/sword25/sfx/soundengine.h
@@ -58,13 +58,13 @@ namespace Sword25 {
 
 enum sndHandleType {
 	kFreeHandle,
-	kEffectHandle,
-	kVoiceHandle
+	kAllocatedHandle
 };
 
 struct SndHandle {
 	Audio::SoundHandle handle;
 	sndHandleType type;
+	uint32 id;
 };
 
 
@@ -244,10 +244,13 @@ public:
 private:
 	bool registerScriptBindings();
 	SndHandle *getHandle(uint *id);
+	SndHandle *findHandle(uint id);
 
 private:
 	Audio::Mixer *_mixer;
 	SndHandle _handles[SOUND_HANDLES];
+
+	uint32 _maxHandleId;
 };
 
 } // End of namespace Sword25






More information about the Scummvm-git-logs mailing list