From 96fd18a13bbe4def704e1f9b15100f3dc48aaf64 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Apr 2008 14:25:37 +0000 Subject: Implemented sound priority handling. svn-id: r31597 --- engines/kyra/kyra_v3.cpp | 12 +++++++----- engines/kyra/sound.h | 4 +++- engines/kyra/sound_digital.cpp | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/kyra/kyra_v3.cpp b/engines/kyra/kyra_v3.cpp index 5088f3557b..66c14c0f69 100644 --- a/engines/kyra/kyra_v3.cpp +++ b/engines/kyra/kyra_v3.cpp @@ -333,7 +333,7 @@ void KyraEngine_v3::playMenuAudioFile() { Common::SeekableReadStream *stream = _res->getFileStream(_menuAudioFile); if (stream) - _musicSoundChannel = _soundDigital->playSound(stream, SoundDigital::kSoundTypeMusic); + _musicSoundChannel = _soundDigital->playSound(stream, 0xFF, SoundDigital::kSoundTypeMusic); } void KyraEngine_v3::playMusicTrack(int track, int force) { @@ -356,7 +356,7 @@ void KyraEngine_v3::playMusicTrack(int track, int force) { Common::SeekableReadStream *stream = _res->getFileStream(_soundList[track]); if (stream) - _musicSoundChannel = _soundDigital->playSound(stream, SoundDigital::kSoundTypeMusic); + _musicSoundChannel = _soundDigital->playSound(stream, 0xFF, SoundDigital::kSoundTypeMusic); } _curMusicTrack = track; @@ -413,10 +413,11 @@ void KyraEngine_v3::playSoundEffect(int item, int volume) { if (_sfxFileMap[item*2+0] != 0xFF) { char filename[16]; snprintf(filename, 16, "%s.AUD", _sfxFileList[_sfxFileMap[item*2+0]]); + uint8 priority = _sfxFileMap[item*2+1]; Common::SeekableReadStream *stream = _res->getFileStream(filename); if (stream) - _soundDigital->playSound(stream, SoundDigital::kSoundTypeSfx, volume); + _soundDigital->playSound(stream, priority, SoundDigital::kSoundTypeSfx, volume); } } @@ -431,8 +432,9 @@ void KyraEngine_v3::snd_playVoiceFile(int file) { snprintf(filename, 16, "%u.AUD", (uint)file); Common::SeekableReadStream *stream = _res->getFileStream(filename); - if (stream) - _voiceSoundChannel = _soundDigital->playSound(stream, SoundDigital::kSoundTypeSpeech, 255); + if (stream) { + _voiceSoundChannel = _soundDigital->playSound(stream, 0xFE, SoundDigital::kSoundTypeSpeech, 255); + } } bool KyraEngine_v3::snd_voiceIsPlaying() { diff --git a/engines/kyra/sound.h b/engines/kyra/sound.h index fb70d6dcf1..04fbf3a1a9 100644 --- a/engines/kyra/sound.h +++ b/engines/kyra/sound.h @@ -515,6 +515,7 @@ public: * * @param stream Data stream used for playback * It will be deleted when playback is finished + * @param priority priority of the sound * @param type type * @param volume channel volume * @param loop true if the sound should loop (endlessly) @@ -522,7 +523,7 @@ public: * * @return channel playing the sound */ - int playSound(Common::SeekableReadStream *stream, kSoundTypes type, int volume = 255, bool loop = false, int channel = -1); + int playSound(Common::SeekableReadStream *stream, uint8 priority, kSoundTypes type, int volume = 255, bool loop = false, int channel = -1); /** * Checks if a given channel is playing a sound. @@ -559,6 +560,7 @@ private: struct Sound { Audio::SoundHandle handle; + uint8 priority; AUDStream *stream; } _sounds[4]; }; diff --git a/engines/kyra/sound_digital.cpp b/engines/kyra/sound_digital.cpp index ca9f8ff58a..0f671ba38f 100644 --- a/engines/kyra/sound_digital.cpp +++ b/engines/kyra/sound_digital.cpp @@ -328,7 +328,7 @@ SoundDigital::~SoundDigital() { stopSound(i); } -int SoundDigital::playSound(Common::SeekableReadStream *stream, kSoundTypes type, int volume, bool loop, int channel) { +int SoundDigital::playSound(Common::SeekableReadStream *stream, uint8 priority, kSoundTypes type, int volume, bool loop, int channel) { Sound *use = 0; if (channel != -1 && channel < ARRAYSIZE(_sounds)) { stopSound(channel); @@ -343,12 +343,23 @@ int SoundDigital::playSound(Common::SeekableReadStream *stream, kSoundTypes type } if (!use) { - warning("no free sound channel"); - delete stream; - return -1; + for (channel = 0; channel < ARRAYSIZE(_sounds); ++channel) { + if (_sounds[channel].priority <= priority) { + stopSound(channel); + use = &_sounds[channel]; + break; + } + } + + if (!use) { + warning("no free sound channel"); + delete stream; + return -1; + } } } + use->priority = priority; use->stream = new AUDStream(stream, loop); if (use->stream->endOfData()) { delete use->stream; -- cgit v1.2.3