and sink all sound related code from main.cxx in there.
{
NoRender(refname);
}
+#else
+ bool useVoice = false;
#endif // ENABLE_AUDIO_SUPPORT
if (!useVoice)
#include <simgear/misc/interpolator.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/model/particles.hxx>
-#include <simgear/sound/soundmgr_openal.hxx>
#include <Aircraft/controls.hxx>
#include <Aircraft/replay.hxx>
#include <Scenery/tilemgr.hxx>
#include <Scripting/NasalSys.hxx>
#include <Sound/voice.hxx>
+#include <Sound/soundmanager.hxx>
#include <Systems/system_mgr.hxx>
#include <Time/light.hxx>
#include <Traffic/TrafficMgr.hxx>
// to be updated in every loop.
// Sound manager is updated last so it can use the CPU while the GPU
// is processing the scenery (doubled the frame-rate for me) -EMH-
- globals->add_subsystem("sound", new SGSoundMgr, SGSubsystemMgr::SOUND);
+ globals->add_subsystem("sound", new FGSoundManager, SGSubsystemMgr::SOUND);
////////////////////////////////////////////////////////////////////
// Initialize the event manager subsystem.
#include <simgear/magvar/magvar.hxx>
#include <simgear/io/raw_socket.hxx>
#include <simgear/scene/tsync/terrasync.hxx>
-#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/math/SGMath.hxx>
#include <simgear/math/sg_random.h>
#include <Model/panelnode.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
-#include <Sound/fg_fx.hxx>
+#include <Sound/soundmanager.hxx>
#include <Time/TimeManager.hxx>
#include <GUI/gui.h>
#include <Viewer/CameraGroup.hxx>
extern int _bootstrap_OSInit;
-void fgInitSoundManager()
-{
- SGSoundMgr *smgr = globals->get_soundmgr();
-
- smgr->bind();
- smgr->init(fgGetString("/sim/sound/device-name", NULL));
-
- vector <const char*>devices = smgr->get_available_devices();
- for (unsigned int i=0; i<devices.size(); i++) {
- SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true);
- p->setStringValue(devices[i]);
- }
- devices.clear();
-}
-
-void fgSetNewSoundDevice(const char *device)
-{
- SGSoundMgr *smgr = globals->get_soundmgr();
- smgr->suspend();
- smgr->stop();
- smgr->init(device);
- smgr->resume();
-}
-
-// Update sound manager state (init/suspend/resume) and propagate property values,
-// since the sound manager doesn't read any properties itself.
-// Actual sound update is triggered by the subsystem manager.
-static void fgUpdateSound(double dt)
-{
-#ifdef ENABLE_AUDIO_SUPPORT
- static bool smgr_init = true;
- static SGPropertyNode *sound_working = fgGetNode("/sim/sound/working");
- if (smgr_init == true) {
- if (sound_working->getBoolValue() == true) {
- fgInitSoundManager();
- smgr_init = false;
- }
- } else {
- static SGPropertyNode *sound_enabled = fgGetNode("/sim/sound/enabled");
- static SGSoundMgr *smgr = globals->get_soundmgr();
- static bool smgr_enabled = true;
-
- if (sound_working->getBoolValue() == false) { // request to reinit
- smgr->reinit();
- smgr->resume();
- sound_working->setBoolValue(true);
- }
-
- if (smgr_enabled != sound_enabled->getBoolValue()) {
- if (smgr_enabled == true) { // request to suspend
- smgr->suspend();
- smgr_enabled = false;
- } else {
- smgr->resume();
- smgr_enabled = true;
- }
- }
-
- if (smgr_enabled == true) {
- static SGPropertyNode *volume = fgGetNode("/sim/sound/volume");
- smgr->set_volume(volume->getFloatValue());
- }
- }
-#endif
-}
-
static void fgLoadInitialScenery()
{
static SGPropertyNode_ptr scenery_loaded
&& fgGetBool("sim/fdm-initialized")) {
fgSetBool("sim/sceneryloaded",true);
fgSplashProgress("");
- if (fgGetBool("/sim/sound/working")) {
- globals->get_soundmgr()->activate();
- }
- globals->get_props()->tie("/sim/sound/devices/name",
- SGRawValueFunctions<const char *>(0, fgSetNewSoundDevice), false);
}
else
{
globals->get_mag()->update( globals->get_aircraft_position(),
globals->get_time_params()->getJD() );
- // Propagate sound manager properties (note: actual update is triggered
- // by the subsystem manager).
- fgUpdateSound(sim_dt);
-
// update all subsystems
globals->get_subsystem_mgr()->update(sim_dt);
sample_queue.cxx
voice.cxx
voiceplayer.cxx
+ soundmanager.cxx
)
set(HEADERS
sample_queue.hxx
voice.hxx
voiceplayer.hxx
+ soundmanager.hxx
)
-
+
flightgear_component(Sound "${SOURCES}" "${HEADERS}")
--- /dev/null
+// soundmanager.cxx -- Wraps the SimGear OpenAl sound manager class
+//
+// 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.
+//
+
+#include <simgear/sound/soundmgr_openal.hxx>
+
+#include "soundmanager.hxx"
+#include "Main/globals.hxx"
+#include "Main/fg_props.hxx"
+
+#include <vector>
+#include <string>
+
+#ifdef ENABLE_AUDIO_SUPPORT
+/**
+ * Listener class that monitors the sim state.
+ */
+class Listener : public SGPropertyChangeListener
+{
+public:
+ Listener(FGSoundManager *wrapper) : _wrapper(wrapper) {}
+ virtual void valueChanged (SGPropertyNode * node);
+
+private:
+ FGSoundManager * _wrapper;
+};
+
+void Listener::valueChanged(SGPropertyNode * node)
+{
+ _wrapper->activate(node->getBoolValue());
+}
+
+FGSoundManager::FGSoundManager()
+ : _is_initialized(false),
+ _listener(new Listener(this))
+{
+ SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
+ scenery_loaded->addChangeListener(_listener);
+}
+
+FGSoundManager::~FGSoundManager()
+{
+}
+
+
+void FGSoundManager::setNewSoundDevice(const char *device)
+{
+ SGSoundMgr *smgr = globals->get_soundmgr();
+ smgr->suspend();
+ smgr->stop();
+ smgr->init(device);
+ smgr->resume();
+}
+
+void FGSoundManager::init()
+{
+ globals->get_props()->tie("/sim/sound/devices/name",
+ SGRawValueFunctions<const char *>(0, FGSoundManager::setNewSoundDevice), false);
+}
+
+void FGSoundManager::bind()
+{
+ _sound_working = fgGetNode("/sim/sound/working");
+ _sound_enabled = fgGetNode("/sim/sound/enabled");
+ _volume = fgGetNode("/sim/sound/volume");
+
+ // we intentionally do _not_ call SGSoundMgr::bind here, we'll do this later
+}
+
+void FGSoundManager::activate(bool State)
+{
+ if (_is_initialized &&
+ fgGetBool("/sim/sound/working"))
+ {
+ if (State)
+ SGSoundMgr::activate();
+ }
+}
+
+void FGSoundManager::runtime_init()
+{
+ SGSoundMgr::bind();
+ SGSoundMgr::init(fgGetString("/sim/sound/device-name", NULL));
+
+ std::vector <const char*>devices = get_available_devices();
+ for (unsigned int i=0; i<devices.size(); i++) {
+ SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true);
+ p->setStringValue(devices[i]);
+ }
+ devices.clear();
+}
+
+// Update sound manager and propagate property values,
+// since the sound manager doesn't read any properties itself.
+// Actual sound update is triggered by the subsystem manager.
+void FGSoundManager::update(double dt)
+{
+ if (!_is_initialized) {
+ if (_sound_working->getBoolValue()) {
+ runtime_init();
+ _is_initialized = true;
+ }
+ } else {
+ if (!_sound_working->getBoolValue()) { // request to reinit
+ SGSoundMgr::reinit();
+ _sound_working->setBoolValue(true);
+ }
+
+ if (_sound_enabled->getBoolValue()) {
+ set_volume(_volume->getFloatValue());
+ SGSoundMgr::update(dt);
+ }
+ }
+}
+
+#endif // ENABLE_AUDIO_SUPPORT
--- /dev/null
+// soundmanager.hxx -- Wraps the SimGear OpenAl sound manager class
+//
+// 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.
+//
+
+#ifndef __FG_SOUNDMGR_HXX
+#define __FG_SOUNDMGR_HXX 1
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <simgear/props/props.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
+
+class SGSoundMgr;
+class Listener;
+
+#ifdef ENABLE_AUDIO_SUPPORT
+class FGSoundManager : public SGSoundMgr
+{
+public:
+ FGSoundManager();
+ ~FGSoundManager();
+
+ void init(void);
+ void bind(void);
+ void update(double dt);
+
+ void runtime_init(void);
+ void activate(bool State);
+
+ static void setNewSoundDevice(const char *device);
+
+private:
+ bool _is_initialized;
+ SGPropertyNode_ptr _sound_working, _sound_enabled, _volume;
+ Listener* _listener;
+};
+#else
+
+// provide a dummy sound class
+class FGSoundManager : public SGSubsystem
+{
+public:
+ FGSoundManager() {}
+ ~FGSoundManager() {}
+
+ void update(double dt) {}
+};
+
+#endif // ENABLE_AUDIO_SUPPORT
+
+#endif // __FG_SOUNDMGR_HXX