From 944a82b57617fa5a9fda4cc3f279c210b3f0d15e Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 10 May 2004 21:24:30 +0000 Subject: [PATCH] Clean up some sound buffer allocation/deallocation issues. --- src/ATC/AIPlane.cxx | 2 +- src/ATC/ATC.cxx | 3 ++- src/ATC/ATCVoice.cxx | 3 ++- src/FDM/ExternalPipe/ExternalPipe.cxx | 4 ++-- src/Main/main.cxx | 3 +++ src/Network/atc610x.cxx | 8 ++++---- src/Sound/beacon.cxx | 20 ++++++++++++++++---- src/Sound/beacon.hxx | 4 ---- src/Sound/morse.cxx | 7 ++++++- 9 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/ATC/AIPlane.cxx b/src/ATC/AIPlane.cxx index a7f021c61..272f4e73b 100644 --- a/src/ATC/AIPlane.cxx +++ b/src/ATC/AIPlane.cxx @@ -189,7 +189,7 @@ void FGAIPlane::Render(string refname, bool repeating) { int len; unsigned char* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), len, voice); if(voice) { - SGSoundSample* simple = new SGSoundSample(buf, len, 8000); + SGSoundSample* simple = new SGSoundSample(buf, len, 8000, false); // TODO - at the moment the volume is always set off comm1 // and can't be changed after the transmission has started. simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume")); diff --git a/src/ATC/ATC.cxx b/src/ATC/ATC.cxx index f17700c67..47f9bba31 100644 --- a/src/ATC/ATC.cxx +++ b/src/ATC/ATC.cxx @@ -223,7 +223,8 @@ void FGATC::Render(string msg, string refname, bool repeating) { int len; unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice); if(voice) { - SGSoundSample* simple = new SGSoundSample(buf, len, 8000); + SGSoundSample *simple + = new SGSoundSample(buf, len, 8000, false); // TODO - at the moment the volume is always set off comm1 // and can't be changed after the transmission has started. simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume")); diff --git a/src/ATC/ATCVoice.cxx b/src/ATC/ATCVoice.cxx index ab88ea0fd..82721f420 100644 --- a/src/ATC/ATCVoice.cxx +++ b/src/ATC/ATCVoice.cxx @@ -37,7 +37,8 @@ FGATCVoice::FGATCVoice() { } FGATCVoice::~FGATCVoice() { - // delete SoundData; + free( rawSoundData ); + delete SoundData; } // Load the two voice files - one containing the raw sound data (.wav) and one containing the word positions (.vce). diff --git a/src/FDM/ExternalPipe/ExternalPipe.cxx b/src/FDM/ExternalPipe/ExternalPipe.cxx index fb4d0daea..dd2920db4 100644 --- a/src/FDM/ExternalPipe/ExternalPipe.cxx +++ b/src/FDM/ExternalPipe/ExternalPipe.cxx @@ -206,7 +206,7 @@ void FGExternalPipe::init() { } last_cg_offset = cg_offset; - SG_LOG( SG_IO, SG_INFO, "before sending reset command." ); + SG_LOG( SG_IO, SG_ALERT, "before sending reset command." ); if( fgGetBool("/sim/presets/onground") ) { sprintf( cmd, "reset=ground" ); @@ -215,7 +215,7 @@ void FGExternalPipe::init() { } result = write_fifo( '1', pd1, cmd, strlen(cmd) ); - SG_LOG( SG_IO, SG_INFO, "Remote FDM init() finished." ); + SG_LOG( SG_IO, SG_ALERT, "Remote FDM init() finished." ); #endif } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 365051385..f3f2191cb 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1291,6 +1291,7 @@ static void fgMainLoop( void ) { sgVec3 source_pos_offset; sgSubVec3( source_pos_offset, view_location->get_view_pos(), acmodel_loc->get_view_pos() ); + // cout << "pos all = " << source_pos_offset[0] << " " << source_pos_offset[1] << " " << source_pos_offset[2] << endl; globals->get_soundmgr()->set_source_pos_all( source_pos_offset ); // set the velocity @@ -1298,12 +1299,14 @@ static void fgMainLoop( void ) { sgSubVec3( source_vel, source_pos_offset, last_pos_offset ); sgScaleVec3( source_vel, delta_time_sec ); sgCopyVec3( last_pos_offset, source_pos_offset ); + // cout << "vel = " << source_vel[0] << " " << source_vel[1] << " " << source_vel[2] << endl; globals->get_soundmgr()->set_source_vel_all( source_vel ); // Right now we make a simplifying assumption that the listener is // always positioned at the origin. sgVec3 listener_pos; sgSetVec3( listener_pos, 0.0, 0.0, 0.0 ); + // cout << "listener = " << listener_pos[0] << " " << listener_pos[1] << " " << listener_pos[2] << endl; globals->get_soundmgr()->set_listener_pos( listener_pos ); #endif diff --git a/src/Network/atc610x.cxx b/src/Network/atc610x.cxx index cf592db73..b16b33121 100644 --- a/src/Network/atc610x.cxx +++ b/src/Network/atc610x.cxx @@ -1768,14 +1768,14 @@ bool FGATC610x::do_switches() { // master switches fgSetBool( "/controls/engines/engine[0]/master-bat", - switch_matrix[board][5][1] ); + switch_matrix[board][4][1] ); fgSetBool( "/controls/engines/engine[1]/master-bat", - switch_matrix[board][5][1] ); + switch_matrix[board][4][1] ); fgSetBool( "/controls/engines/engine[0]/master-alt", - switch_matrix[board][4][1] ); + switch_matrix[board][5][1] ); fgSetBool( "/controls/engines/engine[1]/master-alt", - switch_matrix[board][4][1] ); + switch_matrix[board][5][1] ); fgSetBool( "/controls/switches/master-avionics", switch_matrix[board][0][3] ); diff --git a/src/Sound/beacon.cxx b/src/Sound/beacon.cxx index 24424c14a..7b797a3a7 100644 --- a/src/Sound/beacon.cxx +++ b/src/Sound/beacon.cxx @@ -25,11 +25,18 @@ // constructor -FGBeacon::FGBeacon() { +FGBeacon::FGBeacon() : + inner(NULL), + middle(NULL), + outer(NULL) +{ } // destructor FGBeacon::~FGBeacon() { + delete inner; + delete middle; + delete outer; } @@ -39,6 +46,10 @@ bool FGBeacon::init() { int len; unsigned char *ptr; + unsigned char inner_buf[ INNER_SIZE ] ; + unsigned char middle_buf[ MIDDLE_SIZE ] ; + unsigned char outer_buf[ OUTER_SIZE ] ; + // Make inner marker beacon sound len= (int)(INNER_DIT_LEN / 2.0 ); unsigned char inner_dit[INNER_DIT_LEN]; @@ -51,7 +62,7 @@ bool FGBeacon::init() { ptr += INNER_DIT_LEN; } - inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND ); + inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND, false ); inner->set_reference_dist( 10.0 ); inner->set_max_dist( 20.0 ); @@ -71,7 +82,8 @@ bool FGBeacon::init() { ptr += MIDDLE_DIT_LEN; memcpy( ptr, middle_dah, MIDDLE_DAH_LEN ); - middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND ); + middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND, + false ); middle->set_reference_dist( 10.0 ); middle->set_max_dist( 20.0 ); @@ -86,7 +98,7 @@ bool FGBeacon::init() { ptr += OUTER_DAH_LEN; memcpy( ptr, outer_dah, OUTER_DAH_LEN ); - outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND ); + outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND, false ); outer->set_reference_dist( 10.0 ); outer->set_max_dist( 20.0 ); diff --git a/src/Sound/beacon.hxx b/src/Sound/beacon.hxx index 6d6807622..def92896e 100644 --- a/src/Sound/beacon.hxx +++ b/src/Sound/beacon.hxx @@ -96,10 +96,6 @@ class FGBeacon { private: - unsigned char inner_buf[ INNER_SIZE ] ; - unsigned char middle_buf[ MIDDLE_SIZE ] ; - unsigned char outer_buf[ OUTER_SIZE ] ; - SGSoundSample *inner; SGSoundSample *middle; SGSoundSample *outer; diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index d2f9fc639..e88b2242a 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -261,7 +261,12 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) { // 4. create the simple sound and return SGSoundSample *sample = new SGSoundSample( buffer, length, - BYTES_PER_SECOND ); + BYTES_PER_SECOND, + false ); + + // clean up the buffer + delete [] buffer; + sample->set_reference_dist( 10.0 ); sample->set_max_dist( 20.0 ); -- 2.39.5