Create FGSoundManager as a wrapper for SGSoundMgr_OpenAl
and sink all sound related code from main.cxx in there.
This commit is contained in:
parent
043128c7c0
commit
7415696492
6 changed files with 208 additions and 80 deletions
|
@ -188,6 +188,8 @@ void FGATC::Render(string& msg, const float volume,
|
||||||
{
|
{
|
||||||
NoRender(refname);
|
NoRender(refname);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
bool useVoice = false;
|
||||||
#endif // ENABLE_AUDIO_SUPPORT
|
#endif // ENABLE_AUDIO_SUPPORT
|
||||||
|
|
||||||
if (!useVoice)
|
if (!useVoice)
|
||||||
|
|
|
@ -60,7 +60,6 @@
|
||||||
#include <simgear/misc/interpolator.hxx>
|
#include <simgear/misc/interpolator.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/model/particles.hxx>
|
#include <simgear/scene/model/particles.hxx>
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
|
||||||
|
|
||||||
#include <Aircraft/controls.hxx>
|
#include <Aircraft/controls.hxx>
|
||||||
#include <Aircraft/replay.hxx>
|
#include <Aircraft/replay.hxx>
|
||||||
|
@ -98,6 +97,7 @@
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
#include <Scripting/NasalSys.hxx>
|
#include <Scripting/NasalSys.hxx>
|
||||||
#include <Sound/voice.hxx>
|
#include <Sound/voice.hxx>
|
||||||
|
#include <Sound/soundmanager.hxx>
|
||||||
#include <Systems/system_mgr.hxx>
|
#include <Systems/system_mgr.hxx>
|
||||||
#include <Time/light.hxx>
|
#include <Time/light.hxx>
|
||||||
#include <Traffic/TrafficMgr.hxx>
|
#include <Traffic/TrafficMgr.hxx>
|
||||||
|
@ -1062,7 +1062,7 @@ bool fgInitSubsystems() {
|
||||||
// to be updated in every loop.
|
// to be updated in every loop.
|
||||||
// Sound manager is updated last so it can use the CPU while the GPU
|
// 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-
|
// 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.
|
// Initialize the event manager subsystem.
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
#include <simgear/magvar/magvar.hxx>
|
#include <simgear/magvar/magvar.hxx>
|
||||||
#include <simgear/io/raw_socket.hxx>
|
#include <simgear/io/raw_socket.hxx>
|
||||||
#include <simgear/scene/tsync/terrasync.hxx>
|
#include <simgear/scene/tsync/terrasync.hxx>
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
|
||||||
#include <simgear/math/SGMath.hxx>
|
#include <simgear/math/SGMath.hxx>
|
||||||
#include <simgear/math/sg_random.h>
|
#include <simgear/math/sg_random.h>
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@
|
||||||
#include <Model/panelnode.hxx>
|
#include <Model/panelnode.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
#include <Sound/fg_fx.hxx>
|
#include <Sound/soundmanager.hxx>
|
||||||
#include <Time/TimeManager.hxx>
|
#include <Time/TimeManager.hxx>
|
||||||
#include <GUI/gui.h>
|
#include <GUI/gui.h>
|
||||||
#include <Viewer/CameraGroup.hxx>
|
#include <Viewer/CameraGroup.hxx>
|
||||||
|
@ -86,72 +85,6 @@ int idle_state = 0;
|
||||||
extern int _bootstrap_OSInit;
|
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 void fgLoadInitialScenery()
|
||||||
{
|
{
|
||||||
static SGPropertyNode_ptr scenery_loaded
|
static SGPropertyNode_ptr scenery_loaded
|
||||||
|
@ -163,11 +96,6 @@ static void fgLoadInitialScenery()
|
||||||
&& fgGetBool("sim/fdm-initialized")) {
|
&& fgGetBool("sim/fdm-initialized")) {
|
||||||
fgSetBool("sim/sceneryloaded",true);
|
fgSetBool("sim/sceneryloaded",true);
|
||||||
fgSplashProgress("");
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -200,10 +128,6 @@ static void fgMainLoop( void )
|
||||||
globals->get_mag()->update( globals->get_aircraft_position(),
|
globals->get_mag()->update( globals->get_aircraft_position(),
|
||||||
globals->get_time_params()->getJD() );
|
globals->get_time_params()->getJD() );
|
||||||
|
|
||||||
// Propagate sound manager properties (note: actual update is triggered
|
|
||||||
// by the subsystem manager).
|
|
||||||
fgUpdateSound(sim_dt);
|
|
||||||
|
|
||||||
// update all subsystems
|
// update all subsystems
|
||||||
globals->get_subsystem_mgr()->update(sim_dt);
|
globals->get_subsystem_mgr()->update(sim_dt);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ set(SOURCES
|
||||||
sample_queue.cxx
|
sample_queue.cxx
|
||||||
voice.cxx
|
voice.cxx
|
||||||
voiceplayer.cxx
|
voiceplayer.cxx
|
||||||
|
soundmanager.cxx
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
|
@ -20,6 +21,7 @@ set(HEADERS
|
||||||
sample_queue.hxx
|
sample_queue.hxx
|
||||||
voice.hxx
|
voice.hxx
|
||||||
voiceplayer.hxx
|
voiceplayer.hxx
|
||||||
|
soundmanager.hxx
|
||||||
)
|
)
|
||||||
|
|
||||||
flightgear_component(Sound "${SOURCES}" "${HEADERS}")
|
flightgear_component(Sound "${SOURCES}" "${HEADERS}")
|
||||||
|
|
131
src/Sound/soundmanager.cxx
Normal file
131
src/Sound/soundmanager.cxx
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
// 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
|
69
src/Sound/soundmanager.hxx
Normal file
69
src/Sound/soundmanager.hxx
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
// 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
|
Loading…
Add table
Reference in a new issue