diff options
author | Eugene Sandulenko | 2005-08-15 23:26:50 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2005-08-15 23:26:50 +0000 |
commit | 0db33e8dfd7ef139e23d4a6179baeb1fc2613ce8 (patch) | |
tree | 578a55b972081b42f3ddf2f2eae47d50ad4d8d40 | |
parent | 1b9b4de9ce2bcfdb1889082ac54d39a775b77f6a (diff) | |
download | scummvm-rg350-0db33e8dfd7ef139e23d4a6179baeb1fc2613ce8.tar.gz scummvm-rg350-0db33e8dfd7ef139e23d4a6179baeb1fc2613ce8.tar.bz2 scummvm-rg350-0db33e8dfd7ef139e23d4a6179baeb1fc2613ce8.zip |
Fix prince room sound inconsistencies mentioned in bugreport #1258501
svn-id: r18694
-rw-r--r-- | saga/sound.cpp | 60 | ||||
-rw-r--r-- | saga/sound.h | 19 |
2 files changed, 67 insertions, 12 deletions
diff --git a/saga/sound.cpp b/saga/sound.cpp index 3988e34504..a115947fcd 100644 --- a/saga/sound.cpp +++ b/saga/sound.cpp @@ -32,12 +32,31 @@ namespace Saga { Sound::Sound(SagaEngine *vm, Audio::Mixer *mixer, int enabled) : _vm(vm), _mixer(mixer), _enabled(enabled), _voxStream(0) { + + for (int i = 0; i < SOUND_HANDLES; i++) + _handles[i].type = kFreeHandle; } Sound::~Sound() { delete _voxStream; } +SndHandle *Sound::getHandle() { + for (int i = 0; i < SOUND_HANDLES; i++) { + if (_handles[i].type == kFreeHandle) + return &_handles[i]; + + if (!_mixer->isSoundHandleActive(_handles[i].handle)) { + _handles[i].type = kFreeHandle; + return &_handles[i]; + } + } + + error("Sound::getHandle(): Too many sound handles"); + + return NULL; +} + void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume, bool loop) { byte flags; @@ -61,39 +80,62 @@ void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int } void Sound::playSound(SoundBuffer &buffer, int volume, bool loop) { - playSoundBuffer(&_effectHandle, buffer, 2 * volume, loop); + SndHandle *handle = getHandle(); + + handle->type = kEffectHandle; + playSoundBuffer(&handle->handle, buffer, 2 * volume, loop); } void Sound::pauseSound() { - _mixer->pauseHandle(_effectHandle, true); + for (int i = 0; i < SOUND_HANDLES; i++) + if (_handles[i].type == kEffectHandle) + _mixer->pauseHandle(_handles[i].handle, true); } void Sound::resumeSound() { - _mixer->pauseHandle(_effectHandle, false); + for (int i = 0; i < SOUND_HANDLES; i++) + if (_handles[i].type == kEffectHandle) + _mixer->pauseHandle(_handles[i].handle, false); } void Sound::stopSound() { - _mixer->stopHandle(_effectHandle); + for (int i = 0; i < SOUND_HANDLES; i++) + if (_handles[i].type == kEffectHandle) { + _mixer->stopHandle(_handles[i].handle); + _handles[i].type = kFreeHandle; + } } void Sound::playVoice(SoundBuffer &buffer) { - playSoundBuffer(&_voiceHandle, buffer, 255, false); + SndHandle *handle = getHandle(); + + handle->type = kVoiceHandle; + playSoundBuffer(&handle->handle, buffer, 255, false); } void Sound::pauseVoice() { - _mixer->pauseHandle(_voiceHandle, true); + for (int i = 0; i < SOUND_HANDLES; i++) + if (_handles[i].type == kVoiceHandle) + _mixer->pauseHandle(_handles[i].handle, true); } void Sound::resumeVoice() { - _mixer->pauseHandle(_voiceHandle, false); + for (int i = 0; i < SOUND_HANDLES; i++) + if (_handles[i].type == kVoiceHandle) + _mixer->pauseHandle(_handles[i].handle, false); } void Sound::stopVoice() { - _mixer->stopHandle(_voiceHandle); + for (int i = 0; i < SOUND_HANDLES; i++) + if (_handles[i].type == kVoiceHandle) { + _mixer->stopHandle(_handles[i].handle); + _handles[i].type = kFreeHandle; + } } void Sound::stopAll() { - _mixer->stopAll(); + stopVoice(); + stopSound(); } } // End of namespace Saga diff --git a/saga/sound.h b/saga/sound.h index 68c8e2369c..9cb7584067 100644 --- a/saga/sound.h +++ b/saga/sound.h @@ -30,6 +30,8 @@ namespace Saga { +#define SOUND_HANDLES 10 + enum SOUND_FLAGS { SOUND_LOOP = 1 }; @@ -45,6 +47,17 @@ struct SoundBuffer { bool isBigEndian; }; +enum sndHandleType { + kFreeHandle, + kEffectHandle, + kVoiceHandle +}; + +struct SndHandle { + Audio::SoundHandle handle; + sndHandleType type; +}; + class Sound { public: @@ -66,15 +79,15 @@ public: private: void playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume, bool loop); + + SndHandle *getHandle(); int _enabled; SagaEngine *_vm; Audio::Mixer *_mixer; Common::MemoryReadStream *_voxStream; - Audio::SoundHandle _effectHandle; - Audio::SoundHandle _voiceHandle; - + SndHandle _handles[SOUND_HANDLES]; }; } // End of namespace Saga |