]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/morse.cxx
Set a rapid fall off rate for interior cockpit sounds so they won't be heard
[flightgear.git] / src / Sound / morse.cxx
index 507cf54eb0f858ca8128cd79d0e506d973d2156e..d2f9fc639017125413642faf26147a3d0f2d87e4 100644 (file)
@@ -55,6 +55,19 @@ static const char alphabet[26][4] = {
     { DA, DA, DI, DIT }                /* Z */ 
 };
 
+static const char numerals[10][5] = {
+    { DA, DA, DA, DA, DAH },    // 0
+    { DI, DA, DA, DA, DAH },    // 1
+    { DI, DI, DA, DA, DAH },    // 2
+    { DI, DI, DI, DA, DAH },    // 3
+    { DI, DI, DI, DI, DAH },    // 4
+    { DI, DI, DI, DI, DIT },    // 5
+    { DA, DI, DI, DI, DIT },    // 6
+    { DA, DA, DI, DI, DIT },    // 7
+    { DA, DA, DA, DI, DIT },    // 8
+    { DA, DA, DA, DA, DIT }     // 9
+};
+
 
 // constructor
 FGMorse::FGMorse() {
@@ -74,7 +87,7 @@ void make_tone( unsigned char *buf, int freq,
     int i, j;
 
     for ( i = 0; i < trans_len; ++i ) {
-       float level = ( sin( (double) i * 2.0 * SGD_PI / (8000.0 / freq) ) )
+       float level = ( sin( (double) i * 2.0 * SGD_PI / (BYTES_PER_SECOND / freq) ) )
            * ((double)i / trans_len) / 2.0 + 0.5;
 
        /* Convert to unsigned byte */
@@ -82,7 +95,7 @@ void make_tone( unsigned char *buf, int freq,
     }
 
     for ( i = trans_len; i < len - trans_len; ++i ) {
-       float level = ( sin( (double) i * 2.0 * SGD_PI / (8000.0 / freq) ) )
+       float level = ( sin( (double) i * 2.0 * SGD_PI / (BYTES_PER_SECOND / freq) ) )
            / 2.0 + 0.5;
 
        /* Convert to unsigned byte */
@@ -90,7 +103,7 @@ void make_tone( unsigned char *buf, int freq,
     }
     j = trans_len;
     for ( i = len - trans_len; i < len; ++i ) {
-       float level = ( sin( (double) i * 2.0 * SGD_PI / (8000.0 / freq) ) )
+       float level = ( sin( (double) i * 2.0 * SGD_PI / (BYTES_PER_SECOND / freq) ) )
            * ((double)j / trans_len) / 2.0 + 0.5;
        --j;
 
@@ -152,8 +165,8 @@ bool FGMorse::cust_init(const int freq ) {
 }
 
 
-// make a FGSimpleSound morse code transmission for the specified string
-FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
+// make a SGSoundSample morse code transmission for the specified string
+SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) {
     char *idptr = (char *)id.c_str();
 
     int length = 0;
@@ -178,7 +191,7 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
     // 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';
+           int c = (int)(idptr[i] - 'A');
            for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) {
                if ( alphabet[c][j] == DIT ) {
                    length += DIT_SIZE;
@@ -187,6 +200,16 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
                }
            }
            length += SPACE_SIZE;
+        } else if ( idptr[i] >= '0' && idptr[i] <= '9' ) {
+            int c = (int)(idptr[i] - '0');
+            for ( j = 0; j < 5; ++j) {
+                if ( numerals[c][j] == DIT ) {
+                    length += DIT_SIZE;
+                } else if ( numerals[c][j] == DAH ) {
+                    length += DAH_SIZE;
+                }
+            }
+            length += SPACE_SIZE;
        } else {
            // skip unknown character
        }
@@ -202,7 +225,7 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
 
     for ( i = 0; i < (int)id.length(); ++i ) {
        if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) {
-           char c = idptr[i] - 'A';
+           int c = (int)(idptr[i] - 'A');
            for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) {
                if ( alphabet[c][j] == DIT ) {
                    memcpy( buf_ptr, dit_ptr, DIT_SIZE );
@@ -214,6 +237,19 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
            }
            memcpy( buf_ptr, space, SPACE_SIZE );
            buf_ptr += SPACE_SIZE;
+        } else if ( idptr[i] >= '0' && idptr[i] <= '9' ) {
+            int c = (int)(idptr[i] - '0');
+            for ( j = 0; j < 5; ++j ) {
+                if ( numerals[c][j] == DIT ) {
+                    memcpy( buf_ptr, dit_ptr, DIT_SIZE );
+                    buf_ptr += DIT_SIZE;
+                } else if ( numerals[c][j] == DAH ) {
+                    memcpy( buf_ptr, dah_ptr, DAH_SIZE );
+                    buf_ptr += DAH_SIZE;
+                }
+            }
+           memcpy( buf_ptr, space, SPACE_SIZE );
+           buf_ptr += SPACE_SIZE;
        } else {
            // skip unknown character
        }
@@ -224,7 +260,10 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
     buf_ptr += SPACE_SIZE;
 
     // 4. create the simple sound and return
-    FGSimpleSound *sample = new FGSimpleSound( buffer, length );
+    SGSoundSample *sample = new SGSoundSample( buffer, length,
+                                               BYTES_PER_SECOND );
+    sample->set_reference_dist( 10.0 );
+    sample->set_max_dist( 20.0 );
 
     return sample;
 }