From d8e50b8a037de7f721491664610682f1076ca9ea Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 22 Oct 2011 19:37:49 +0200 Subject: KYRA: Fix memory leak when a sound is started but no free handles are left. --- engines/kyra/sound.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index b4fcea784e..0e83c1cb1f 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -109,8 +109,14 @@ bool Sound::playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *hand while (h < kNumChannelHandles && _mixer->isSoundHandleActive(_soundChannels[h])) ++h; - if (h >= kNumChannelHandles) + 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. + // See bug #3427240 "LOL-CD: Memory leak in caves level 3". + delete stream; return false; + } _mixer->playStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h], stream, -1, volume); if (handle) -- cgit v1.2.3 From 5be3ac9fcc7e057e74bb8eff9c0d234f887a0a50 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 29 Oct 2011 00:37:08 +0200 Subject: KYRA: Move non-empty virtual methods of Sound from sound.h to sound.cpp. --- engines/kyra/sound.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index 0e83c1cb1f..77fd8e2346 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -43,6 +43,22 @@ Sound::Sound(KyraEngine_v1 *vm, Audio::Mixer *mixer) Sound::~Sound() { } +Sound::kType Sound::getSfxType() const { + return getMusicType(); +} + +void Sound::setSoundList(const AudioDataStruct *list) { + _soundDataList = list; +} + +bool Sound::hasSoundFile(uint file) const { + return (fileListEntry(file) != 0); +} + +bool Sound::isPlaying() const { + return false; +} + bool Sound::voiceFileIsPresent(const char *file) { for (int i = 0; _supportedCodecs[i].fileext; ++i) { Common::String f = file; -- cgit v1.2.3 From 17883b913715f90c21f6831c1c0314bd46e2b55b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 29 Oct 2011 00:42:18 +0200 Subject: KYRA: Make more methods of Sound const. --- engines/kyra/sound.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index 77fd8e2346..e58e0c6359 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -59,7 +59,7 @@ bool Sound::isPlaying() const { return false; } -bool Sound::voiceFileIsPresent(const char *file) { +bool Sound::voiceFileIsPresent(const char *file) const { for (int i = 0; _supportedCodecs[i].fileext; ++i) { Common::String f = file; f += _supportedCodecs[i].fileext; @@ -70,7 +70,7 @@ bool Sound::voiceFileIsPresent(const char *file) { return false; } -bool Sound::isVoicePresent(const char *file) { +bool Sound::isVoicePresent(const char *file) const { char filenamebuffer[25]; for (int i = 0; _supportedCodecs[i].fileext; ++i) { @@ -96,7 +96,7 @@ int32 Sound::voicePlay(const char *file, Audio::SoundHandle *handle, uint8 volum return playTime; } -Audio::SeekableAudioStream *Sound::getVoiceStream(const char *file) { +Audio::SeekableAudioStream *Sound::getVoiceStream(const char *file) const { char filenamebuffer[25]; Audio::SeekableAudioStream *audioStream = 0; @@ -152,7 +152,7 @@ void Sound::voiceStop(const Audio::SoundHandle *handle) { } } -bool Sound::voiceIsPlaying(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])) @@ -165,7 +165,7 @@ bool Sound::voiceIsPlaying(const Audio::SoundHandle *handle) { return false; } -bool Sound::allVoiceChannelsPlaying() { +bool Sound::allVoiceChannelsPlaying() const { for (int i = 0; i < kNumChannelHandles; ++i) if (!_mixer->isSoundHandleActive(_soundChannels[i])) return false; -- cgit v1.2.3 From 951cb8ea71a6fc62fd9a247cbf407559e9935ec8 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 29 Oct 2011 00:43:52 +0200 Subject: KYRA: Get rid of Sound's voiceFileIsPresent in favor of isVoicePresent. --- engines/kyra/sound.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index e58e0c6359..e8d010480a 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -59,17 +59,6 @@ bool Sound::isPlaying() const { return false; } -bool Sound::voiceFileIsPresent(const char *file) const { - for (int i = 0; _supportedCodecs[i].fileext; ++i) { - Common::String f = file; - f += _supportedCodecs[i].fileext; - if (_vm->resource()->getFileSize(f.c_str()) > 0) - return true; - } - - return false; -} - bool Sound::isVoicePresent(const char *file) const { char filenamebuffer[25]; -- cgit v1.2.3 From 9d9837f217599fa238d5a9098b65994f089ece6b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 29 Oct 2011 00:46:47 +0200 Subject: KYRA: Prefer Common::String over plain char arrays in Sound. --- engines/kyra/sound.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index e8d010480a..af50f0f5cb 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -60,13 +60,13 @@ bool Sound::isPlaying() const { } bool Sound::isVoicePresent(const char *file) const { - char filenamebuffer[25]; + Common::String filename; for (int i = 0; _supportedCodecs[i].fileext; ++i) { - strcpy(filenamebuffer, file); - strcat(filenamebuffer, _supportedCodecs[i].fileext); + filename = file; + filename += _supportedCodecs[i].fileext; - if (_vm->resource()->exists(filenamebuffer)) + if (_vm->resource()->exists(filename.c_str())) return true; } @@ -86,14 +86,14 @@ int32 Sound::voicePlay(const char *file, Audio::SoundHandle *handle, uint8 volum } Audio::SeekableAudioStream *Sound::getVoiceStream(const char *file) const { - char filenamebuffer[25]; + Common::String filename; Audio::SeekableAudioStream *audioStream = 0; for (int i = 0; _supportedCodecs[i].fileext; ++i) { - strcpy(filenamebuffer, file); - strcat(filenamebuffer, _supportedCodecs[i].fileext); + filename = file; + filename += _supportedCodecs[i].fileext; - Common::SeekableReadStream *stream = _vm->resource()->createReadStream(filenamebuffer); + Common::SeekableReadStream *stream = _vm->resource()->createReadStream(filename); if (!stream) continue; -- cgit v1.2.3 From 7469187ef3dbfe34acef6d3a538489595e246b55 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 29 Oct 2011 00:56:39 +0200 Subject: KYRA: Move MixedSoundDriver implementation to sound.cpp. --- engines/kyra/sound.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index af50f0f5cb..5195271808 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -163,6 +163,91 @@ bool Sound::allVoiceChannelsPlaying() const { #pragma mark - +MixedSoundDriver::MixedSoundDriver(KyraEngine_v1 *vm, Audio::Mixer *mixer, Sound *music, Sound *sfx) + : Sound(vm, mixer), _music(music), _sfx(sfx) { +} + +MixedSoundDriver::~MixedSoundDriver() { + delete _music; + delete _sfx; +} + +Sound::kType MixedSoundDriver::getMusicType() const { + return _music->getMusicType(); +} + +Sound::kType MixedSoundDriver::getSfxType() const { + return _sfx->getSfxType(); +} + +bool MixedSoundDriver::init() { + return (_music->init() && _sfx->init()); +} + +void MixedSoundDriver::process() { + _music->process(); + _sfx->process(); +} + +void MixedSoundDriver::updateVolumeSettings() { + _music->updateVolumeSettings(); + _sfx->updateVolumeSettings(); +} + +void MixedSoundDriver::setSoundList(const AudioDataStruct *list) { + _music->setSoundList(list); + _sfx->setSoundList(list); +} + +bool MixedSoundDriver::hasSoundFile(uint file) const { + return _music->hasSoundFile(file) && _sfx->hasSoundFile(file); +} + +void MixedSoundDriver::loadSoundFile(uint file) { + _music->loadSoundFile(file); + _sfx->loadSoundFile(file); +} + +void MixedSoundDriver::loadSoundFile(Common::String file) { + _music->loadSoundFile(file); + _sfx->loadSoundFile(file); +} + +void MixedSoundDriver::loadSfxFile(Common::String file) { + _sfx->loadSoundFile(file); +} + +void MixedSoundDriver::playTrack(uint8 track) { + _music->playTrack(track); +} + +void MixedSoundDriver::haltTrack() { + _music->haltTrack(); +} + +bool MixedSoundDriver::isPlaying() const { + return _music->isPlaying() | _sfx->isPlaying(); +} + +void MixedSoundDriver::playSoundEffect(uint8 track) { + _sfx->playSoundEffect(track); +} + +void MixedSoundDriver::stopAllSoundEffects() { + _sfx->stopAllSoundEffects(); +} + +void MixedSoundDriver::beginFadeOut() { + _music->beginFadeOut(); +} + +void MixedSoundDriver::pause(bool paused) { + _music->pause(paused); + _sfx->pause(paused); +} + +#pragma mark - + void KyraEngine_v1::snd_playTheme(int file, int track) { if (_curMusicTheme == file) return; -- cgit v1.2.3 From 9fa9f68789ef51e078cb8631e06bead13cae13f2 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 12 Oct 2011 21:42:24 +0200 Subject: AUDIO: Implement a basic VocStream class. Now all VOCs are streamed rather than preloaded. This deprecates the STREAM_AUDIO_FROM_DISK define, which was previously used to stream VOCs from disk. This might very well break some engines which relied on the stream not being changed after makeVOCStream! I adapted all engines which had a check for STREAM_AUDIO_FROM_DISK in their code. It would be wise to check all other engines using VOC to see if this might cause any problems for them. --- engines/kyra/sound.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'engines/kyra/sound.cpp') diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index 5195271808..a1af1ad6f8 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -334,16 +334,7 @@ namespace { // A simple wrapper to create VOC streams the way like creating MP3, OGG/Vorbis and FLAC streams. // Possible TODO: Think of making this complete and moving it to sound/voc.cpp ? Audio::SeekableAudioStream *makeVOCStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse) { - -#ifdef STREAM_AUDIO_FROM_DISK Audio::SeekableAudioStream *as = Audio::makeVOCStream(stream, Audio::FLAG_UNSIGNED, disposeAfterUse); -#else - Audio::SeekableAudioStream *as = Audio::makeVOCStream(stream, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO); - - if (disposeAfterUse) - delete stream; -#endif - return as; } -- cgit v1.2.3