#include <Scenery/tilemgr.hxx>
#include <Scenery/scenery.hxx>
#include <Scripting/NasalSys.hxx>
-#include <Sound/fg_fx.hxx>
+#include <Sound/sample_queue.hxx>
#include <Time/sunsolver.hxx>
#include <Time/tmp.hxx>
{
string path = arg->getStringValue("path");
string file = arg->getStringValue("file");
- double volume = arg->getDoubleValue("volume");
+ float volume = arg->getFloatValue("volume");
// cout << "playing " << path << " / " << file << endl;
try {
- static FGFX *fx = 0;
- if ( !fx ) {
+ static FGSampleQueue *queue = 0;
+ if ( !queue ) {
SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
- fx = (FGFX *)smgr->find("fx");
+ queue = new FGSampleQueue(smgr, "queue");
+ queue->tie_to_listener();
}
- if (fx) fx->play_message( path, file, volume );
+
+ SGSoundSample *msg = new SGSoundSample(path.c_str(), file.c_str());
+ msg->set_volume( volume );
+ queue->add( msg );
+
return true;
} catch (const sg_io_exception&) {
beacon.cxx beacon.hxx \
fg_fx.cxx fg_fx.hxx \
morse.cxx morse.hxx \
- voice.cxx voice.hxx
+ voice.cxx voice.hxx \
+ sample_queue.cxx sample_queue.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
#include "fg_fx.hxx"
-#include <simgear/debug/logstream.hxx>
-#include <simgear/structure/exception.hxx>
-#include <simgear/misc/sg_path.hxx>
+#include <Main/fg_props.hxx>
+
#include <simgear/props/props.hxx>
+#include <simgear/misc/sg_path.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/sound/xmlsound.hxx>
-#include <Main/fg_props.hxx>
-
-#include <simgear/scene/model/placement.hxx>
-#include <Model/acmodel.hxx>
-#include <Main/viewer.hxx>
-
FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
- last_visitor_pos(SGVec3d::zeros()),
- last_model_pos(SGVec3d::zeros()),
last_pause( true ),
last_volume( 0.0 ),
_pause( fgGetNode("/sim/sound/pause") ),
FGFX::~FGFX ()
{
- unsigned int i;
- for ( i = 0; i < _sound.size(); i++ ) {
+ for (unsigned int i = 0; i < _sound.size(); i++ ) {
delete _sound[i];
}
_sound.clear();
-
- while ( _samplequeue.size() > 0 ) {
- delete _samplequeue.front();
- _samplequeue.pop();
- }
}
last_pause = new_pause;
}
- // process mesage queue
- const string msgid = "Sequential Audio Message";
- bool now_playing = false;
- if ( exists( msgid ) ) {
- if ( is_playing( msgid ) ) {
- // still playing, do nothing
- now_playing = true;
- } else {
- // 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 ( _samplequeue.size() > 0 ) {
- add( _samplequeue.front(), msgid );
- _samplequeue.pop();
- play_once( msgid );
- }
- }
-
double volume = _volume->getDoubleValue();
if ( volume != last_volume ) {
set_volume( volume );
SGSampleGroup::update(dt);
}
-/**
- * add a sound sample to the message queue which is played sequentially
- * in order.
- */
-void
-FGFX::play_message( SGSoundSample *_sample )
-{
- _samplequeue.push( _sample );
-}
-void
-FGFX::play_message( const std::string& path, const std::string& fname, double volume )
-{
- SGSoundSample *sample = new SGSoundSample( path.c_str(), fname.c_str() );
- sample->set_volume( volume );
- play_message( sample );
-}
-
// end of fg_fx.cxx
#include <simgear/compiler.h>
-#include <queue>
#include <vector>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/sound/sample_group.hxx>
-#include <simgear/math/SGMath.hxx>
class SGXmlSound;
* Generator for FlightGear sound effects.
*
* This module uses a FGSampleGroup class to generate sound effects based
- * on current flight conditions. The sound manager must be initialized
+ * on current flight conditions. The sound manager must be initialized
* before this object is.
*
- * Note: this module supports two separate sound mechanisms concurrently.
- *
- * 1. This module will load and play a set of sound effects defined in an
+ * This module will load and play a set of sound effects defined in an
* xml file and tie them to various property states.
- * 2. This modules also maintains a queue of 'message' audio files. These
- * are played sequentially with no overlap until the queue is finished.
- * This second mechanims is useful for things like tutorial messages or
- * background atc chatter.
*/
class FGFX : public SGSampleGroup
{
virtual void reinit ();
virtual void update (double dt);
- /**
- * add a sound sample to the message queue which is played sequentially
- * in order.
- */
- void play_message( SGSoundSample *_sample );
- void play_message( const std::string& path, const std::string& fname, double volume );
-
private:
- void update_pos_and_orientation(double dt);
-
- SGVec3d last_visitor_pos;
- SGVec3d last_model_pos;
-
std::vector<SGXmlSound *> _sound;
- std::queue<SGSoundSample *> _samplequeue;
bool last_pause;
double last_volume;
--- /dev/null
+// _samplequeue.cxx -- Sound effect management class implementation
+//
+// Started by David Megginson, October 2001
+// (Reuses some code from main.cxx, probably by Curtis Olson)
+//
+// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#ifdef _MSC_VER
+#pragma warning (disable: 4786)
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "sample_queue.hxx"
+
+#include <Main/fg_props.hxx>
+
+#include <simgear/sound/soundmgr_openal.hxx>
+#include <simgear/sound/sample_openal.hxx>
+
+FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const string &refname ) :
+ last_pause( true ),
+ last_volume( 0.0 ),
+ _pause( fgGetNode("/sim/sound/pause") ),
+ _volume( fgGetNode("/sim/sound/volume") )
+{
+ SGSampleGroup::_smgr = smgr;
+ SGSampleGroup::_smgr->add(this, refname);
+ SGSampleGroup::_active = _smgr->is_working();
+}
+
+
+FGSampleQueue::~FGSampleQueue ()
+{
+ while ( _messages.size() > 0 ) {
+ delete _messages.front();
+ _messages.pop();
+ }
+}
+
+
+void
+FGSampleQueue::update (double dt)
+{
+ // command sound manger
+ bool new_pause = _pause->getBoolValue();
+ if ( new_pause != last_pause ) {
+ if ( new_pause ) {
+ suspend();
+ } else {
+ resume();
+ }
+ last_pause = 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
+ }
+ }
+
+ 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);
+}
+
+// end of _samplequeue.cxx
--- /dev/null
+// sample_queue.hxx -- sample queue management class
+//
+// Started by David Megginson, October 2001
+// (Reuses some code from main.cxx, probably by Curtis Olson)
+//
+// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#ifndef __FGSAMPLE_QUEUE_HXX
+#define __FGSAMPLE_QUEUE_HXX 1
+
+#include <simgear/compiler.h>
+
+#include <queue>
+
+#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/sound/sample_group.hxx>
+
+class SGSoundSample;
+
+/**
+ * FlightGear sample queue class
+ *
+ * This modules maintains a queue of 'message' audio files. These
+ * are played sequentially with no overlap until the queue is finished.
+ * This second mechanims is useful for things like tutorial messages or
+ * background atc chatter.
+ */
+class FGSampleQueue : public SGSampleGroup
+{
+
+public:
+
+ FGSampleQueue ( SGSoundMgr *smgr, const string &refname );
+ virtual ~FGSampleQueue ();
+
+ virtual void update (double dt);
+
+ inline void add (SGSoundSample *msg) { _messages.push(msg); }
+
+private:
+
+ std::queue<SGSoundSample *> _messages;
+
+ bool last_pause;
+ double last_volume;
+
+ SGPropertyNode_ptr _pause;
+ SGPropertyNode_ptr _volume;
+};
+
+
+#endif
+
+// end of fg_fx.hxx