aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/sound.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2009-05-24 01:29:09 +0000
committerJohannes Schickel2009-05-24 01:29:09 +0000
commit344caa88fcf8ce352e7bee6b2c6d4a8df2df548e (patch)
tree34060263b7e3c21cfab3df09ce811fe7d094d34e /engines/kyra/sound.cpp
parentc2812140274d1c37e57f732f0a30e8a39d30e2ca (diff)
downloadscummvm-rg350-344caa88fcf8ce352e7bee6b2c6d4a8df2df548e.tar.gz
scummvm-rg350-344caa88fcf8ce352e7bee6b2c6d4a8df2df548e.tar.bz2
scummvm-rg350-344caa88fcf8ce352e7bee6b2c6d4a8df2df548e.zip
Make various Sound functionality SoundHandle instead of filename based.
- This fixes multiple sounds being played at once in Lands of Lore svn-id: r40848
Diffstat (limited to 'engines/kyra/sound.cpp')
-rw-r--r--engines/kyra/sound.cpp81
1 files changed, 28 insertions, 53 deletions
diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp
index cd86d388d8..62eedae559 100644
--- a/engines/kyra/sound.cpp
+++ b/engines/kyra/sound.cpp
@@ -49,24 +49,17 @@ Sound::~Sound() {
}
bool Sound::voiceFileIsPresent(const char *file) {
- char filenamebuffer[25];
for (int i = 0; _supportedCodecs[i].fileext; ++i) {
- strcpy(filenamebuffer, file);
- strcat(filenamebuffer, _supportedCodecs[i].fileext);
- if (_vm->resource()->getFileSize(filenamebuffer) > 0)
+ Common::String f = file;
+ f += _supportedCodecs[i].fileext;
+ if (_vm->resource()->getFileSize(f.c_str()) > 0)
return true;
}
- strcpy(filenamebuffer, file);
- strcat(filenamebuffer, ".VOC");
-
- if (_vm->resource()->getFileSize(filenamebuffer) > 0)
- return true;
-
return false;
}
-int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx) {
+int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx, Audio::SoundHandle *handle) {
Audio::AudioStream *audioStream = getVoiceStream(file);
if (!audioStream) {
@@ -75,7 +68,7 @@ int32 Sound::voicePlay(const char *file, uint8 volume, bool isSfx) {
}
int playTime = audioStream->getTotalPlayTime();
- playVoiceStream(audioStream, file, volume, isSfx);
+ playVoiceStream(audioStream, handle, volume, isSfx);
return playTime;
}
@@ -97,66 +90,51 @@ Audio::AudioStream *Sound::getVoiceStream(const char *file) {
return audioStream;
}
-void Sound::playVoiceStream(Audio::AudioStream *stream, const char *handleName, uint8 volume, bool isSfx) {
+bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *handle, uint8 volume, bool isSfx) {
int h = 0;
- while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles)
+ while (_mixer->isSoundHandleActive(_soundChannels[h]) && h < kNumChannelHandles)
h++;
if (h >= kNumChannelHandles)
- return;
+ return false;
+
+ _mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h], stream, -1, volume);
+ if (handle)
+ *handle = _soundChannels[h];
- _soundChannels[h].file = handleName;
- _mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, stream, -1, volume);
+ return true;
}
-void Sound::voiceStop(const char *file) {
- if (!file) {
+void Sound::voiceStop(const Audio::SoundHandle *handle) {
+ if (!handle) {
for (int h = 0; h < kNumChannelHandles; h++) {
- if (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle))
- _mixer->stopHandle(_soundChannels[h].channelHandle);
+ if (_mixer->isSoundHandleActive(_soundChannels[h]))
+ _mixer->stopHandle(_soundChannels[h]);
}
} else {
- for (int i = 0; i < kNumChannelHandles; ++i) {
- if (_soundChannels[i].file == file)
- _mixer->stopHandle(_soundChannels[i].channelHandle);
- }
+ _mixer->stopHandle(*handle);
}
}
-bool Sound::voiceIsPlaying(const char *file) {
- bool res = false;
- if (!file) {
+bool Sound::voiceIsPlaying(const Audio::SoundHandle *handle) {
+ if (!handle) {
for (int h = 0; h < kNumChannelHandles; h++) {
- if (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle))
- res = true;
+ if (_mixer->isSoundHandleActive(_soundChannels[h]))
+ return true;
}
} else {
- for (int i = 0; i < kNumChannelHandles; ++i) {
- if (_soundChannels[i].file == file)
- res = _mixer->isSoundHandleActive(_soundChannels[i].channelHandle);
- }
+ return _mixer->isSoundHandleActive(*handle);
}
- return res;
+
+ return false;
}
bool Sound::allVoiceChannelsPlaying() {
for (int i = 0; i < kNumChannelHandles; ++i)
- if (!_mixer->isSoundHandleActive(_soundChannels[i].channelHandle))
+ if (!_mixer->isSoundHandleActive(_soundChannels[i]))
return false;
return true;
}
-uint32 Sound::voicePlayedTime(const char *file) {
- if (!file)
- return 0;
-
- for (int i = 0; i < kNumChannelHandles; ++i) {
- if (_soundChannels[i].file == file)
- return _mixer->getSoundElapsedTime(_soundChannels[i].channelHandle);
- }
-
- return 0;
-}
-
#pragma mark -
void KyraEngine_v1::snd_playTheme(int file, int track) {
@@ -224,14 +202,11 @@ void KyraEngine_v1::snd_playWanderScoreViaMap(int command, int restart) {
}
void KyraEngine_v1::snd_stopVoice() {
- if (!_speechFile.empty()) {
- _sound->voiceStop(_speechFile.c_str());
- _speechFile.clear();
- }
+ _sound->voiceStop(&_speechHandle);
}
bool KyraEngine_v1::snd_voiceIsPlaying() {
- return _speechFile.empty() ? false : _sound->voiceIsPlaying(_speechFile.c_str());
+ return _sound->voiceIsPlaying(&_speechHandle);
}
// static res