From 3a4892cedea92e66f0763fc2008896154498f691 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 29 Nov 2009 10:24:47 +0000 Subject: [PATCH] New Property layout: /sim/sound/enabled enable/disable the use of OpenAL /sin/sound/pause master mute, effects all SampleGroups /sim/sound/volume master volume /sim/sound/effects/enabled enable/disable (mute) sound fx /sim/sound/effects/volume effects volume /sim/sound/chatter/enabled enable/disable (mute) atc chatter /sim/sound/chatter/volume chatter (sample queue) volume --- src/Main/main.cxx | 30 +++++++++++++++++++++--------- src/Sound/fg_fx.cxx | 22 ++++++++++++---------- src/Sound/fg_fx.hxx | 4 ++-- src/Sound/sample_queue.cxx | 22 ++++++++++++---------- src/Sound/sample_queue.hxx | 4 ++-- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 66bf3c6d8..896a38bfe 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -480,7 +480,23 @@ static void fgMainLoop( void ) { // Update the sound manager last so it can use the CPU while the GPU // is processing the scenery (doubled the frame-rate for me) -EMH- #ifdef ENABLE_AUDIO_SUPPORT - globals->get_soundmgr()->update(delta_time_sec); + static SGPropertyNode *sound_pause = fgGetNode("/sim/sound/pause"); + static SGSoundMgr *smgr = globals->get_soundmgr(); + static bool smgr_suspend = false; + if (smgr_suspend != sound_pause->getBoolValue()) { + if (smgr_suspend == false) { // request to suspend + smgr->suspend(); + } else { + smgr->resume(); + } + smgr_suspend = sound_pause->getBoolValue(); + } + + if (smgr_suspend == false) { + static SGPropertyNode *volume = fgGetNode("/sim/sound/volume"); + smgr->set_volume(volume->getFloatValue()); + smgr->update(delta_time_sec); + } #endif // END Tile Manager udpates @@ -488,15 +504,11 @@ static void fgMainLoop( void ) { if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded() && cur_fdm_state->get_inited()) { fgSetBool("sim/sceneryloaded",true); -#ifdef ENABLE_AUDIO_SUPPORT - if (fgGetBool("/sim/sound/enabled") == true) { - float volume = fgGetFloat("/sim/sound/volume"); - globals->get_soundmgr()->set_volume(volume); - globals->get_soundmgr()->activate(); + if (fgGetBool("/sim/sound/enabled")) { + smgr->activate(); + } else { + smgr->stop(); } - else - globals->get_soundmgr()->stop(); -#endif } fgRequestRedraw(); diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index d2addc66d..831375454 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -39,16 +39,18 @@ #include FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) : - last_pause( false ), + last_enabled( true ), last_volume( 0.0 ), - _pause( fgGetNode("/sim/sound/pause") ), - _volume( fgGetNode("/sim/sound/volume") ) + _enabled( fgGetNode("/sim/sound/effects/enabled", true) ), + _volume( fgGetNode("/sim/sound/effects/volume", true) ) { SGSampleGroup::_smgr = smgr; SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); _avionics = _smgr->find("avionics", true); _avionics->tie_to_listener(); + _enabled->setBoolValue(true); + _volume->setFloatValue(1.0); } @@ -116,17 +118,17 @@ FGFX::reinit() void FGFX::update (double dt) { - bool new_pause = _pause->getBoolValue(); - if ( new_pause != last_pause ) { - if ( new_pause ) { - suspend(); - } else { + bool new_enabled = _enabled->getBoolValue(); + if ( new_enabled != last_enabled ) { + if ( new_enabled ) { resume(); + } else { + suspend(); } - last_pause = new_pause; + last_enabled = new_enabled; } - if ( !new_pause ) { + if ( new_enabled ) { double volume = _volume->getDoubleValue(); if ( volume != last_volume ) { set_volume( volume ); diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 8a004465c..f28d3677b 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -60,10 +60,10 @@ private: SGSharedPtr _avionics; std::vector _sound; - bool last_pause; + bool last_enabled; double last_volume; - SGPropertyNode_ptr _pause; + SGPropertyNode_ptr _enabled; SGPropertyNode_ptr _volume; }; diff --git a/src/Sound/sample_queue.cxx b/src/Sound/sample_queue.cxx index 863cbcbdc..e5c2293a6 100644 --- a/src/Sound/sample_queue.cxx +++ b/src/Sound/sample_queue.cxx @@ -37,14 +37,16 @@ #include FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const string &refname ) : - last_pause( false ), + last_enabled( true ), last_volume( 0.0 ), - _pause( fgGetNode("/sim/sound/pause") ), - _volume( fgGetNode("/sim/sound/volume") ) + _enabled( fgGetNode("/sim/sound/chatter/enabled", true) ), + _volume( fgGetNode("/sim/sound/chatter/volume", true) ) { SGSampleGroup::_smgr = smgr; SGSampleGroup::_smgr->add(this, refname); SGSampleGroup::_refname = refname; + _enabled->setBoolValue(true); + _volume->setFloatValue(1.0); } @@ -61,17 +63,17 @@ void FGSampleQueue::update (double dt) { // command sound manger - bool new_pause = _pause->getBoolValue(); - if ( new_pause != last_pause ) { - if ( new_pause ) { - suspend(); - } else { + bool new_enabled = _enabled->getBoolValue(); + if ( new_enabled != last_enabled ) { + if ( new_enabled ) { resume(); + } else { + suspend(); } - last_pause = new_pause; + last_enabled = new_enabled; } - if ( !new_pause ) { + if ( new_enabled ) { double volume = _volume->getDoubleValue(); if ( volume != last_volume ) { set_volume( volume ); diff --git a/src/Sound/sample_queue.hxx b/src/Sound/sample_queue.hxx index 88b30ae75..db3d9c785 100644 --- a/src/Sound/sample_queue.hxx +++ b/src/Sound/sample_queue.hxx @@ -57,10 +57,10 @@ private: std::queue< SGSharedPtr > _messages; - bool last_pause; + bool last_enabled; double last_volume; - SGPropertyNode_ptr _pause; + SGPropertyNode_ptr _enabled; SGPropertyNode_ptr _volume; };