aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2011-06-26 17:36:53 +0300
committerEugene Sandulenko2011-06-26 17:36:53 +0300
commit32392c9430c80d323914ffa91d4f08272396dcd9 (patch)
tree1e1dd969cec1bca013ba52f5e6873b3f6cf597fd
parentbce549f42a374e47c5de794c863d6cbe0842bfb4 (diff)
downloadscummvm-rg350-32392c9430c80d323914ffa91d4f08272396dcd9.tar.gz
scummvm-rg350-32392c9430c80d323914ffa91d4f08272396dcd9.tar.bz2
scummvm-rg350-32392c9430c80d323914ffa91d4f08272396dcd9.zip
SWORD25: Fixed bug with concurrent sounds. Reported by criezy
-rw-r--r--engines/sword25/sfx/soundengine.cpp60
-rw-r--r--engines/sword25/sfx/soundengine.h7
2 files changed, 39 insertions, 28 deletions
diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp
index 9244137c25..130383f8ef 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 4dbd475846..71f1602484 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