]> git.mxchange.org Git - flightgear.git/commitdiff
Play the full 4x VOR and 1x DME morse ident sequence at 30 second intervals.
authorcurt <curt>
Fri, 9 Mar 2001 23:35:21 +0000 (23:35 +0000)
committercurt <curt>
Fri, 9 Mar 2001 23:35:21 +0000 (23:35 +0000)
When you tune into a station start at a "random" point in the sequence.
Sped up the words per minute to 13 to which means one sequence per about 4 secs.
This means we get through the whole sequence in about 20 seconds leaving 10
seconds of silence.

src/Cockpit/radiostack.cxx
src/Sound/morse.cxx
src/Sound/morse.hxx

index 82512a7e423170627d248b75ebb9d0a46f14fd32..8b3681c3144c12ab17f8c5579b0945063a8b2997 100644 (file)
@@ -21,6 +21,8 @@
 // $Id$
 
 
+#include <simgear/math/sg_random.h>
+
 #include <Aircraft/aircraft.hxx>
 #include <Main/bfi.hxx>
 #include <Navaids/ilslist.hxx>
 
 #include "radiostack.hxx"
 
+static int nav1_play_count = 0;
+static time_t nav1_last_time = 0;
+
+
 /**
  * Boy, this is ugly!  Make the VOR range vary by altitude difference.
  */
@@ -257,16 +263,34 @@ FGRadioStack::update()
        // play station ident via audio system if on + ident,
        // otherwise turn it off
        if ( nav1_on_btn && nav1_ident_btn ) {
-           if ( ! globals->get_soundmgr()->is_playing( "nav1-ident" ) ) {
-               globals->get_soundmgr()->play_once( "nav1-ident" );
+           if ( nav1_last_time <
+                globals->get_time_params()->get_cur_time() - 30 ) {
+               nav1_last_time = globals->get_time_params()->get_cur_time();
+               nav1_play_count = 0;
+           }
+           if ( nav1_play_count < 4 ) {
+               // play VOR ident
+               if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") ) {
+                   globals->get_soundmgr()->play_once( "nav1-vor-ident" );
+                   ++nav1_play_count;
+               }
+           } else if ( nav1_play_count < 5 ) {
+               // play DME ident
+               if ( !globals->get_soundmgr()->is_playing("nav1-vor-ident") &&
+                    !globals->get_soundmgr()->is_playing("nav1-dme-ident") ) {
+                   globals->get_soundmgr()->play_once( "nav1-dme-ident" );
+                   ++nav1_play_count;
+               }
            }
        } else {
-           globals->get_soundmgr()->stop( "nav1-ident" );
+           globals->get_soundmgr()->stop( "nav1-vor-ident" );
+           globals->get_soundmgr()->stop( "nav1-dme-ident" );
        }
     } else {
        nav1_inrange = false;
        nav1_dme_dist = 0.0;
-       globals->get_soundmgr()->stop( "nav1-ident" );
+       globals->get_soundmgr()->stop( "nav1-vor-ident" );
+       globals->get_soundmgr()->stop( "nav1-dme-ident" );
        // cout << "not picking up vor. :-(" << endl;
     }
 
@@ -385,12 +409,28 @@ void FGRadioStack::search()
            nav1_dme_y = ils.get_dme_y();
            nav1_dme_z = ils.get_dme_z();
 
-           if ( globals->get_soundmgr()->exists( "nav1-ident" ) ) {
-               globals->get_soundmgr()->remove( "nav1-ident" );
+           if ( globals->get_soundmgr()->exists( "nav1-vor-ident" ) ) {
+               globals->get_soundmgr()->remove( "nav1-vor-ident" );
+           }
+           FGSimpleSound *sound;
+           sound = morse.make_ident( nav1_ident, LO_FREQUENCY );
+           sound->set_volume( 0.3 );
+           globals->get_soundmgr()->add( sound, "nav1-vor-ident" );
+
+           if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) {
+               globals->get_soundmgr()->remove( "nav1-dme-ident" );
            }
-           FGSimpleSound *sound = morse.make_ident( nav1_ident );
+           sound = morse.make_ident( nav1_ident, HI_FREQUENCY );
            sound->set_volume( 0.3 );
-           globals->get_soundmgr()->add( sound, "nav1-ident" );
+           globals->get_soundmgr()->add( sound, "nav1-dme-ident" );
+
+           int offset = (int)(sg_random() * 30.0);
+           nav1_play_count = offset / 4;
+           nav1_last_time = globals->get_time_params()->get_cur_time() -
+               offset;
+           cout << "offset = " << offset << " play_count = " << nav1_play_count
+                << " nav1_last_time = " << nav1_last_time << " current time = "
+                << globals->get_time_params()->get_cur_time() << endl;
 
            // cout << "Found an ils station in range" << endl;
            // cout << " id = " << ils.get_locident() << endl;
@@ -415,12 +455,28 @@ void FGRadioStack::search()
            nav1_y = nav1_dme_y = nav.get_y();
            nav1_z = nav1_dme_z = nav.get_z();
 
