]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/audioident.cxx
Stop AI aircraft's sound when removing
[flightgear.git] / src / Sound / audioident.cxx
index 74674522c5d9a38cfac8a5740d574847094f1310..c205287f2e97720b7dbd64dfea75e6d95c936a2f 100644 (file)
 
 #include "audioident.hxx"
 #include <simgear/sg_inlines.h>
+#include <simgear/sound/sample_group.hxx>
 
 #include <Main/globals.hxx>
-#include <Sound/Morse.hxx>
+#include <Sound/morse.hxx>
 
 AudioIdent::AudioIdent( const std::string & fx_name, const double interval_secs, const int frequency_hz ) :
   _fx_name(fx_name),
@@ -70,7 +71,15 @@ void AudioIdent::setVolumeNorm( double volumeNorm )
 
 void AudioIdent::setIdent( const std::string & ident, double volumeNorm )
 {
-    if( _ident == ident ) {
+    // Signal may flicker very frequently (due to our realistic newnavradio...).
+    // Avoid recreating identical sound samples all the time, instead turn off
+    // volume when signal is lost, and save the most recent sample.
+    if (ident.empty())
+        volumeNorm = 0;
+
+    if(( _ident == ident )||
+       (volumeNorm == 0))  // don't bother with sounds when volume is OFF anyway...
+    {
         if( false == _ident.empty() )
             setVolumeNorm( volumeNorm );
         return;
@@ -88,6 +97,7 @@ void AudioIdent::setIdent( const std::string & ident, double volumeNorm )
             sound->set_volume( volumeNorm );
             if (!_sgr->add( sound, _fx_name )) {
                 SG_LOG(SG_SOUND, SG_WARN, "Failed to add sound '" << _fx_name << "' for ident '" << ident << "'" );
+                delete sound;
                 return;
             }
 
@@ -135,7 +145,12 @@ VORAudioIdent::VORAudioIdent( const std::string & fx_name )
 //FIXME: LOCAudioIdent at approx 7wpm (ICAO Annex 10 - 3.1.3.9.4)
 // not less than six times per minute at approx equal intervals
 // frequency 1020+/-50Hz (3.1.3.9.2)
+LOCAudioIdent::LOCAudioIdent( const std::string & fx_name )
+: AudioIdent( fx_name, 10, FGMorse::LO_FREQUENCY )
+{
+}
+
 
 // FIXME: NDBAudioIdent at approx 7 wpm (ICAO ANNEX 10 - 3.4.5.1)
 // at least once every 10s (3.4.5.2.1)
-// frequency 1020+/-50Hz or 400+/-25Hz (3.4.5.4)
\ No newline at end of file
+// frequency 1020+/-50Hz or 400+/-25Hz (3.4.5.4)