]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/soundmanager.cxx
Interim windows build fix
[flightgear.git] / src / Sound / soundmanager.cxx
index 2a41ade13b61570f2a171514a04b9459fafc8877..bb1b83418bf07e252fe9604148e82ffe92d90b5f 100644 (file)
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/sound/soundmgr_openal.hxx>
 
+#if defined(ENABLE_FLITE)
+#include "VoiceSynthesizer.hxx"
+#endif
 #include "soundmanager.hxx"
 #include "Main/globals.hxx"
 #include "Main/fg_props.hxx"
@@ -47,10 +54,9 @@ void Listener::valueChanged(SGPropertyNode * node)
 
 FGSoundManager::FGSoundManager()
   : _is_initialized(false),
+    _enabled(false),
     _listener(new Listener(this))
 {
-    SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
-    scenery_loaded->addChangeListener(_listener);
 }
 
 FGSoundManager::~FGSoundManager()
@@ -64,18 +70,36 @@ void FGSoundManager::init()
     _volume        = fgGetNode("/sim/sound/volume");
     _device_name   = fgGetNode("/sim/sound/device-name");
 
-    _currentView = fgGetNode("sim/current-view");
-    _viewPosLon    = fgGetNode("sim/current-view/viewer-lon-deg");
-    _viewPosLat    = fgGetNode("sim/current-view/viewer-lat-deg");
-    _viewPosElev   = fgGetNode("sim/current-view/viewer-elev-ft");
+    _currentView   = fgGetNode("sim/current-view");
+
+    _viewX = _currentView->getNode("viewer-x-m", true);
+    _viewY = _currentView->getNode("viewer-y-m", true);
+    _viewZ = _currentView->getNode("viewer-z-m", true);
   
     _velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true);
-    _velocityEastFPS = fgGetNode("velocities/speed-east-fps", true);
-    _velocityDownFPS = fgGetNode("velocities/speed-down-fps", true);
+    _velocityEastFPS  = fgGetNode("velocities/speed-east-fps", true);
+    _velocityDownFPS  = fgGetNode("velocities/speed-down-fps", true);
   
+    _viewXoffset      = _currentView->getNode("x-offset-m", true);
+    _viewYoffset      = _currentView->getNode("y-offset-m", true);
+    _viewZoffset      = _currentView->getNode("z-offset-m", true);
+
+    SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
+    scenery_loaded->addChangeListener(_listener.get());
+
     reinit();
 }
 
+void FGSoundManager::shutdown()
+{
+    SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
+    scenery_loaded->removeChangeListener(_listener.get());
+    
+    stop();
+    
+    SGSoundMgr::shutdown();
+}
+
 void FGSoundManager::reinit()
 {
     _is_initialized = false;
@@ -122,13 +146,13 @@ void FGSoundManager::update_device_list()
     devices.clear();
 }
 
-bool FGSoundManager::stationary() const
+bool FGSoundManager::stationaryView() const
 {
   // this is an ugly hack to decide if the *viewer* is stationary,
   // since we don't model the viewer velocity directly.
-  return (_currentView->getDoubleValue("x-offset-m") == 0.0) &&
-         (_currentView->getDoubleValue("y-offset-m") == 0.0) &&
-         (_currentView->getDoubleValue("z-offset-m") == 0.0);
+  return (_viewXoffset->getDoubleValue() == 0.0) &&
+         (_viewYoffset->getDoubleValue() == 0.0) &&
+         (_viewZoffset->getDoubleValue() == 0.0);
 }
 
 // Update sound manager and propagate property values,
@@ -136,34 +160,58 @@ bool FGSoundManager::stationary() const
 // Actual sound update is triggered by the subsystem manager.
 void FGSoundManager::update(double dt)
 {
-    if (_is_initialized && _sound_working->getBoolValue() && _sound_enabled->getBoolValue())
+    if (_is_initialized && _sound_working->getBoolValue())
     {
-        SGGeod viewPosGeod(SGGeod::fromDegFt(_viewPosLon->getDoubleValue(),
-                                             _viewPosLat->getDoubleValue(),
-                                             _viewPosElev->getDoubleValue()));
-        SGVec3d cartPos = SGVec3d::fromGeod(viewPosGeod);
-        
-        set_position(cartPos, viewPosGeod);
-        
-        SGQuatd viewOrientation;
-        for (int i=0; i<4; ++i) {
-          viewOrientation[i] = _currentView->getChild("raw-orientation", i, true)->getDoubleValue();
+        bool enabled = _sound_enabled->getBoolValue();
+        if (enabled != _enabled)
+        {
+            if (enabled)
+                resume();
+            else
+                suspend();
+            _enabled = enabled;
         }
-        
-        set_orientation( viewOrientation );
-        
-        SGVec3d velocity(SGVec3d::zeros());
-        if (!stationary()) {
-          velocity = SGVec3d(_velocityNorthFPS->getDoubleValue(),
-                             _velocityEastFPS->getDoubleValue(),
-                             _velocityDownFPS->getDoubleValue() );
+        if (enabled)
+        {
+            SGVec3d cartPos(_viewX->getDoubleValue(),
+                            _viewY->getDoubleValue(),
+                            _viewZ->getDoubleValue());
+            SGGeod geodPos = SGGeod::fromCart(cartPos);
+
+            set_position(cartPos, geodPos);
+
+            SGQuatd viewOrientation;
+            for (int i=0; i<4; ++i) {
+              viewOrientation[i] = _currentView->getChild("raw-orientation", i, true)->getDoubleValue();
+            }
+
+            set_orientation( viewOrientation );
+
+            SGVec3d velocity(SGVec3d::zeros());
+            if (!stationaryView()) {
+              velocity = SGVec3d(_velocityNorthFPS->getDoubleValue(),
+                                 _velocityEastFPS->getDoubleValue(),
+                                 _velocityDownFPS->getDoubleValue() );
+            }
+
+            set_velocity( velocity );
+
+            set_volume(_volume->getFloatValue());
+            SGSoundMgr::update(dt);
         }
-        
-        set_velocity( velocity );
-      
-        set_volume(_volume->getFloatValue());
-        SGSoundMgr::update(dt);
     }
 }
 
+#if defined(ENABLE_FLITE)
+VoiceSynthesizer * FGSoundManager::getSynthesizer( const std::string & voice )
+{
+  std::map<std::string,VoiceSynthesizer*>::iterator it = _synthesizers.find(voice);
+  if( it == _synthesizers.end() ) {
+    VoiceSynthesizer * synthesizer = new FLITEVoiceSynthesizer( voice );
+    _synthesizers[voice] = synthesizer;
+    return synthesizer;
+  }
+  return it->second;
+}
+#endif
 #endif // ENABLE_AUDIO_SUPPORT