]> git.mxchange.org Git - flightgear.git/commitdiff
Don't make the SoundManager a memebr of the subsystem manager; It needs to be initial...
authorehofman <ehofman>
Sat, 24 Oct 2009 08:31:37 +0000 (08:31 +0000)
committerTim Moore <timoore@redhat.com>
Sat, 24 Oct 2009 17:51:39 +0000 (19:51 +0200)
20 files changed:
src/ATCDCL/AIPlane.cxx
src/ATCDCL/ATC.cxx
src/ATCDCL/ATCVoice.cxx
src/ATCDCL/ATCVoice.hxx
src/Environment/fgclouds.cxx
src/Instrumentation/adf.cxx
src/Instrumentation/kr_87.cxx
src/Instrumentation/marker_beacon.cxx
src/Instrumentation/mk_viii.cxx
src/Instrumentation/navradio.cxx
src/Main/fg_commands.cxx
src/Main/fg_init.cxx
src/Main/fg_props.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Main/main.cxx
src/Main/viewmgr.cxx
src/Model/acmodel.cxx
src/Sound/beacon.cxx
src/Sound/morse.cxx

index 1a3e77dc005ce7e5c07daae461100b2b9bf09eb1..3a46ee051932eb0c06df859d7d623a293205aca4 100644 (file)
@@ -24,7 +24,6 @@
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <math.h>
 #include <string>
-#include <memory>
 using std::string;
 
 
