X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSound%2Fmorse.cxx;h=df6c969face529f7572d3e55f9f15c59af5b3f7a;hb=2d6bf222acdb6de32d6dff07993dc340834dbfff;hp=e88b2242aa6ae669eeea6aa058f3f8194a6925cb;hpb=944a82b57617fa5a9fda4cc3f279c210b3f0d15e;p=flightgear.git diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index e88b2242a..df6c969fa 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -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 @@ -16,7 +16,7 @@ // // 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$ @@ -87,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 / (BYTES_PER_SECOND / 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 +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 / (BYTES_PER_SECOND / freq) ) ) + float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) ) / 2.0 + 0.5; /* Convert to unsigned byte */ @@ -103,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 / (BYTES_PER_SECOND / freq) ) ) + float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) ) * ((double)j / trans_len) / 2.0 + 0.5; --j; @@ -167,6 +167,7 @@ bool FGMorse::cust_init(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; @@ -192,7 +193,7 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) { for ( i = 0; i < (int)id.length(); ++i ) { if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) { int c = (int)(idptr[i] - 'A'); - for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) { + for ( j = 0; j < 4 && alphabet[c][j] != end; ++j ) { if ( alphabet[c][j] == DIT ) { length += DIT_SIZE; } else if ( alphabet[c][j] == DAH ) { @@ -218,15 +219,15 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) { length += 2 * SPACE_SIZE; // 2. Allocate space for the message - unsigned char *buffer = new unsigned char[length]; + const unsigned char* buffer = (const unsigned char *)malloc(length); // 3. Assemble the message; - unsigned char *buf_ptr = buffer; + unsigned char *buf_ptr = (unsigned char*)buffer; for ( i = 0; i < (int)id.length(); ++i ) { if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) { int c = (int)(idptr[i] - 'A'); - for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) { + for ( j = 0; j < 4 && alphabet[c][j] != end; ++j ) { if ( alphabet[c][j] == DIT ) { memcpy( buf_ptr, dit_ptr, DIT_SIZE ); buf_ptr += DIT_SIZE; @@ -260,12 +261,8 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) { buf_ptr += SPACE_SIZE; // 4. create the simple sound and return - SGSoundSample *sample = new SGSoundSample( buffer, length, - BYTES_PER_SECOND, - false ); - - // clean up the buffer - delete [] buffer; + SGSoundSample *sample = new SGSoundSample( &buffer, length, + BYTES_PER_SECOND ); sample->set_reference_dist( 10.0 ); sample->set_max_dist( 20.0 );