From b25940e1ea03af325a8a3648e1f389d7a489b22e Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 19 Oct 2009 10:41:17 +0000 Subject: [PATCH] Fix a number of small bugs; eg test if SoundMgr::load fails and return false in that case. --- src/ATCDCL/ATCVoice.cxx | 3 ++- src/Sound/fg_fx.cxx | 19 +++++++------- src/Sound/sample_queue.cxx | 51 ++++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/ATCDCL/ATCVoice.cxx b/src/ATCDCL/ATCVoice.cxx index 023dde22c..bcd48f54a 100644 --- a/src/ATCDCL/ATCVoice.cxx +++ b/src/ATCDCL/ATCVoice.cxx @@ -74,7 +74,8 @@ bool FGATCVoice::LoadVoice(const string& voice) { int format, freq; SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr"); void *data; - smgr->load(full_path, &data, &format, &rawDataSize, &freq); + if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq)) + return false; rawSoundData = (char*)data; #ifdef VOICE_TEST cout << "ATCVoice: format: " << format diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 8bc493bfa..4d879bff2 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -39,7 +39,7 @@ #include FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) : - last_pause( true ), + last_pause( false ), last_volume( 0.0 ), _pause( fgGetNode("/sim/sound/pause") ), _volume( fgGetNode("/sim/sound/volume") ) @@ -114,7 +114,6 @@ FGFX::reinit() void FGFX::update (double dt) { - // command sound manger bool new_pause = _pause->getBoolValue(); if ( new_pause != last_pause ) { if ( new_pause ) { @@ -125,20 +124,20 @@ FGFX::update (double dt) last_pause = new_pause; } - double volume = _volume->getDoubleValue(); - if ( volume != last_volume ) { - set_volume( volume ); - last_volume = volume; - } - if ( !new_pause ) { + double volume = _volume->getDoubleValue(); + if ( volume != last_volume ) { + set_volume( volume ); + last_volume = volume; + } + // update sound effects if not paused for ( unsigned int i = 0; i < _sound.size(); i++ ) { _sound[i]->update(dt); } - } - SGSampleGroup::update(dt); + SGSampleGroup::update(dt); + } } // end of fg_fx.cxx diff --git a/src/Sound/sample_queue.cxx b/src/Sound/sample_queue.cxx index d032a8d90..f09870947 100644 --- a/src/Sound/sample_queue.cxx +++ b/src/Sound/sample_queue.cxx @@ -37,7 +37,7 @@ #include FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const string &refname ) : - last_pause( true ), + last_pause( false ), last_volume( 0.0 ), _pause( fgGetNode("/sim/sound/pause") ), _volume( fgGetNode("/sim/sound/volume") ) @@ -59,6 +59,7 @@ FGSampleQueue::~FGSampleQueue () void FGSampleQueue::update (double dt) { +return; // command sound manger bool new_pause = _pause->getBoolValue(); if ( new_pause != last_pause ) { @@ -70,34 +71,36 @@ FGSampleQueue::update (double dt) last_pause = new_pause; } - double volume = _volume->getDoubleValue(); - if ( volume != last_volume ) { - set_volume( volume ); - last_volume = volume; - } + if ( !new_pause ) { + double volume = _volume->getDoubleValue(); + if ( volume != last_volume ) { + set_volume( volume ); + last_volume = volume; + } - // process mesage queue - const string msgid = "Sequential Audio Message"; - bool now_playing = false; - if ( exists( msgid ) ) { - now_playing = is_playing( msgid ); - if ( !now_playing ) { - // current message finished, stop and remove - stop( msgid ); // removes source - remove( msgid ); // removes buffer + // process mesage queue + const string msgid = "Sequential Audio Message"; + bool now_playing = false; + if ( exists( msgid ) ) { + now_playing = is_playing( msgid ); + if ( !now_playing ) { + // current message finished, stop and remove + stop( msgid ); // removes source + remove( msgid ); // removes buffer + } } - } - if ( !now_playing ) { - // message queue idle, add next sound if we have one - if ( _messages.size() > 0 ) { - SGSampleGroup::add( _messages.front(), msgid ); - _messages.pop(); - play_once( msgid ); + if ( !now_playing ) { + // message queue idle, add next sound if we have one + if ( _messages.size() > 0 ) { + SGSampleGroup::add( _messages.front(), msgid ); + _messages.pop(); + play_once( msgid ); + } } - } - SGSampleGroup::update(dt); + SGSampleGroup::update(dt); + } } // end of _samplequeue.cxx -- 2.39.5