]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/morse.cxx
Merge branch 'jsd/atmos' into topic/atmos-merge
[flightgear.git] / src / Sound / morse.cxx
index f9b2fd11440e39c636fc2352ce790a4ca903a512..754c98eb3be201903ebe809160cf1f65277a238b 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started March 2001.
 //
-// Copyright (C) 2001  Curtis L. Olson - curt@flightgear.org
+// Copyright (C) 2001  Curtis L. Olson - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 
 #include <simgear/constants.h>
 
+#include <Main/fg_props.hxx>
+#include <Main/globals.hxx>
+
 #include "morse.hxx"
 
 
@@ -87,7 +90,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 * SGD_2PI / (BYTES_PER_SECOND / freq) ) )
            * ((double)i / trans_len) / 2.0 + 0.5;
 
        /* Convert to unsigned byte */
@@ -95,7 +98,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 * SGD_2PI / (BYTES_PER_SECOND / freq) ) )
            / 2.0 + 0.5;
 
        /* Convert to unsigned byte */
@@ -103,7 +106,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 * SGD_2PI / (BYTES_PER_SECOND / freq) ) )
            * ((double)j / trans_len) / 2.0 + 0.5;
        --j;
 
@@ -165,8 +168,13 @@ bool FGMorse::cust_init(const int freq ) {
 }
 
 
-// make a SGSimpleSound morse code transmission for the specified string
-SGSimpleSound *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 ) {
+
+    if (globals->get_soundmgr()->is_working() == false) {
+       return 0;
+    }
+
     char *idptr = (char *)id.c_str();
 
     int length = 0;
@@ -191,7 +199,7 @@ SGSimpleSound *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;
@@ -201,7 +209,7 @@ SGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
            }
            length += SPACE_SIZE;
         } else if ( idptr[i] >= '0' && idptr[i] <= '9' ) {
-            char c = idptr[i] - '0';
+            int c = (int)(idptr[i] - '0');
             for ( j = 0; j < 5; ++j) {
                 if ( numerals[c][j] == DIT ) {
                     length += DIT_SIZE;
@@ -225,7 +233,7 @@ SGSimpleSound *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 );
@@ -238,7 +246,7 @@ SGSimpleSound *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' ) {
-            char c = idptr[i] - '0';
+            int c = (int)(idptr[i] - '0');
             for ( j = 0; j < 5; ++j ) {
                 if ( numerals[c][j] == DIT ) {
                     memcpy( buf_ptr, dit_ptr, DIT_SIZE );
@@ -260,7 +268,14 @@ SGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
     buf_ptr += SPACE_SIZE;
 
     // 4. create the simple sound and return
-    SGSimpleSound *sample = new SGSimpleSound( buffer, length );
+    SGSoundSample *sample = new SGSoundSample( buffer, length,
+                                               BYTES_PER_SECOND );
+
+    // clean up the buffer
+    delete [] buffer;
+
+    sample->set_reference_dist( 10.0 );
+    sample->set_max_dist( 20.0 );
 
     return sample;
 }