From: curt Date: Mon, 5 Mar 2001 14:11:25 +0000 (+0000) Subject: More work on morse code ... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fbad3482fa1b81dde3fdf435acf41ff8b22b6f0a;p=flightgear.git More work on morse code ... --- diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 092e97d16..9cd830f71 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -117,6 +117,7 @@ int objc=0; #include "fg_io.hxx" #include "globals.hxx" #include "keyboard.hxx" +#include "morse.hxx" #include "splash.hxx" #ifdef ENABLE_AUDIO_SUPPORT @@ -1191,8 +1192,11 @@ static void fgIdleFunction ( void ) { << " Bps = " << s1->get_sample()->getBps() << " Stereo = " << s1->get_sample()->getStereo() ); - s2 = new FGSimpleSound( "Sounds/corflaps.wav" ); - s2->set_volume( 2.0 ); + // s2 = new FGSimpleSound( "Sounds/corflaps.wav" ); + // s2->set_volume( 2.0 ); + FGMorse mmm; + mmm.init(); + s2 = mmm.make_ident( "JLI" ); globals->get_soundmgr()->add( s2, "flaps" ); } #endif diff --git a/src/Main/morse.cxx b/src/Main/morse.cxx index f6d1267a8..ceaa23cfe 100644 --- a/src/Main/morse.cxx +++ b/src/Main/morse.cxx @@ -38,7 +38,6 @@ bool FGMorse::init() { int i, j; // Make DIT - unsigned char dit[ DIT_SIZE ] ; for ( i = 0; i < TRANSITION_BYTES; ++i ) { float level = ( sin( (double) i * 2.0 * M_PI / (8000.0 / FREQUENCY)) ) * ((double)i / TRANSITION_BYTES) / 2.0 + 0.5; @@ -71,7 +70,6 @@ bool FGMorse::init() { } // Make DAH - unsigned char dah[ DAH_SIZE ] ; for ( i = 0; i < TRANSITION_BYTES; ++i ) { float level = ( sin( (double) i * 2.0 * M_PI / (8000.0 / FREQUENCY) ) ) * ((double)i / TRANSITION_BYTES) / 2.0 + 0.5; @@ -114,5 +112,56 @@ bool FGMorse::init() { // make a FGSimpleSound morse code transmission for the specified string -FGSimpleSound FGMorse::make_ident( const string& id ) { +FGSimpleSound *FGMorse::make_ident( const string& id ) { + char *idptr = (char *)id.c_str(); + + int length = 0; + int i, j; + + // 1. Determine byte length of message + for ( i = 0; i < (int)id.length(); ++i ) { + if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) { + char c = idptr[i] - 'A'; + for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) { + if ( alphabet[c][j] == DIT ) { + length += DIT_SIZE; + } else if ( alphabet[c][j] == DAH ) { + length += DAH_SIZE; + } + } + length += SPACE_SIZE; + } else { + // skip unknown character + } + } + + // 2. Allocate space for the message + unsigned char *buffer = new unsigned char[length]; + + // 3. Assemble the message; + unsigned char *bufptr = buffer; + + for ( i = 0; i < (int)id.length(); ++i ) { + if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) { + char c = idptr[i] - 'A'; + for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) { + if ( alphabet[c][j] == DIT ) { + memcpy( bufptr, dit, DIT_SIZE ); + bufptr += DIT_SIZE; + } else if ( alphabet[c][j] == DAH ) { + memcpy( bufptr, dah, DAH_SIZE ); + bufptr += DAH_SIZE; + } + } + memcpy( bufptr, space, SPACE_SIZE ); + bufptr += SPACE_SIZE; + } else { + // skip unknown character + } + } + + // 4. create the simple sound and return + FGSimpleSound *sample = new FGSimpleSound( buffer, length ); + + return sample; } diff --git a/src/Main/morse.hxx b/src/Main/morse.hxx index 9315c8164..34426bd27 100644 --- a/src/Main/morse.hxx +++ b/src/Main/morse.hxx @@ -91,7 +91,7 @@ static const char end = '0'; static const int BYTES_PER_SECOND = 8000; static const int BEAT_LENGTH = 240; // milleseconds (5 wpm) -static const int TRANSITION_BYTES = 40; +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 static const int DAH_SIZE = 4 * COUNT_SIZE; // 4 counts @@ -143,7 +143,7 @@ public: bool init(); // make a FGSimpleSound morse code transmission for the specified string - FGSimpleSound make_ident( const string& id ); + FGSimpleSound *make_ident( const string& id ); }; diff --git a/src/Main/soundmgr.cxx b/src/Main/soundmgr.cxx index 653bdfb5a..2703698d3 100644 --- a/src/Main/soundmgr.cxx +++ b/src/Main/soundmgr.cxx @@ -24,6 +24,7 @@ // $Id$ +#include #include #include "globals.hxx" @@ -61,6 +62,11 @@ FGSimpleSound::~FGSimpleSound() { FGSoundMgr::FGSoundMgr() { audio_sched = new slScheduler( 8000 ); audio_mixer = new smMixer; + + FG_LOG( FG_GENERAL, FG_INFO, + "Rate = " << audio_sched->getRate() + << " Bps = " << audio_sched->getBps() + << " Stereo = " << audio_sched->getStereo() ); } // destructor