]> git.mxchange.org Git - flightgear.git/commitdiff
Melchior FRANZ:
authorehofman <ehofman>
Thu, 19 Aug 2004 11:54:57 +0000 (11:54 +0000)
committerehofman <ehofman>
Thu, 19 Aug 2004 11:54:57 +0000 (11:54 +0000)
All necessary elements for an ADF gauge had been migrated from
Cockpit/kr_87.cxx to Instrumentation/adf.cxx. Migrating the sound
related elements was apparently planned, but not done yet. This
intermediate state broke the ident morse sound: it couldn't get
turned off and it always indicated "SF", regardless of the tuned-in
frequency. The following patches continue the migration:

adf-radio.diff     => Base/Aircraft/Instruments/adf-radio.xml:
---------------------------------------------------------------
* sets maximum volume to 1 (rather than 2); Not only is 1
  loud enough (and 2 unpleasantly noisy), it also prevents
  the knob from being turned to non-existant positions.  :-)
* fixes wrong use of /instrumentation/adf/ident
* the voice/ident selector(?) remains unchanged, but as it's
  not switched to "IDENT", there'll be no ident sound by default
  this is consistent with other sounds and DME.

radiostack.diff    => src/Cockpit/radiostack.[ch]xx:
---------------------------------------------------------------
* comment out use of FGKR_87 class. kr_87.[ch]xx is now no
  longer used. kr-87adf.xml would no longer work, either, but
  isn't used anywhere, anyway. Future adf radios have to use
  the adf instrument, using xml/Nasal for specific hardware
  implementation details.

adf.diff           => src/Instrumentation/adf.[ch]xx:
---------------------------------------------------------------
* adds ident morse sound capability using two new input
  properties:
  - /instrumentation/adf/volume-norm  (double)
  - /instrumentation/adf/ident-audible  (bool)

src/Cockpit/radiostack.cxx
src/Cockpit/radiostack.hxx
src/Instrumentation/adf.cxx
src/Instrumentation/adf.hxx

