]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/AIPlane.cxx
Merge branch 'torsten/metar'
[flightgear.git] / src / ATCDCL / AIPlane.cxx
index 5352c1c47d00324497dcbb71dc5290fd515f984d..8fd67d13aeb190b837706c8996e27c339f068b90 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#include <simgear/math/point3d.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <math.h>
@@ -48,6 +47,12 @@ FGAIPlane::FGAIPlane() {
        _trackSet = false;
        _tgtRoll = 0.0;
        _rollSuspended = false;
+
+       if ( !_sgr ) {
+               SGSoundMgr *smgr = globals->get_soundmgr();
+               _sgr = smgr->find("atc", true);
+                _sgr->tie_to_listener();
+       }
 }
 
 FGAIPlane::~FGAIPlane() {
@@ -106,7 +111,9 @@ void FGAIPlane::Update(double dt) {
                        if(1) {
                                // For now assume in range !!!
                                // TODO - implement range checking
-                               Render(plane.callsign, false);
+                               // TODO - at the moment the volume is always set off comm1 
+                               float volume = fgGetFloat("/instrumentation/comm[0]/volume");
+                               Render(plane.callsign, volume, false);
                        }
                }
                // Run the callback regardless of whether on same freq as user or not.
@@ -166,7 +173,10 @@ void FGAIPlane::ConditionalTransmit(double timeout, int callback_code) {
 }
 
 void FGAIPlane::ImmediateTransmit(int callback_code) {
-       Render(plane.callsign, false);
+       // TODO - at the moment the volume is always set off comm1 
+       float volume = fgGetFloat("/instrumentation/comm[0]/volume");
+
+       Render(plane.callsign, volume, false);
        if(callback_code) {
                ProcessCallback(callback_code);
        }
@@ -180,26 +190,19 @@ void FGAIPlane::ProcessCallback(int code) {
 // Outputs the transmission either on screen or as audio depending on user preference
 // The refname is a string to identify this sample to the sound manager
 // The repeating flag indicates whether the message should be repeated continuously or played once.
-void FGAIPlane::Render(const string& refname, bool repeating) {
+void FGAIPlane::Render(const string& refname, const float volume, bool repeating) {
        fgSetString("/sim/messages/ai-plane", pending_transmission.c_str());
 #ifdef ENABLE_AUDIO_SUPPORT
        voice = (voiceOK && fgGetBool("/sim/sound/voice"));
        if(voice) {
-               int len;
-               unsigned char* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), len, voice);
-               if(voice) {
-                       SGSoundSample* simple = new SGSoundSample(buf, len, 8000);
-                       // TODO - at the moment the volume is always set off comm1 
-                       // and can't be changed after the transmission has started.
-                       simple->set_volume(5.0 * fgGetDouble("/instrumentation/comm[0]/volume"));
-                       globals->get_soundmgr()->add(simple, refname);
-                       if(repeating) {
-                               globals->get_soundmgr()->play_looped(refname);
-                       } else {
-                               globals->get_soundmgr()->play_once(refname);
-                       }
-               }
-               delete[] buf;
+            size_t len;
+           void* buf = vPtr->WriteMessage(pending_transmission, &len);
+           if(voice && (volume > 0.05)) {
+               SGSoundSample* simple = new SGSoundSample(&buf, len, 8000 );
+               simple->set_volume(volume);
+               _sgr->add(simple, refname);
+               _sgr->play(refname, repeating);
+           }
        }
 #endif // ENABLE_AUDIO_SUPPORT
        if(!voice) {
@@ -219,8 +222,8 @@ void FGAIPlane::NoRender(const string& refname) {
        if(playing) {
                if(voice) {
 #ifdef ENABLE_AUDIO_SUPPORT            
-                       globals->get_soundmgr()->stop(refname);
-                       globals->get_soundmgr()->remove(refname);
+                       _sgr->stop(refname);
+                       _sgr->remove(refname);
 #endif
                }
                playing = false;