From: Christoph Sommer Date: Fri, 26 May 2006 12:19:15 +0000 (+0000) Subject: Workaround for a bug with stopped SoundSource not being able to resume playing X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e40ca5f96ed68d602c7027ae8a183ee7871ee4d3;p=supertux.git Workaround for a bug with stopped SoundSource not being able to resume playing SVN-Revision: 3591 --- diff --git a/src/audio/managed_sound_source.cpp b/src/audio/managed_sound_source.cpp index 3644298c2..167608f8e 100644 --- a/src/audio/managed_sound_source.cpp +++ b/src/audio/managed_sound_source.cpp @@ -23,19 +23,13 @@ #include "log.hpp" ManagedSoundSource::ManagedSoundSource(SoundManager* sound_manager, const std::string& name) - : name(name), soundManager(sound_manager) + : name(name), soundSource(0), soundManager(sound_manager) { - soundSource = soundManager->create_sound_source(name); - if(!soundSource) { - log_warning << "Couldn't create managed sound source for \"" << name << "\"" << std::endl; - return; - } } ManagedSoundSource::ManagedSoundSource(const ManagedSoundSource& other) - : name(other.name), soundManager(other.soundManager) + : name(other.name), soundSource(0), soundManager(other.soundManager) { - soundSource = soundManager->create_sound_source(name); } ManagedSoundSource::~ManagedSoundSource() @@ -43,3 +37,44 @@ ManagedSoundSource::~ManagedSoundSource() delete soundSource; } +bool +ManagedSoundSource::preload() +{ + if (soundSource) return true; + soundSource = soundManager->create_sound_source(name); + return (soundSource != 0); +} + +void +ManagedSoundSource::release() +{ + if (!soundSource) return; + if (playing()) soundSource->stop(); + delete soundSource; + soundSource = 0; +} + +void +ManagedSoundSource::play() +{ + if (!preload()) { + log_warning << "Couldn't play \"" << name << "\"" << std::endl; + return; + } + soundSource->play(); +} + +void +ManagedSoundSource::stop() +{ + // FIXME: calling release() instead of stop() seems necessary due to an unconfirmed sound bug + release(); +} + +bool +ManagedSoundSource::playing() +{ + if (!soundSource) return false; + return soundSource->playing(); +} + diff --git a/src/audio/managed_sound_source.hpp b/src/audio/managed_sound_source.hpp index d22b72ab0..cebf6ad09 100644 --- a/src/audio/managed_sound_source.hpp +++ b/src/audio/managed_sound_source.hpp @@ -40,17 +40,17 @@ public: * pre-loads SoundSource and indicates success. * If pre-loading failed, the SoundSource will be loaded at first use */ - bool preload() { return (soundSource != 0); /* TODO: implement */ } + bool preload(); /** * stops playing and temporarily releases memory for the SoundSource. * Memory will be re-allocated on next use */ - void release() { if (playing()) stop(); /* TODO: implement*/ } + void release(); - void play() { if (preload()) soundSource->play(); } - void stop() { if (preload()) soundSource->stop(); } - bool playing() { return ((preload())?(soundSource->playing()):(false)); } + void play(); + void stop(); + bool playing(); void set_looping(bool looping) { if (preload()) soundSource->set_looping(looping); } void set_gain(float gain) { if (preload()) soundSource->set_gain(gain); } void set_pitch(float pitch) { if (preload()) soundSource->set_pitch(pitch); }