diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index 82512a7e4..8b3681c31 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -21,6 +21,8 @@ // $Id$ +#include + #include #include
#include @@ -29,6 +31,10 @@ #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 = morse.make_ident( nav1_ident ); + FGSimpleSound *sound; + sound = morse.make_ident( nav1_ident, LO_FREQUENCY ); sound->set_volume( 0.3 ); - globals->get_soundmgr()->add( sound, "nav1-ident" ); + globals->get_soundmgr()->add( sound, "nav1-vor-ident" ); + + if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) { + globals->get_soundmgr()->remove( "nav1-dme-ident" ); + } + sound = morse.make_ident( nav1_ident, HI_FREQUENCY ); + sound->set_volume( 0.3 ); + 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 = morse.make_ident( nav1_ident ); + FGSimpleSound *sound; + sound = morse.make_ident( nav1_ident, LO_FREQUENCY ); sound->set_volume( 0.3 ); - globals->get_soundmgr()->add( sound, "nav1-ident" ); + globals->get_soundmgr()->add( sound, "nav1-vor-ident" ); + + if ( globals->get_soundmgr()->exists( "nav1-dme-ident" ) ) { + globals->get_soundmgr()->remove( "nav1-dme-ident" ); + } + sound = morse.make_ident( nav1_ident, HI_FREQUENCY ); + sound->set_volume( 0.3 ); + 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; } diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index 4414b70b1..ae9509d88 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -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 ) ; diff --git a/src/Sound/morse.hxx b/src/Sound/morse.hxx index c17635ef9..658b54db9 100644 --- a/src/Sound/morse.hxx +++ b/src/Sound/morse.hxx @@ -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