@@ -52,8 +51,7 @@ FGAIPlane::FGAIPlane() {
        _rollSuspended = false;
 
        if ( !_sgr ) {
-               SGSoundMgr *smgr;
-               smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+               SGSoundMgr *smgr = globals->get_soundmgr();
                _sgr = smgr->find("atc", true);
                 _sgr->tie_to_listener();
        }
@@ -199,13 +197,10 @@ void FGAIPlane::Render(const string& refname, const float volume, bool repeating
 #ifdef ENABLE_AUDIO_SUPPORT
        voice = (voiceOK && fgGetBool("/sim/sound/voice"));
        if(voice) {
-           string buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), voice);
+            sizte_t len;
+           void* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), voice, &len);
            if(voice && (volume > 0.05)) {
-                std::auto_ptr<unsigned char> ptr( (unsigned char*)buf.c_str() );
-               SGSoundSample* simple = 
-                   new SGSoundSample(ptr, buf.length(), 8000 );
-                // TODO - at the moment the volume can't be changed 
-               // after the transmission has started.
+               SGSoundSample* simple = new SGSoundSample(buf, len, 8000 );
                simple->set_volume(volume);
                _sgr->add(simple, refname);
                _sgr->play(refname, repeating);
index 9a8d1602882b10df304608c9d55e3b3f05198989..7e17f1da79775f0fd936eb614af0eaa8661c16ad 100644 (file)
@@ -25,7 +25,6 @@
 #include "ATC.hxx"
 
 #include <iostream>
-#include <memory>
 
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/structure/exception.hxx>
@@ -57,8 +56,7 @@ FGATC::FGATC() :
        _counter(0.0),
        _max_count(5.0)
 {
-       SGSoundMgr *smgr;
-       smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+       SGSoundMgr *smgr = globals->get_soundmgr();
        _sgr = smgr->find("atc", true);
 }
 
@@ -231,18 +229,15 @@ void FGATC::Render(string& msg, const float volume,
 #ifdef ENABLE_AUDIO_SUPPORT
        _voice = (_voiceOK && fgGetBool("/sim/sound/voice"));
        if(_voice) {
-               string buf = _vPtr->WriteMessage((char*)msg.c_str(), _voice);
-               if(_voice && (volume > 0.05)) {
+                size_t len;
+               void* buf = _vPtr->WriteMessage((char*)msg.c_str(), &len);
+               if(buf && (volume > 0.05)) {
                        NoRender(refname);
                        try {
 // >>> Beware: must pass a (new) object to the (add) method,
 // >>> because the (remove) method is going to do a (delete)
 // >>> whether that's what you want or not.
-                               std::auto_ptr<unsigned char> ptr( (unsigned char*)buf.c_str() );
-                               SGSoundSample *simple = 
-                                   new SGSoundSample(ptr,  buf.length(), 8000);
-                               // TODO - at the moment the volume can't be changed 
-                               // after the transmission has started.
+                               SGSoundSample *simple = new SGSoundSample(&buf, len, 8000);
                                simple->set_volume(volume);
                                _sgr->add(simple, refname);
                                _sgr->play(refname, repeating);
index bcd48f54ad18f168c1cd79ba7926d1311afc523b..5659b1132cfad76bbecbde1701bc9e585c5bb66d 100644 (file)
@@ -72,7 +72,7 @@ bool FGATCVoice::LoadVoice(const string& voice) {
        
        string full_path = path.str();
        int format, freq;
-        SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+        SGSoundMgr *smgr = globals->get_soundmgr();
        void *data;
         if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq))
             return false;
@@ -134,7 +134,7 @@ typedef tokenList_type::iterator tokenList_iterator;
 
 // Given a desired message, return a string containing the
 // sound-sample data
-string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
+void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
        
        // What should we do here?
        // First - parse the message into a list of tokens.
@@ -185,8 +185,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
        
        // Check for no tokens found else slScheduler can be crashed
        if(!word) {
-               dataOK = false;
-               return "";
+               *len = 0;
+               return NULL;
        }
        boost::shared_array<char> tmpbuf(new char[cumLength]);
        unsigned int bufpos = 0;
@@ -202,8 +202,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
                        SG_LOG(SG_ATC, SG_ALERT, "Offset + length: " << wdptr[i].offset + wdptr[i].length
                             << " exceeds rawdata size: " << rawDataSize << endl);
 
-                       dataOK = false;
-                       return "";
+                       *len = 0;
+                       return NULL;
                }
                memcpy(tmpbuf.get() + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length);
                bufpos += wdptr[i].length;
@@ -213,9 +213,11 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
        unsigned int offsetIn = (int)(cumLength * sg_random());
        if(offsetIn > cumLength) offsetIn = cumLength;
 
-       string front(tmpbuf.get(), offsetIn);
-       string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
+       void *data = malloc(cumLength);
+       memcpy(data, tmpbuf.get(), cumLength);
+       *len = cumLength;
+       // string front(tmpbuf.get(), offsetIn);
+       // string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
 
-       dataOK = true;  
-       return back + front;
+       return data;
 }
index f4b6c7f50b399952a40ad35634bd0150d6747401..6ec4f39324ad7e62e8dc08956abe82cd67821b5b 100644 (file)
@@ -49,8 +49,8 @@ public:
        bool LoadVoice(const std::string& voice);
        
        // Given a desired message, return a pointer to the data buffer and write the buffer length into len.
-       // Sets dataOK = true if the returned buffer is valid.
-       std::string WriteMessage(const char* message, bool& dataOK);
+       // Sets len to something other than 0 if the returned buffer is valid.
+       void* WriteMessage(const char* message, size_t *len);
 
 private:
 
index a4264bc58ee739c966e17199d5f16244806bf376..1498a00f47096502c7386c14c327a6657b20427b 100644 (file)
@@ -68,7 +68,7 @@ void FGClouds::init(void) {
                snd_lightning = new SGSoundSample(globals->get_fg_root().c_str(), "Sounds/thunder.wav");
                snd_lightning->set_max_dist(7000.0f);
                snd_lightning->set_reference_dist(3000.0f);
-               SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+               SGSoundMgr *smgr = globals->get_soundmgr();
                SGSampleGroup *sgr = smgr->find("weather", true);
                sgr->add( snd_lightning, "thunder" );
                sgEnviro.set_sampleGroup( sgr );
index 9f9ba2d835d90c6b5ff2800cf98946b469acf67a..6da2a2ed40d1614d8f01386d6d3b3a1e0bd7fee1 100644 (file)
@@ -102,7 +102,7 @@ ADF::init ()
     _ident_node = node->getChild("ident", 0, true);
     _ident_audible_node = node->getChild("ident-audible", 0, true);
 
-    SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    SGSoundMgr *smgr = globals->get_soundmgr();
     _sgr = smgr->find("avionics", true);
     _sgr->tie_to_listener();
 
index d0087c0985429b53db48b60a32afe512e58c742b..41928a097f486c223b6cc224c0bac09c7ff9480c 100644 (file)
@@ -117,7 +117,7 @@ FGKR_87::~FGKR_87() {
 
 
 void FGKR_87::init () {
-    SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    SGSoundMgr *smgr = globals->get_soundmgr();
     _sgr = smgr->find("avionics", true);
     _sgr->tie_to_listener();
     morse.init();
index 3a0d33819d24e28bc3607e73e571c6e7e2141f90..d2e9774b702dacc4f0c6a81eaa4172d609e7fff5 100644 (file)
@@ -117,7 +117,7 @@ FGMarkerBeacon::init ()
     if (serviceable->getType() == simgear::props::NONE)
         serviceable->setBoolValue( true );
 
-    SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    SGSoundMgr *smgr = globals->get_soundmgr();
     _sgr = smgr->find("avionics", true);
     _sgr->tie_to_listener();
 
index 340c4bf1162861c50c11a0901572c146fa888752..f2a4dba2c3801503c5201cb007fb6644ade16d15 100755 (executable)
@@ -2200,7 +2200,7 @@ MK_VIII::VoicePlayer::init ()
 {
 #define STDPAUSE 0.75  // [SPEC] 6.4.4: "the standard 0.75 second delay"
 
-  SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+  SGSoundMgr *smgr = globals->get_soundmgr();
   _sgr = smgr->find("avionics", true);
   _sgr->tie_to_listener();
 
index 79f864c336994c8b6ed9d991627b04ce9a06e498..4dace88a02690f932570ebe11746600a7acc9da7 100644 (file)
@@ -183,7 +183,7 @@ FGNavRadio::~FGNavRadio()
 void
 FGNavRadio::init ()
 {
-    SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    SGSoundMgr *smgr = globals->get_soundmgr();
     _sgr = smgr->find("avionics", true);
     _sgr->tie_to_listener();
 
index 52b892a41d9d35991e1caf731d007e3fedc67ef1..151efa2075a58360389bfb1466d735ecddbc0ead 100644 (file)
@@ -1259,7 +1259,7 @@ do_play_audio_sample (const SGPropertyNode * arg)
     try {
         static FGSampleQueue *queue = 0;
         if ( !queue ) {
-           SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+           SGSoundMgr *smgr = globals->get_soundmgr();
            queue = new FGSampleQueue(smgr, "queue");
            queue->tie_to_listener();
         }
index a78759c42f1a0c2384951f1b1293081f0d987c46..cf6c86b702cab88cedfe088ee6495f93f0d1aeea 100644 (file)
@@ -1448,6 +1448,13 @@ bool fgInitSubsystems() {
     globals->get_event_mgr()->init();
     globals->get_event_mgr()->setRealtimeProperty(fgGetNode("/sim/time/delta-realtime-sec", true));
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the sound manager subsystem.
+    ////////////////////////////////////////////////////////////////////
+
+    globals->get_soundmgr()->bind();
+    globals->get_soundmgr()->init();
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the property interpolator subsystem. Put into the INIT
     // group because the "nasal" subsystem may need it at GENERAL take-down.
index 6a54db66515efc2e9ba5185b9fdd5df2a3db79c7..f18c5fb92d2578683d339988e7f39555e94af300 100644 (file)
@@ -222,7 +222,7 @@ setFreeze (bool f)
     frozen = f;
 
     // Stop sound on a pause
-    SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    SGSoundMgr *smgr = globals->get_soundmgr();
     if ( smgr != NULL ) {
         if ( f ) {
             smgr->suspend();
index 7e6553fa4b196ba2602e70bdc2ada320e5ef95c3..da3de6a46beeba1fabe72597bd86356dde77e94a 100644 (file)
@@ -15,8 +15,8 @@
 // General Public License for more details.
 //
 // You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
@@ -32,6 +32,7 @@
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/structure/event_mgr.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
 
 #include <Aircraft/controls.hxx>
 #include <Airports/runways.hxx>
@@ -72,6 +73,7 @@ FGGlobals::FGGlobals() :
     renderer( new FGRenderer ),
     subsystem_mgr( new SGSubsystemMgr ),
     event_mgr( new SGEventMgr ),
+    soundmgr( new SGSoundMgr ),
     sim_time_sec( 0.0 ),
     fg_root( "" ),
     warp( 0 ),
@@ -158,6 +160,9 @@ FGGlobals::~FGGlobals()
     delete channellist;
     delete airwaynet;
     delete multiplayer_mgr;
+
+    soundmgr->unbind();
+    delete soundmgr;
 }
 
 
@@ -259,6 +264,11 @@ FGGlobals::add_subsystem (const char * name,
     subsystem_mgr->add(name, subsystem, type, min_time_sec);
 }
 
+SGSoundMgr *
+FGGlobals::get_soundmgr () const
+{
+    return soundmgr;
+}
 
 SGEventMgr *
 FGGlobals::get_event_mgr () const
index e778590ddb092b18b1500042b759d43c14ab7065..06490eaf38f9a60af0012464e557306d49929b20 100644 (file)
@@ -52,6 +52,7 @@ class SGTime;
 class SGEventMgr;
 class SGSubsystemMgr;
 class SGSubsystem;
+class SGSoundMgr;
 
 class FGAIMgr;
 class FGATCMgr;
@@ -93,6 +94,7 @@ private:
     FGRenderer *renderer;
     SGSubsystemMgr *subsystem_mgr;
     SGEventMgr *event_mgr;
+    SGSoundMgr *soundmgr;
 
     // Number of milliseconds elapsed since the start of the program.
     double sim_time_sec;
@@ -198,6 +200,8 @@ public:
 
     virtual SGEventMgr *get_event_mgr () const;
 
+    virtual SGSoundMgr *get_soundmgr () const;
+
     inline double get_sim_time_sec () const { return sim_time_sec; }
     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
index 30741f1c1794f5887153ec6cfba2f8a7a59f989d..4ab21a8850e5ad0579065aa442cfebc7d225d5db 100644 (file)
@@ -482,7 +482,7 @@ static void fgMainLoop( void ) {
     // is processing the scenery (doubled the frame-rate for me) -EMH-
     ////////////////////////////////////////////////////////////////////
 #ifdef ENABLE_AUDIO_SUPPORT
-    static SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    static SGSoundMgr *smgr = globals->get_soundmgr();
     smgr->update_late(delta_time_sec);
 #endif
 
@@ -636,13 +636,6 @@ static void fgIdleFunction ( void ) {
 
     } else if ( idle_state == 5 ) {
         idle_state++;
-#ifdef ENABLE_AUDIO_SUPPORT
-        ////////////////////////////////////////////////////////////////////
-        // Add the Sound Manager before any other subsystem that uses it.
-        // This makes sure the SoundMgr is available at construction time.
-        ////////////////////////////////////////////////////////////////////
-        globals->add_subsystem("soundmgr", new SGSoundMgr);
-#endif
 
         ////////////////////////////////////////////////////////////////////
         // Initialize the 3D aircraft model subsystem (has a dependency on
index a23a28d795d630e6d6747859b1dff6ee8d237abb..6074dcf95119fac9f1005a602c9ac081f6913c6b 100644 (file)
@@ -43,7 +43,7 @@ FGViewMgr::FGViewMgr( void ) :
   config_list(fgGetNode("/sim", true)->getChildren("view")),
   current(0)
 {
-    smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    smgr = globals->get_soundmgr();
 }
 
 // Destructor
index 1dcf2bd2297e63cb0dba19065aa231a1f166e0bc..65104a99022dea3094f2f670f51c374661939042 100644 (file)
@@ -48,8 +48,7 @@ FGAircraftModel::FGAircraftModel ()
     _speed_e(0),
     _speed_d(0)
 {
-    SGSoundMgr *smgr;
-    smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    SGSoundMgr *smgr = globals->get_soundmgr();
     _fx = new FGFX(smgr, "fx");
     _fx->init();
 }
index 497cbf03277ee37a143b1aef485e50b5bb21a9e3..4505017c93da03183788ebd3b2dbbf60b44b96b4 100644 (file)
@@ -21,7 +21,7 @@
 // $Id$
 
 
-#include <memory>
+#include <stdlib.h>
 
 #include "beacon.hxx"
 
@@ -39,13 +39,12 @@ FGBeacon::~FGBeacon() {
 
 // allocate and initialize sound samples
 bool FGBeacon::init() {
-    int i;
-    int len;
     unsigned char *ptr;
+    size_t i, len;
 
-    std::auto_ptr<unsigned char>inner_buf( new unsigned char[ INNER_SIZE ] );
-    std::auto_ptr<unsigned char>middle_buf( new unsigned char[ MIDDLE_SIZE ] );
-    std::auto_ptr<unsigned char>outer_buf( new unsigned char[ 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 );
@@ -53,14 +52,14 @@ bool FGBeacon::init() {
     make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
               TRANSITION_BYTES );
 
-    ptr = inner_buf.get();
+    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 );
 
@@ -75,12 +74,12 @@ bool FGBeacon::init() {
         make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
                    TRANSITION_BYTES );
 
-        ptr = middle_buf.get();
+        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 );
 
@@ -90,12 +89,12 @@ bool FGBeacon::init() {
         make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
                    TRANSITION_BYTES );
            
-        ptr = outer_buf.get();
+        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 ) {
index 0943b8a8613e50c50f0e54d98c1c84f01fee3d96..942b637a5a2ae46ecf1687994fdd2e82983ce386 100644 (file)
@@ -21,8 +21,6 @@
 // $Id$
 
 
-#include <memory>
-
 #include <simgear/constants.h>
 
 #include "morse.hxx"
@@ -221,10 +219,10 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) {
     length += 2 * SPACE_SIZE;
 
     // 2. Allocate space for the message
-    std::auto_ptr<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.get();
+    unsigned char *buf_ptr = (unsigned char*)buffer;
 
     for ( i = 0; i < (int)id.length(); ++i ) {
        if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) {
@@ -263,7 +261,7 @@ 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 );
 
     sample->set_reference_dist( 10.0 );