]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/beacon.cxx
Make the sound-manager optional in a few places.
[flightgear.git] / src / Sound / beacon.cxx
index ad938c0c648cf4b7a59e452dff6d12dec50378ba..689922932b4bfb15a3a7321a2b146b5b7c14bb31 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
-// $Id$
 
+#include <stdlib.h>
+#include <cstring>
 
 #include "beacon.hxx"
 
+#include <simgear/sound/sample_openal.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/debug/logstream.hxx>
 
 // constructor
 FGBeacon::FGBeacon()
@@ -37,17 +40,12 @@ FGBeacon::~FGBeacon() {
 
 // allocate and initialize sound samples
 bool FGBeacon::init() {
-    int i;
-    int len;
     unsigned char *ptr;
+    size_t i, len;
 
-    if (globals->get_soundmgr()->is_working() == false) {
-       return false;
-    }
-
-    unsigned char inner_buf[ INNER_SIZE ] ;
-    unsigned char middle_buf[ MIDDLE_SIZE ] ;
-    unsigned char outer_buf[ OUTER_SIZE ] ;
+    const unsigned char* inner_buf = (const unsigned char*)malloc( INNER_SIZE );
+    const unsigned char* middle_buf = (const unsigned char*)malloc(MIDDLE_SIZE);
+    const unsigned char* outer_buf = (const unsigned char*)malloc( OUTER_SIZE );
 
     // Make inner marker beacon sound
     len= (int)(INNER_DIT_LEN / 2.0 );
@@ -55,14 +53,14 @@ bool FGBeacon::init() {
     make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
               TRANSITION_BYTES );
 
-    ptr = inner_buf;
+    ptr = (unsigned char*)inner_buf;
     for ( i = 0; i < 6; ++i ) {
        memcpy( ptr, inner_dit, INNER_DIT_LEN );
        ptr += INNER_DIT_LEN;
     }
 
     try {
-        inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
+        inner = new SGSoundSample( &inner_buf, INNER_SIZE, BYTES_PER_SECOND );
         inner->set_reference_dist( 10.0 );
         inner->set_max_dist( 20.0 );
 
@@ -77,12 +75,12 @@ bool FGBeacon::init() {
         make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
                    TRANSITION_BYTES );
 
-        ptr = middle_buf;
+        ptr = (unsigned char*)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 = new SGSoundSample( &middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND);
         middle->set_reference_dist( 10.0 );
         middle->set_max_dist( 20.0 );
 
@@ -92,17 +90,28 @@ bool FGBeacon::init() {
         make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
                    TRANSITION_BYTES );
            
-        ptr = outer_buf;
+        ptr = (unsigned char*)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 = 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());
+        SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage());
     }
 
     return true;
 }
+
+FGBeacon * FGBeacon::_instance = NULL;
+
+FGBeacon * FGBeacon::instance()
+{
+    if( _instance == NULL ) {
+        _instance = new FGBeacon();
+        _instance->init();
+    }
+    return _instance;
+}