1
0
Fork 0

Make the sound-manager optional in a few places.

This commit is contained in:
James Turner 2012-10-01 10:10:34 +01:00
parent 21d50b11f5
commit bcea720db3
7 changed files with 52 additions and 16 deletions

View file

@ -143,12 +143,17 @@ FGAIBase::~FGAIBase() {
model_removed->setStringValue(props->getPath());
}
// refID=0 is supposedley impossible, refID=1 is the special ai_ac aircaft
// representing the current user, in the ATCManager. Maybe both these
// tests could die?
if (_fx && _refID != 0 && _refID != 1) {
SGSoundMgr *smgr = globals->get_soundmgr();
stringstream name;
name << "aifx:";
name << _refID;
smgr->remove(name.str());
if (smgr) {
stringstream name;
name << "aifx:";
name << _refID;
smgr->remove(name.str());
}
}
if (fp)
@ -245,11 +250,10 @@ void FGAIBase::update(double dt) {
props->setStringValue("sim/sound/path", fxpath.c_str());
// initialize the sound configuration
SGSoundMgr *smgr = globals->get_soundmgr();
stringstream name;
name << "aifx:";
name << _refID;
_fx = new FGFX(smgr, name.str(), props);
_fx = new FGFX(name.str(), props);
_fx->init();
}
}

View file

@ -1106,6 +1106,12 @@ do_set_cursor (const SGPropertyNode * arg)
static bool
do_play_audio_sample (const SGPropertyNode * arg)
{
SGSoundMgr *smgr = globals->get_soundmgr();
if (!smgr) {
SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
return false;
}
string path = arg->getStringValue("path");
string file = arg->getStringValue("file");
float volume = arg->getFloatValue("volume");
@ -1113,7 +1119,6 @@ do_play_audio_sample (const SGPropertyNode * arg)
try {
static FGSampleQueue *queue = 0;
if ( !queue ) {
SGSoundMgr *smgr = globals->get_soundmgr();
queue = new FGSampleQueue(smgr, "chatter");
queue->tie_to_listener();
}

View file

@ -48,8 +48,7 @@ FGAircraftModel::FGAircraftModel ()
_speed_e(0),
_speed_d(0)
{
SGSoundMgr *smgr = globals->get_soundmgr();
_fx = new FGFX(smgr, "fx");
_fx = new FGFX("fx");
_fx->init();
}

View file

@ -32,6 +32,7 @@
#include "fg_fx.hxx"
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
@ -39,7 +40,7 @@
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/sound/xmlsound.hxx>
FGFX::FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props ) :
FGFX::FGFX ( const std::string &refname, SGPropertyNode *props ) :
_props( props )
{
if (!props) {
@ -60,6 +61,11 @@ FGFX::FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props
_avionics_ext = _props->getNode("sim/sound/avionics/external-view", true);
_internal = _props->getNode("sim/current-view/internal", true);
SGSoundMgr *smgr = globals->get_soundmgr();
if (!smgr) {
return;
}
SGSampleGroup::_smgr = smgr;
SGSampleGroup::_refname = refname;
SGSampleGroup::_smgr->add(this, refname);
@ -84,6 +90,10 @@ FGFX::~FGFX ()
void
FGFX::init()
{
if (!_smgr) {
return;
}
SGPropertyNode *node = _props->getNode("sim/sound", true);
std::string path_str = node->getStringValue("path");
@ -143,6 +153,10 @@ FGFX::reinit()
void
FGFX::update (double dt)
{
if (!_smgr) {
return;
}
if ( _enabled->getBoolValue() ) {
if ( _avionics_enabled->getBoolValue())
{

View file

@ -49,7 +49,7 @@ class FGFX : public SGSampleGroup
public:
FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props = 0 );
FGFX ( const std::string &refname, SGPropertyNode *props = 0 );
virtual ~FGFX ();
virtual void init ();

View file

@ -65,6 +65,12 @@ using std::vector;
// FGVoicePlayer::Voice::SampleElement ///////////////////////////
/////////////////////////////////////////////////////////////////////////
FGVoicePlayer::Voice::SampleElement::SampleElement (SGSharedPtr<SGSoundSample> sample, float volume)
: _sample(sample), _volume(volume)
{
silence = false;
}
void FGVoicePlayer::Voice::SampleElement::play (float volume)
{
if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); }
@ -179,7 +185,9 @@ FGVoicePlayer::FGVoicePlayer (PropertiesHandler* properties_handler, string _dev
: volume(1.0), voice(NULL), next_voice(NULL), paused(false),
dev_name(_dev_name), dir_prefix(""),
speaker(this,properties_handler)
{}
{
_sgr = NULL;
}
FGVoicePlayer::~FGVoicePlayer ()
{
@ -339,3 +347,10 @@ FGVoicePlayer::update ()
}
}
}
void
FGVoicePlayer::append (Voice *voice, const char *sample_name)
{
voice->append(new Voice::SampleElement(get_sample(sample_name)));
}

View file

@ -149,9 +149,8 @@ public:
float _volume;
public:
SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
: _sample(sample), _volume(volume) { silence = false; }
SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0);
virtual void play (float volume);
virtual void stop ();
virtual bool is_playing ();
@ -311,7 +310,7 @@ protected:
SGSoundSample *get_sample (const char *name);
inline void append (Voice *voice, Voice::Element *element) { voice->append(element); }
inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); }
void append (Voice *voice, const char *sample_name);
inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); }
inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); }