-           if ( globals->get_soundmgr()->exists( "nav1-ident" ) ) {
-               globals->get_soundmgr()->remove( "nav1-ident" );
+           if ( globals->get_soundmgr()->exists( "nav1-vor-ident" ) ) {
+               globals->get_soundmgr()->remove( "nav1-vor-ident" );
+           }
+           FGSimpleSound *sound;
+           sound = morse.make_ident( nav1_ident, LO_FREQUENCY );
+           sound->set_volume( 0.3 );
+           globals->get_soundmgr()->add( sound, "nav1-vor-ident" );
+
+           if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) {
+               globals->get_soundmgr()->remove( "nav1-dme-ident" );
            }
-           FGSimpleSound *sound = morse.make_ident( nav1_ident );
+           sound = morse.make_ident( nav1_ident, HI_FREQUENCY );
            sound->set_volume( 0.3 );
-           globals->get_soundmgr()->add( sound, "nav1-ident" );
+           globals->get_soundmgr()->add( sound, "nav1-dme-ident" );
+
+           int offset = (int)(sg_random() * 30.0);
+           nav1_play_count = offset / 4;
+           nav1_last_time = globals->get_time_params()->get_cur_time() -
+               offset;
+           cout << "offset = " << offset << " play_count = " << nav1_play_count
+                << " nav1_last_time = " << nav1_last_time << " current time = "
+                << globals->get_time_params()->get_cur_time() << endl;
 
            // cout << "Found a vor station in range" << endl;
            // cout << " id = " << nav.get_ident() << endl;
@@ -430,7 +486,8 @@ void FGRadioStack::search()
        nav1_ident = "";
        nav1_radial = 0;
        nav1_dme_dist = 0;
-       globals->get_soundmgr()->remove( "nav1-ident" );
+       globals->get_soundmgr()->remove( "nav1-vor-ident" );
+       globals->get_soundmgr()->remove( "nav1-dme-ident" );
        // cout << "not picking up vor1. :-(" << endl;
     }
 
index 4414b70b1bbef90927abc9ba47c3725a0e3a8ae2..ae9509d88a86a43e75408afe2ae558879d66be2d 100644 (file)
@@ -174,6 +174,42 @@ bool FGMorse::init() {
        lo_dah[ i ] = (unsigned char) ( 0.5 * 255.0 ) ;
     }
 
+    // Make High DAH
+    for ( i = 0; i < TRANSITION_BYTES; ++i ) {
+       float level = ( sin( (double) i * 2.0 * M_PI
+                            / (8000.0 / HI_FREQUENCY) ) )
+           * ((double)i / TRANSITION_BYTES) / 2.0 + 0.5;
+
+       /* Convert to unsigned byte */
+       hi_dah[ i ] = (unsigned char) ( level * 255.0 ) ;
+    }
+
+    for ( i = TRANSITION_BYTES;
+         i < DAH_SIZE - TRANSITION_BYTES - COUNT_SIZE;
+         ++i ) {
+       float level = ( sin( (double) i * 2.0 * M_PI
+                            / (8000.0 / HI_FREQUENCY) ) )
+           / 2.0 + 0.5;
+
+       /* Convert to unsigned byte */
+       hi_dah[ i ] = (unsigned char) ( level * 255.0 ) ;
+    }
+    j = TRANSITION_BYTES;
+    for ( int i = DAH_SIZE - TRANSITION_BYTES - COUNT_SIZE;
+         i < DAH_SIZE - COUNT_SIZE;
+         ++i ) {
+       float level = ( sin( (double) i * 2.0 * M_PI
+                            / (8000.0 / HI_FREQUENCY) ) )
+           * ((double)j / TRANSITION_BYTES) / 2.0 + 0.5;
+       --j;
+
+       /* Convert to unsigned byte */
+       hi_dah[ i ] = (unsigned char) ( level * 255.0 ) ;
+    }
+    for ( int i = DAH_SIZE - COUNT_SIZE; i < DAH_SIZE; ++i ) {
+       hi_dah[ i ] = (unsigned char) ( 0.5 * 255.0 ) ;
+    }
+
     // Make SPACE
     for ( int i = 0; i < SPACE_SIZE; ++i ) {
        space[ i ] = (unsigned char) ( 0.5 * 255 ) ;
index c17635ef91fc7f377717f75e79f783d36cfe4079..658b54db9edf310f6c2e9dbd73c10315f8647ad7 100644 (file)
@@ -90,8 +90,8 @@ static const char DAH = '2';
 static const char end = '0';
 
 static const int BYTES_PER_SECOND = 8000;
-static const int BEAT_LENGTH = 240; // milleseconds (5 wpm)
-// static const int BEAT_LENGTH = 92;  // milleseconds (13 wpm)
+// static const int BEAT_LENGTH = 240; // milleseconds (5 wpm)
+static const int BEAT_LENGTH = 92;  // milleseconds (13 wpm)
 static const int TRANSITION_BYTES = (int)(0.005 * BYTES_PER_SECOND);
 static const int COUNT_SIZE = BYTES_PER_SECOND * BEAT_LENGTH / 1000;
 static const int DIT_SIZE = 2 * COUNT_SIZE;   // 2 counts