]> git.mxchange.org Git - flightgear.git/commitdiff
More work on morse code ...
authorcurt <curt>
Mon, 5 Mar 2001 14:11:25 +0000 (14:11 +0000)
committercurt <curt>
Mon, 5 Mar 2001 14:11:25 +0000 (14:11 +0000)
src/Main/main.cxx
src/Main/morse.cxx
src/Main/morse.hxx
src/Main/soundmgr.cxx

index 092e97d16adc58f750360326c32386ca988c11a1..9cd830f71b276398f6025441661ba9f88442e101 100644 (file)
@@ -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
index f6d1267a827374f752ab280a1bf2597022a0b651..ceaa23cfe6869f4646f922cc7ab38a3975f14b64 100644 (file)
@@ -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;
 }
index 9315c8164d6f5c7923c8ed742408f6ee2957122b..34426bd271eb1e4ecf591ad550700ea6c19b8481 100644 (file)
@@ -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 );
 };
 
 
index 653bdfb5a12075987387409fd89b546a0f94c4b0..2703698d3873983156f5bee2d1b374483603dd7f 100644 (file)
@@ -24,6 +24,7 @@
 // $Id$
 
 
+#include <simgear/debug/logstream.hxx>
 #include <simgear/misc/fgpath.hxx>
 
 #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