Catch sound exceptions at the earliest, report problem has an alert, and continue without segfaulting ( hopefully )
This commit is contained in:
parent
f5469ba9fe
commit
cc27909e6f
6 changed files with 111 additions and 79 deletions
|
@ -23,6 +23,7 @@
|
|||
#endif
|
||||
|
||||
#include <simgear/sound/soundmgr_openal.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
@ -231,16 +232,20 @@ void FGATC::Render(string& msg, const 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);
|
||||
// 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("/instrumentation/comm[0]/volume"));
|
||||
globals->get_soundmgr()->add(simple, refname);
|
||||
if(repeating) {
|
||||
globals->get_soundmgr()->play_looped(refname);
|
||||
} else {
|
||||
globals->get_soundmgr()->play_once(refname);
|
||||
try {
|
||||
SGSoundSample *simple
|
||||
= new SGSoundSample(buf, len, 8000);
|
||||
// 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("/instrumentation/comm[0]/volume"));
|
||||
globals->get_soundmgr()->add(simple, refname);
|
||||
if(repeating) {
|
||||
globals->get_soundmgr()->play_looped(refname);
|
||||
} else {
|
||||
globals->get_soundmgr()->play_once(refname);
|
||||
}
|
||||
} catch ( sg_io_exception &e ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
|
||||
}
|
||||
}
|
||||
delete[] buf;
|
||||
|
|
|
@ -110,8 +110,15 @@ void FGATCMgr::init() {
|
|||
// For now we'll do one hardwired one
|
||||
|
||||
v1 = new FGATCVoice;
|
||||
voiceOK = v1->LoadVoice("default");
|
||||
voice = true;
|
||||
try {
|
||||
voiceOK = v1->LoadVoice("default");
|
||||
voice = true;
|
||||
} catch ( sg_io_exception & ) {
|
||||
voiceOK = false;
|
||||
voice = false;
|
||||
delete v1;
|
||||
v1 = 0;
|
||||
}
|
||||
|
||||
/* I've loaded the voice even if /sim/sound/pause is true
|
||||
* since I know no way of forcing load of the voice if the user
|
||||
|
|
|
@ -293,8 +293,10 @@ void FGMarkerBeacon::search()
|
|||
if ( last_beacon != OUTER ) {
|
||||
if ( ! globals->get_soundmgr()->exists( "outer-marker" ) ) {
|
||||
SGSoundSample *sound = beacon.get_outer();
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, "outer-marker" );
|
||||
if ( sound ) {
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, "outer-marker" );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( audio_btn->getBoolValue() ) {
|
||||
|
@ -310,8 +312,10 @@ void FGMarkerBeacon::search()
|
|||
if ( last_beacon != MIDDLE ) {
|
||||
if ( ! globals->get_soundmgr()->exists( "middle-marker" ) ) {
|
||||
SGSoundSample *sound = beacon.get_middle();
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, "middle-marker" );
|
||||
if ( sound ) {
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, "middle-marker" );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( audio_btn->getBoolValue() ) {
|
||||
|
@ -327,8 +331,10 @@ void FGMarkerBeacon::search()
|
|||
if ( last_beacon != INNER ) {
|
||||
if ( ! globals->get_soundmgr()->exists( "inner-marker" ) ) {
|
||||
SGSoundSample *sound = beacon.get_inner();
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, "inner-marker" );
|
||||
if ( sound ) {
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, "inner-marker" );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( audio_btn->getBoolValue() ) {
|
||||
|
|
|
@ -905,32 +905,36 @@ void FGNavRadio::search()
|
|||
if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
|
||||
globals->get_soundmgr()->remove( nav_fx_name );
|
||||
}
|
||||
SGSoundSample *sound;
|
||||
sound = morse.make_ident( trans_ident, LO_FREQUENCY );
|
||||
sound->set_volume( 0.3 );
|
||||
if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
|
||||
// cout << "Added nav-vor-ident sound" << endl;
|
||||
} else {
|
||||
SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
|
||||
try {
|
||||
SGSoundSample *sound;
|
||||
sound = morse.make_ident( trans_ident, LO_FREQUENCY );
|
||||
sound->set_volume( 0.3 );
|
||||
if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
|
||||
// cout << "Added nav-vor-ident sound" << endl;
|
||||
} else {
|
||||
SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
|
||||
}
|
||||
|
||||
if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
|
||||
globals->get_soundmgr()->remove( dme_fx_name );
|
||||
}
|
||||
sound = morse.make_ident( trans_ident, HI_FREQUENCY );
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, dme_fx_name );
|
||||
|
||||
int offset = (int)(sg_random() * 30.0);
|
||||
play_count = offset / 4;
|
||||
last_time = globals->get_time_params()->get_cur_time() - offset;
|
||||
// cout << "offset = " << offset << " play_count = "
|
||||
// << play_count << " last_time = "
|
||||
// << last_time << " current time = "
|
||||
// << globals->get_time_params()->get_cur_time() << endl;
|
||||
|
||||
// cout << "Found a vor station in range" << endl;
|
||||
// cout << " id = " << nav->get_ident() << endl;
|
||||
} catch ( sg_io_exception &e ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
|
||||
}
|
||||
|
||||
if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
|
||||
globals->get_soundmgr()->remove( dme_fx_name );
|
||||
}
|
||||
sound = morse.make_ident( trans_ident, HI_FREQUENCY );
|
||||
sound->set_volume( 0.3 );
|
||||
globals->get_soundmgr()->add( sound, dme_fx_name );
|
||||
|
||||
int offset = (int)(sg_random() * 30.0);
|
||||
play_count = offset / 4;
|
||||
last_time = globals->get_time_params()->get_cur_time() - offset;
|
||||
// cout << "offset = " << offset << " play_count = "
|
||||
// << play_count << " last_time = "
|
||||
// << last_time << " current time = "
|
||||
// << globals->get_time_params()->get_cur_time() << endl;
|
||||
|
||||
// cout << "Found a vor station in range" << endl;
|
||||
// cout << " id = " << nav->get_ident() << endl;
|
||||
}
|
||||
} else {
|
||||
is_valid = false;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "beacon.hxx"
|
||||
|
||||
#include <simgear/structure/exception.hxx>
|
||||
|
||||
// constructor
|
||||
FGBeacon::FGBeacon()
|
||||
|
@ -56,44 +57,48 @@ bool FGBeacon::init() {
|
|||
ptr += INNER_DIT_LEN;
|
||||
}
|
||||
|
||||
inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
|
||||
inner->set_reference_dist( 10.0 );
|
||||
inner->set_max_dist( 20.0 );
|
||||
try {
|
||||
inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
|
||||
inner->set_reference_dist( 10.0 );
|
||||
inner->set_max_dist( 20.0 );
|
||||
|
||||
// Make middle marker beacon sound
|
||||
len= (int)(MIDDLE_DIT_LEN / 2.0 );
|
||||
unsigned char middle_dit[MIDDLE_DIT_LEN];
|
||||
make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
|
||||
TRANSITION_BYTES );
|
||||
// Make middle marker beacon sound
|
||||
len= (int)(MIDDLE_DIT_LEN / 2.0 );
|
||||
unsigned char middle_dit[MIDDLE_DIT_LEN];
|
||||
make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
|
||||
TRANSITION_BYTES );
|
||||
|
||||
len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
|
||||
unsigned char middle_dah[MIDDLE_DAH_LEN];
|
||||
make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
|
||||
TRANSITION_BYTES );
|
||||
len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
|
||||
unsigned char middle_dah[MIDDLE_DAH_LEN];
|
||||
make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
|
||||
TRANSITION_BYTES );
|
||||
|
||||
ptr = middle_buf;
|
||||
memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
|
||||
ptr += MIDDLE_DIT_LEN;
|
||||
memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
|
||||
ptr = middle_buf;
|
||||
memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
|
||||
ptr += MIDDLE_DIT_LEN;
|
||||
memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
|
||||
|
||||
middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND );
|
||||
middle->set_reference_dist( 10.0 );
|
||||
middle->set_max_dist( 20.0 );
|
||||
middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND );
|
||||
middle->set_reference_dist( 10.0 );
|
||||
middle->set_max_dist( 20.0 );
|
||||
|
||||
// Make outer marker beacon sound
|
||||
len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
|
||||
unsigned char outer_dah[OUTER_DAH_LEN];
|
||||
make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
|
||||
TRANSITION_BYTES );
|
||||
// Make outer marker beacon sound
|
||||
len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
|
||||
unsigned char outer_dah[OUTER_DAH_LEN];
|
||||
make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
|
||||
TRANSITION_BYTES );
|
||||
|
||||
ptr = outer_buf;
|
||||
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
|
||||
ptr += OUTER_DAH_LEN;
|
||||
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
|
||||
ptr = outer_buf;
|
||||
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
|
||||
ptr += OUTER_DAH_LEN;
|
||||
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
|
||||
|
||||
outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND);
|
||||
outer->set_reference_dist( 10.0 );
|
||||
outer->set_max_dist( 20.0 );
|
||||
outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND);
|
||||
outer->set_reference_dist( 10.0 );
|
||||
outer->set_max_dist( 20.0 );
|
||||
} catch ( sg_io_exception &e ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ FGFX::init()
|
|||
SGPropertyNode root;
|
||||
try {
|
||||
readProperties(path.str(), &root);
|
||||
} catch (const sg_exception &e) {
|
||||
} catch (const sg_exception &) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||
"Incorrect path specified in configuration file");
|
||||
return;
|
||||
|
@ -95,10 +95,15 @@ FGFX::init()
|
|||
for (i = 0; i < node->nChildren(); i++) {
|
||||
SGXmlSound *sound = new SGXmlSound();
|
||||
|
||||
sound->init(globals->get_props(), node->getChild(i),
|
||||
globals->get_soundmgr(), globals->get_fg_root());
|
||||
try {
|
||||
sound->init(globals->get_props(), node->getChild(i),
|
||||
globals->get_soundmgr(), globals->get_fg_root());
|
||||
|
||||
_sound.push_back(sound);
|
||||
_sound.push_back(sound);
|
||||
} catch ( sg_io_exception &e ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
|
||||
delete sound;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue