From b57b223a59137b67e79a6f85d102ce3d2a61421d Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Tue, 13 Dec 2011 11:09:12 +0100 Subject: [PATCH] Add an out_of_range property to sound samples. If set the sound is set to non playing (which allows the OpenAL sound the be free'd) --- simgear/sound/sample_group.cxx | 8 ++++---- simgear/sound/sample_openal.cxx | 4 ++++ simgear/sound/sample_openal.hxx | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index bdc00ee6..0be6d13d 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -412,10 +412,10 @@ void SGSampleGroup::update_pos_and_orientation() { float max2 = sample->get_max_dist() * sample->get_max_dist(); float dist2 = position[0]*position[0] + position[1]*position[1] + position[2]*position[2]; - if (sample->is_playing() && (dist2 > max2)) { - sample->stop(); - } else if (!sample->is_playing() && (dist2 < max2)) { - sample->play(sample->is_looping()); + if ((dist2 > max2) && !sample->test_out_of_range()) { + sample->set_out_of_range(true); + } else if ((dist2 < max2) && sample->test_out_of_range()) { + sample->set_out_of_range(false); } } } diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 2029d9cc..13e27145 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -74,6 +74,7 @@ SGSoundSample::SGSoundSample() : _playing(false), _changed(true), _static_changed(true), + _out_of_range(false), _is_file(false) { } @@ -109,6 +110,7 @@ SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) : _playing(false), _changed(true), _static_changed(true), + _out_of_range(false), _is_file(true) { SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir); @@ -146,6 +148,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data, _playing(false), _changed(true), _static_changed(true), + _out_of_range(false), _is_file(false) { SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" ); @@ -182,6 +185,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : _playing(false), _changed(true), _static_changed(true), + _out_of_range(false), _is_file(false) { SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" ); diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 9e816c21..a5ad521d 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -152,6 +152,22 @@ public: */ inline bool is_playing() { return _playing; } + + /** + * Set this sample to out-of-range (or not) and + * Schedule this audio sample to stop (or start) playing. + */ + inline void set_out_of_range(bool oor = true) { + _out_of_range = oor; _playing = oor ? false : true; _changed = true; + } + + /** + * Test if this sample to out-of-range or not. + */ + inline bool test_out_of_range() { + return _out_of_range; + } + /** * Set the data associated with this audio sample * @param data Pointer to a memory block containg this audio sample data. @@ -495,6 +511,7 @@ private: bool _playing; bool _changed; bool _static_changed; + bool _out_of_range; bool _is_file; string random_string(); -- 2.39.5