X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSound%2Fmorse.cxx;h=df6c969face529f7572d3e55f9f15c59af5b3f7a;hb=2d6bf222acdb6de32d6dff07993dc340834dbfff;hp=754c98eb3be201903ebe809160cf1f65277a238b;hpb=08dfa30d875c484affbe36a20041a7d70ea9d0da;p=flightgear.git diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index 754c98eb3..df6c969fa 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -23,9 +23,6 @@ #include -#include
-#include
- #include "morse.hxx" @@ -171,10 +168,6 @@ 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 ) { - if (globals->get_soundmgr()->is_working() == false) { - return 0; - } - char *idptr = (char *)id.c_str(); int length = 0; @@ -200,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 ) { @@ -226,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; @@ -268,12 +261,9 @@ 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, + 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 );