aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2008-04-20 14:36:39 +0000
committerJohannes Schickel2008-04-20 14:36:39 +0000
commitd484c7ed434e9f8e8267049fccbe3dbb5c39fe0b (patch)
tree8e88c1fdb15ea892327851f8b3088f74f5747849
parent96fd18a13bbe4def704e1f9b15100f3dc48aaf64 (diff)
downloadscummvm-rg350-d484c7ed434e9f8e8267049fccbe3dbb5c39fe0b.tar.gz
scummvm-rg350-d484c7ed434e9f8e8267049fccbe3dbb5c39fe0b.tar.bz2
scummvm-rg350-d484c7ed434e9f8e8267049fccbe3dbb5c39fe0b.zip
Improved sound priority handling.
svn-id: r31598
-rw-r--r--engines/kyra/kyra_v3.cpp17
-rw-r--r--engines/kyra/sound.h7
-rw-r--r--engines/kyra/sound_digital.cpp37
3 files changed, 32 insertions, 29 deletions
diff --git a/engines/kyra/kyra_v3.cpp b/engines/kyra/kyra_v3.cpp
index 66c14c0f69..ef0cb41367 100644
--- a/engines/kyra/kyra_v3.cpp
+++ b/engines/kyra/kyra_v3.cpp
@@ -331,9 +331,7 @@ void KyraEngine_v3::playMenuAudioFile() {
if (_soundDigital->isPlaying(_musicSoundChannel))
return;
- Common::SeekableReadStream *stream = _res->getFileStream(_menuAudioFile);
- if (stream)
- _musicSoundChannel = _soundDigital->playSound(stream, 0xFF, SoundDigital::kSoundTypeMusic);
+ _musicSoundChannel = _soundDigital->playSound(_menuAudioFile, 0xFF, SoundDigital::kSoundTypeMusic);
}
void KyraEngine_v3::playMusicTrack(int track, int force) {
@@ -354,9 +352,7 @@ void KyraEngine_v3::playMusicTrack(int track, int force) {
if (_musicSoundChannel == -1) {
assert(track < _soundListSize && track >= 0);
- Common::SeekableReadStream *stream = _res->getFileStream(_soundList[track]);
- if (stream)
- _musicSoundChannel = _soundDigital->playSound(stream, 0xFF, SoundDigital::kSoundTypeMusic);
+ _musicSoundChannel = _soundDigital->playSound(_soundList[track], 0xFF, SoundDigital::kSoundTypeMusic);
}
_curMusicTrack = track;
@@ -415,9 +411,7 @@ void KyraEngine_v3::playSoundEffect(int item, int volume) {
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, priority, SoundDigital::kSoundTypeSfx, volume);
+ _soundDigital->playSound(filename, priority, SoundDigital::kSoundTypeSfx, volume);
}
}
@@ -431,10 +425,7 @@ void KyraEngine_v3::snd_playVoiceFile(int file) {
char filename[16];
snprintf(filename, 16, "%u.AUD", (uint)file);
- Common::SeekableReadStream *stream = _res->getFileStream(filename);
- if (stream) {
- _voiceSoundChannel = _soundDigital->playSound(stream, 0xFE, SoundDigital::kSoundTypeSpeech, 255);
- }
+ _voiceSoundChannel = _soundDigital->playSound(filename, 0xFE, SoundDigital::kSoundTypeSpeech, 255);
}
bool KyraEngine_v3::snd_voiceIsPlaying() {
diff --git a/engines/kyra/sound.h b/engines/kyra/sound.h
index 04fbf3a1a9..d61c095ac9 100644
--- a/engines/kyra/sound.h
+++ b/engines/kyra/sound.h
@@ -513,8 +513,7 @@ public:
/**
* Plays a sound.
*
- * @param stream Data stream used for playback
- * It will be deleted when playback is finished
+ * @param filename file to be played
* @param priority priority of the sound
* @param type type
* @param volume channel volume
@@ -523,7 +522,7 @@ public:
*
* @return channel playing the sound
*/
- int playSound(Common::SeekableReadStream *stream, uint8 priority, kSoundTypes type, int volume = 255, bool loop = false, int channel = -1);
+ int playSound(const char *filename, uint8 priority, kSoundTypes type, int volume = 255, bool loop = false, int channel = -1);
/**
* Checks if a given channel is playing a sound.
@@ -560,6 +559,8 @@ private:
struct Sound {
Audio::SoundHandle handle;
+
+ char filename[16];
uint8 priority;
AUDStream *stream;
} _sounds[4];
diff --git a/engines/kyra/sound_digital.cpp b/engines/kyra/sound_digital.cpp
index 0f671ba38f..a7f50a6e23 100644
--- a/engines/kyra/sound_digital.cpp
+++ b/engines/kyra/sound_digital.cpp
@@ -24,6 +24,7 @@
*/
#include "kyra/sound.h"
+#include "kyra/resource.h"
#include "sound/audiostream.h"
@@ -328,13 +329,13 @@ SoundDigital::~SoundDigital() {
stopSound(i);
}
-int SoundDigital::playSound(Common::SeekableReadStream *stream, uint8 priority, kSoundTypes type, int volume, bool loop, int channel) {
+int SoundDigital::playSound(const char *filename, uint8 priority, kSoundTypes type, int volume, bool loop, int channel) {
Sound *use = 0;
if (channel != -1 && channel < ARRAYSIZE(_sounds)) {
stopSound(channel);
use = &_sounds[channel];
} else {
- for (channel = 0; channel < ARRAYSIZE(_sounds); ++channel) {
+ for (channel = 0; !use && channel < ARRAYSIZE(_sounds); ++channel) {
if (!isPlaying(channel)) {
stopSound(channel);
use = &_sounds[channel];
@@ -342,23 +343,33 @@ int SoundDigital::playSound(Common::SeekableReadStream *stream, uint8 priority,
}
}
- if (!use) {
- for (channel = 0; channel < ARRAYSIZE(_sounds); ++channel) {
- if (_sounds[channel].priority <= priority) {
- stopSound(channel);
- use = &_sounds[channel];
- break;
- }
+ for (channel = 0; !use && channel < ARRAYSIZE(_sounds); ++channel) {
+ if (strcmp(_sounds[channel].filename, filename) == 0) {
+ stopSound(channel);
+ use = &_sounds[channel];
+ break;
}
+ }
- if (!use) {
- warning("no free sound channel");
- delete stream;
- return -1;
+ for (channel = 0; !use && channel < ARRAYSIZE(_sounds); ++channel) {
+ if (_sounds[channel].priority <= priority) {
+ stopSound(channel);
+ use = &_sounds[channel];
+ break;
}
}
+
+ if (!use) {
+ warning("no free sound channel");
+ return -1;
+ }
}
+ Common::SeekableReadStream *stream = _vm->resource()->getFileStream(filename);
+ if (!stream)
+ return -1;
+
+ strncpy(use->filename, filename, sizeof(use->filename));
use->priority = priority;
use->stream = new AUDStream(stream, loop);
if (use->stream->endOfData()) {