]> git.mxchange.org Git - flightgear.git/commitdiff
Catch sound exceptions at the earliest, report problem has an alert, and continue...
authorfredb <fredb>
Sun, 12 Feb 2006 19:57:57 +0000 (19:57 +0000)
committerfredb <fredb>
Sun, 12 Feb 2006 19:57:57 +0000 (19:57 +0000)
src/ATC/ATC.cxx
src/ATC/ATCmgr.cxx
src/Instrumentation/marker_beacon.cxx
src/Instrumentation/navradio.cxx
src/Sound/beacon.cxx
src/Sound/fg_fx.cxx

index 9d0a37a04108359576241cc8ced26e813a0ac89a..096b7cdfc8443e7aaf13a0a1abf61d4aa2b31198 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 #include <simgear/sound/soundmgr_openal.hxx>
 #endif
 
 #include <simgear/sound/soundmgr_openal.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.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) {
                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;
                        }
                }
                delete[] buf;
index dfb483ace3408538a803713ee0534a5ffdf48e94..12ac4aaa5604e077ec6c3f433d21c59e5283f95b 100644 (file)
@@ -110,8 +110,15 @@ void FGATCMgr::init() {
        // For now we'll do one hardwired one
        
        v1 = new FGATCVoice;
        // 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
        
        /* 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
index 018d5baf7e4c2d62247b5ed1cd9067b0d904d3a9..910efc56d865bbaadf3513c0b5fecd346252707b 100644 (file)
@@ -293,8 +293,10 @@ void FGMarkerBeacon::search()
         if ( last_beacon != OUTER ) {
             if ( ! globals->get_soundmgr()->exists( "outer-marker" ) ) {
                 SGSoundSample *sound = beacon.get_outer();
         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() ) {
             }
         }
         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();
        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() ) {
            }
         }
         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();
        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() ) {
            }
         }
         if ( audio_btn->getBoolValue() ) {
index 399e3c507759048fdd77960f24f4ecb43027c648..466564010aea72ae1524cd897137d75918aaa313 100644 (file)
@@ -905,32 +905,36 @@ void FGNavRadio::search()
            if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
                globals->get_soundmgr()->remove( nav_fx_name );
            }
            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");
-            }
-
-           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;
+            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");
+                }
 
 
-           // cout << "Found a vor station in range" << endl;
-           // cout << " id = " << nav->get_ident() << endl;
+               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());
+            }
        }
     } else {
        is_valid = false;
        }
     } else {
        is_valid = false;
index 5d9ae959414107972bae401fcdd04d10853f244e..4b3bd21d77795af8e04afcf0ccdd91a2a07c21db 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "beacon.hxx"
 
 
 #include "beacon.hxx"
 
+#include <simgear/structure/exception.hxx>
 
 // constructor
 FGBeacon::FGBeacon()
 
 // constructor
 FGBeacon::FGBeacon()
@@ -56,44 +57,48 @@ bool FGBeacon::init() {
        ptr += INNER_DIT_LEN;
     }
 
        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 );
-
-    // 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 );
-
-    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 );
-
-    // 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 );
-
-    outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND);
-    outer->set_reference_dist( 10.0 );
-    outer->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 );
+
+        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 );
+
+        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 );
+           
+        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 );
+    } catch ( sg_io_exception &e ) {
+        SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
+    }
 
     return true;
 }
 
     return true;
 }
index 7054e358e2bdd2c5d12f475394e691e70d01032a..5537bb1195b80743a59005658aa6499ed1829383 100644 (file)
@@ -85,7 +85,7 @@ FGFX::init()
    SGPropertyNode root;
    try {
       readProperties(path.str(), &root);
    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;
       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();
 
    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;
+      }
    }
 }
 
    }
 }