diff options
Diffstat (limited to 'engines/kyra/sound.cpp')
-rw-r--r-- | engines/kyra/sound.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index 73c20ee6df..9d3e5f67f5 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -73,7 +73,7 @@ bool Sound::isVoicePresent(const char *file) const { return false; } -int32 Sound::voicePlay(const char *file, Audio::SoundHandle *handle, uint8 volume, bool isSfx) { +int32 Sound::voicePlay(const char *file, Audio::SoundHandle *handle, uint8 volume, uint8 priority, bool isSfx) { Audio::SeekableAudioStream *audioStream = getVoiceStream(file); if (!audioStream) { @@ -81,7 +81,7 @@ int32 Sound::voicePlay(const char *file, Audio::SoundHandle *handle, uint8 volum } int playTime = audioStream->getLength().msecs(); - playVoiceStream(audioStream, handle, volume, isSfx); + playVoiceStream(audioStream, handle, volume, priority, isSfx); return playTime; } @@ -109,12 +109,20 @@ Audio::SeekableAudioStream *Sound::getVoiceStream(const char *file) const { } } -bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *handle, uint8 volume, bool isSfx) { +bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *handle, uint8 volume, uint8 priority, bool isSfx) { int h = 0; - while (h < kNumChannelHandles && _mixer->isSoundHandleActive(_soundChannels[h])) + while (h < kNumChannelHandles && _mixer->isSoundHandleActive(_soundChannels[h].handle)) ++h; if (h >= kNumChannelHandles) { + h = 0; + while (h < kNumChannelHandles && _soundChannels[h].priority > priority) + ++h; + if (h < kNumChannelHandles) + voiceStop(&_soundChannels[h].handle); + } + + if (h >= kNumChannelHandles) { // When we run out of handles we need to destroy the stream object, // this is to avoid memory leaks in some scenes where too many sfx // are started. @@ -123,9 +131,10 @@ bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *hand return false; } - _mixer->playStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h], stream, -1, volume); + _mixer->playStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].handle, stream, -1, volume); + _soundChannels[h].priority = priority; if (handle) - *handle = _soundChannels[h]; + *handle = _soundChannels[h].handle; return true; } @@ -133,8 +142,8 @@ bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *hand void Sound::voiceStop(const Audio::SoundHandle *handle) { if (!handle) { for (int h = 0; h < kNumChannelHandles; ++h) { - if (_mixer->isSoundHandleActive(_soundChannels[h])) - _mixer->stopHandle(_soundChannels[h]); + if (_mixer->isSoundHandleActive(_soundChannels[h].handle)) + _mixer->stopHandle(_soundChannels[h].handle); } } else { _mixer->stopHandle(*handle); @@ -144,7 +153,7 @@ void Sound::voiceStop(const Audio::SoundHandle *handle) { bool Sound::voiceIsPlaying(const Audio::SoundHandle *handle) const { if (!handle) { for (int h = 0; h < kNumChannelHandles; ++h) { - if (_mixer->isSoundHandleActive(_soundChannels[h])) + if (_mixer->isSoundHandleActive(_soundChannels[h].handle)) return true; } } else { @@ -156,7 +165,7 @@ bool Sound::voiceIsPlaying(const Audio::SoundHandle *handle) const { bool Sound::allVoiceChannelsPlaying() const { for (int i = 0; i < kNumChannelHandles; ++i) - if (!_mixer->isSoundHandleActive(_soundChannels[i])) + if (!_mixer->isSoundHandleActive(_soundChannels[i].handle)) return false; return true; } |