index 880906dfae9fe923d12354452f7fc47542319e22..fac5c2f1717d316165b0d6ecc9426ada87cdb38d 100644 (file)
@@ -50,7 +50,7 @@ FGRadioStack::FGRadioStack() {
 // Destructor
 FGRadioStack::~FGRadioStack() 
 {
-    adf.unbind();
+    //adf.unbind();
     beacon.unbind();
     navcom1.unbind();
     navcom2.unbind();
@@ -67,7 +67,7 @@ FGRadioStack::init ()
     navcom2.set_bind_index( 1 );
     navcom2.init();
 
-    adf.init();
+    //adf.init();
     beacon.init();
     xponder.init();
 
@@ -83,7 +83,7 @@ FGRadioStack::init ()
 void
 FGRadioStack::bind ()
 {
-    adf.bind();
+    //adf.bind();
     beacon.bind();
     dme.bind();
     navcom1.set_bind_index( 0 );
@@ -97,7 +97,7 @@ FGRadioStack::bind ()
 void
 FGRadioStack::unbind ()
 {
-    adf.unbind();
+    //adf.unbind();
     beacon.unbind();
     dme.unbind();
     navcom1.unbind();
@@ -110,7 +110,7 @@ FGRadioStack::unbind ()
 void 
 FGRadioStack::update(double dt) 
 {
-    adf.update( dt );
+    //adf.update( dt );
     beacon.update( dt );
     navcom1.update( dt );
     navcom2.update( dt );
@@ -122,7 +122,7 @@ FGRadioStack::update(double dt)
 // Update current nav/adf radio stations based on current postition
 void FGRadioStack::search() 
 {
-    adf.search();
+    //adf.search();
     beacon.search();
     navcom1.search();
     navcom2.search();
index dc6664e00ce95c72f39324c8d55a589e843c1253..1b7ed9c1c89e12829daf84837e5ed458954b0b31 100644 (file)
@@ -46,7 +46,7 @@
 class FGRadioStack : public SGSubsystem
 {
     FGDME dme;
-    FGKR_87 adf;                // King KR 87 Digital ADF model
+    //FGKR_87 adf;                // King KR 87 Digital ADF model
     FGKT_70 xponder;            // Bendix/King KT 70 Panel-Mounted Transponder
     FGMarkerBeacon beacon;
     FGNavCom navcom1;
index 85b18b92dd5b4ae51a418cd165127c8001b07d00..0d666ec872f730bec3c13524ca3a74ebdbcaff61 100644 (file)
@@ -53,7 +53,10 @@ ADF::ADF ()
       _last_frequency_khz(-1),
       _transmitter_valid(false),
       _transmitter_elevation_ft(0),
-      _transmitter_range_nm(0)
+      _transmitter_range_nm(0),
+      _ident_count(0),
+      _last_ident_time(0),
+      _last_volume(-1)
 {
 }
 
@@ -79,6 +82,9 @@ ADF::init ()
     _bearing_node =
         fgGetNode("/instrumentation/adf/indicated-bearing-deg", true);
     _ident_node = fgGetNode("/instrumentation/adf/ident", true);
+    _volume_node = fgGetNode("/instrumentation/adf/volume-norm", true);
+    _ident_audible = fgGetNode("/instrumentation/adf/ident-audible", true);
+    morse.init();
 }
 
 void
@@ -146,10 +152,42 @@ ADF::update (double delta_time_sec)
         if (bearing < 0)
             bearing += 360;
         set_bearing(delta_time_sec, bearing);
+
+        // adf ident sound
+        double volume;
+        if ( _ident_audible->getBoolValue() )
+            volume = _volume_node->getDoubleValue();
+        else
+            volume = 0.0;
+
+        if ( volume != _last_volume ) {
+            _last_volume = volume;
+
+            SGSoundSample *sound;
+            sound = globals->get_soundmgr()->find( "adf-ident" );
+            if ( sound != NULL )
+                sound->set_volume( volume );
+            else
+                SG_LOG( SG_GENERAL, SG_ALERT, "Can't find adf-ident sound" );
+        }
+
+        double cur_time = globals->get_time_params()->get_cur_time();
+        if ( _last_ident_time < cur_time - 30 ) {
+            _last_ident_time = cur_time;
+            _ident_count = 0;
+        }
+
+        if ( _ident_count < 4 ) {
+            if ( !globals->get_soundmgr()->is_playing("adf-ident") ) {
+                globals->get_soundmgr()->play_once( "adf-ident" );
+                ++_ident_count;
+            }
+        }
     } else {
         _in_range_node->setBoolValue(false);
         set_bearing(delta_time_sec, 90);
         _ident_node->setStringValue("");
+        globals->get_soundmgr()->stop( "adf-ident" );
     }
 }
 
@@ -158,7 +196,6 @@ ADF::search (double frequency_khz, double longitude_rad,
              double latitude_rad, double altitude_m)
 {
     string ident = "";
-
                                 // reset search time
     _time_before_search_sec = 1.0;
 
@@ -178,8 +215,27 @@ ADF::search (double frequency_khz, double longitude_rad,
             _transmitter_range_nm = nav->get_range();
         }
     }
-    _last_ident = ident;
-    _ident_node->setStringValue(ident.c_str());
+
+    if ( _last_ident != ident ) {
+        _last_ident = ident;
+        _ident_node->setStringValue(ident.c_str());
+
+        if ( globals->get_soundmgr()->exists( "adf-ident" ) ) {
+            globals->get_soundmgr()->stop( "adf-ident" );
+            globals->get_soundmgr()->remove( "adf-ident" );
+        }
+
+        SGSoundSample *sound;
+        sound = morse.make_ident( ident, LO_FREQUENCY );
+        sound->set_volume(0);
+        _last_volume = -1;
+        globals->get_soundmgr()->add( sound, "adf-ident" );
+
+        int offset = (int)(sg_random() * 30.0);
+        _ident_count = offset / 4;
+        _last_ident_time = globals->get_time_params()->get_cur_time() -
+            offset;
+    }
 }
 
 void
index fa17234f23a9342792c98ca1553e6da3f411adc9..6b8b306aa27575d5d94cea050716667086a45702 100644 (file)
@@ -17,6 +17,7 @@
 #include <simgear/props/props.hxx>
 
 #include <simgear/structure/subsystem_mgr.hxx>
+#include <Sound/morse.hxx>
 
 SG_USING_STD(string);
 
@@ -35,6 +36,8 @@ SG_USING_STD(string);
  * /instrumentation/adf/error-deg
  * /instrumentation/adf/frequencies/selected-khz
  * /instrumentation/adf/mode
+ * /instrumentation/adf/ident-audible
+ * /instrumentation/adf/volume-norm
  *
  * Output properties:
  *
@@ -73,6 +76,13 @@ private:
     SGPropertyNode_ptr _in_range_node;
     SGPropertyNode_ptr _bearing_node;
     SGPropertyNode_ptr _ident_node;
+    SGPropertyNode_ptr _ident_audible;
+    SGPropertyNode_ptr _volume_node;
+
+    FGMorse morse;
+    int _ident_count;
+    time_t _last_ident_time;
+    double _last_volume;
 
     double _time_before_search_sec;