1
0
Fork 0

add avionics enable/disable and volume control to the sound fx class.

This commit is contained in:
ehofman 2009-12-02 09:34:06 +00:00 committed by Tim Moore
parent e657a53b32
commit c7ef67df80
3 changed files with 17 additions and 24 deletions

View file

@ -1260,7 +1260,7 @@ do_play_audio_sample (const SGPropertyNode * arg)
static FGSampleQueue *queue = 0;
if ( !queue ) {
SGSoundMgr *smgr = globals->get_soundmgr();
queue = new FGSampleQueue(smgr, "queue");
queue = new FGSampleQueue(smgr, "chatter");
queue->tie_to_listener();
}

View file

@ -39,18 +39,16 @@
#include <simgear/sound/xmlsound.hxx>
FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
last_enabled( true ),
last_volume( 0.0 ),
_enabled( fgGetNode("/sim/sound/effects/enabled", true) ),
_volume( fgGetNode("/sim/sound/effects/volume", true) )
_volume( fgGetNode("/sim/sound/effects/volume", true) ),
_avionics_enabled( fgGetNode("/sim/sound/avionics/enabled", true) ),
_avionics_volume( fgGetNode("/sim/sound/avionics/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);
}
@ -118,22 +116,16 @@ FGFX::reinit()
void
FGFX::update (double dt)
{
bool new_enabled = _enabled->getBoolValue();
if ( new_enabled != last_enabled ) {
if ( new_enabled ) {
resume();
} else {
suspend();
}
last_enabled = new_enabled;
}
if ( _avionics_enabled->getBoolValue() )
_avionics->resume(); // no-op if already in resumed state
else
_avionics->suspend();
_avionics->set_volume( _avionics_volume->getDoubleValue() );
if ( new_enabled ) {
double volume = _volume->getDoubleValue();
if ( volume != last_volume ) {
set_volume( volume );
last_volume = volume;
}
if ( _enabled->getBoolValue() ) {
set_volume( _volume->getDoubleValue() );
resume();
// update sound effects if not paused
for ( unsigned int i = 0; i < _sound.size(); i++ ) {
@ -142,6 +134,8 @@ FGFX::update (double dt)
SGSampleGroup::update(dt);
}
else
suspend();
}
// end of fg_fx.cxx

View file

@ -60,11 +60,10 @@ private:
SGSharedPtr<SGSampleGroup> _avionics;
std::vector<SGXmlSound *> _sound;
bool last_enabled;
double last_volume;
SGPropertyNode_ptr _enabled;
SGPropertyNode_ptr _volume;
SGPropertyNode_ptr _avionics_enabled;
SGPropertyNode_ptr _avionics_volume;
};