]> git.mxchange.org Git - flightgear.git/commitdiff
Use shared pointers for any reference to SGSoundSample
authorehofman <ehofman>
Sat, 24 Oct 2009 12:57:50 +0000 (12:57 +0000)
committerTim Moore <timoore@redhat.com>
Sat, 24 Oct 2009 17:52:09 +0000 (19:52 +0200)
13 files changed:
src/ATCDCL/AIPlane.cxx
src/ATCDCL/AIPlane.hxx
src/ATCDCL/ATC.hxx
src/ATCDCL/ATCVoice.cxx
src/ATCDCL/ATCVoice.hxx
src/Instrumentation/adf.hxx
src/Instrumentation/kr_87.hxx
src/Instrumentation/marker_beacon.hxx
src/Instrumentation/mk_viii.cxx
src/Instrumentation/mk_viii.hxx
src/Instrumentation/navradio.hxx
src/Model/acmodel.hxx
src/Sound/sample_queue.hxx

index 3a46ee051932eb0c06df859d7d623a293205aca4..3f22dafa15cb1b1171dc51e7dec66c2107562fb1 100644 (file)
@@ -29,8 +29,6 @@ using std::string;
 
 #include "AIPlane.hxx"
 
-SGSampleGroup *FGAIPlane::_sgr = 0;
-
 FGAIPlane::FGAIPlane() {
        leg = LEG_UNKNOWN;
        tuned_station = NULL;
@@ -198,7 +196,7 @@ void FGAIPlane::Render(const string& refname, const float volume, bool repeating
        voice = (voiceOK && fgGetBool("/sim/sound/voice"));
        if(voice) {
             sizte_t len;
-           void* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), voice, &len);
+           void* buf = vPtr->WriteMessage(pending_transmission, &len);
            if(voice && (volume > 0.05)) {
                SGSoundSample* simple = new SGSoundSample(buf, len, 8000 );
                simple->set_volume(volume);
index e099cdfac1132626d64ab75afd597b6f938dcf70..53158f9296c5d9081b8176e40773fedfec3fe57b 100644 (file)
@@ -160,7 +160,7 @@ private:
        double _tgtRoll;
        bool _rollSuspended;    // Set true when a derived class has suspended AIPlane's roll control
 
-        static SGSampleGroup *_sgr;
+        SGSharedPtr<SGSampleGroup> _sgr;
 };
 
 #endif  // _FG_AI_PLANE_HXX
index 8b05d6ca08293fd5c6a7ebdd764a8c8ca03fe457..dd3fc8be2433bc71c95d8c16a156aa113d45f8fd 100644 (file)
@@ -27,6 +27,7 @@
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 
 #include <iosfwd>
 #include <string>
@@ -212,7 +213,7 @@ protected:
        bool _voiceOK;  // Flag - true if at least one voice has loaded OK
        FGATCVoice* _vPtr;
 
-       SGSampleGroup *_sgr; // default sample group;
+       SGSharedPtr<SGSampleGroup> _sgr; // default sample group;
 
        
        bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
index 5659b1132cfad76bbecbde1701bc9e585c5bb66d..3648bfedd49f1ab7643b16f3edb01fc44d6f49a0 100644 (file)
@@ -72,10 +72,10 @@ bool FGATCVoice::LoadVoice(const string& voice) {
        
        string full_path = path.str();
        int format, freq;
-        SGSoundMgr *smgr = globals->get_soundmgr();
+       SGSoundMgr *smgr = globals->get_soundmgr();
        void *data;
-        if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq))
-            return false;
+       if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq))
+           return false;
        rawSoundData = (char*)data;
 #ifdef VOICE_TEST
        cout << "ATCVoice:  format: " << format
@@ -118,7 +118,7 @@ bool FGATCVoice::LoadVoice(const string& voice) {
                  *p = tolower(*p);
                  if (*p == '-') *p = '_';
                }
-               if (wrdstr != ws2) wordMap[ws2] = wd;
+               if (wrdstr != ws2)  wordMap[ws2] = wd;
 
                //cout << wrd << "\t\t" << wrdOffset << "\t\t" << wrdLength << '\n';
                //cout << i << '\n';
@@ -134,7 +134,7 @@ typedef tokenList_type::iterator tokenList_iterator;
 
 // Given a desired message, return a string containing the
 // sound-sample data
-void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
+void* FGATCVoice::WriteMessage(const string& message, size_t* len) {
        
        // What should we do here?
        // First - parse the message into a list of tokens.
@@ -145,14 +145,12 @@ void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
 
        // TODO - at the moment we're effectively taking 3 passes through the data.
        // There is no need for this - 2 should be sufficient - we can probably ditch the tokenList.
-       size_t n1 = 1+strlen(message);
-       boost::shared_array<char> msg(new char[n1]);
-       strncpy(msg.get(), message, n1); // strtok requires a non-const char*
+        char* msg = (char *)message.c_str();
        char* token;
        int numWords = 0;
        const char delimiters[] = " \t.,;:\"\n";
        char* context;
-       token = strtok_r(msg.get(), delimiters, &context);
+       token = strtok_r(msg, delimiters, &context);
        while(token != NULL) {
                for (char *t = token; *t; t++) {
                  *t = tolower(*t);     // canonicalize the case, to
@@ -173,7 +171,7 @@ void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
        while(tokenListItr != tokenList.end()) {
                if(wordMap.find(*tokenListItr) == wordMap.end()) {
                // Oh dear - the token isn't in the sound file
-                 SG_LOG(SG_ATC, SG_ALERT, "voice synth: word '"
+                 SG_LOG(SG_ATC, SG_DEBUG, "voice synth: word '"
                      << *tokenListItr << "' not found");
                } else {
                    wdptr.push_back(wordMap[*tokenListItr]);
@@ -213,11 +211,12 @@ void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
        unsigned int offsetIn = (int)(cumLength * sg_random());
        if(offsetIn > cumLength) offsetIn = cumLength;
 
-       void *data = malloc(cumLength);
-       memcpy(data, tmpbuf.get(), cumLength);
+       unsigned char *data = (unsigned char *)calloc(1, cumLength);
        *len = cumLength;
-       // string front(tmpbuf.get(), offsetIn);
-       // string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
+#if 0
+memcpy(data, tmpbuf.get() + offsetIn, cumLength - offsetIn);
+       memcpy(data + cumLength - offsetIn, tmpbuf.get(), offsetIn);
+#endif
 
        return data;
 }
index 6ec4f39324ad7e62e8dc08956abe82cd67821b5b..5128cc55dda2fc0654d3405f59370b6e3946de69 100644 (file)
@@ -22,6 +22,7 @@
 #define _FG_ATC_VOICE
 
 #include <simgear/compiler.h>
+#include <simgear/structure/SGSharedPtr.hxx>
 
 #include <map>
 #include <string>
@@ -50,14 +51,14 @@ public:
        
        // Given a desired message, return a pointer to the data buffer and write the buffer length into len.
        // Sets len to something other than 0 if the returned buffer is valid.
-       void* WriteMessage(const char* message, size_t *len);
+       void* WriteMessage(const std::string& message, size_t *len);
 
 private:
 
        // the sound and word position data
        char* rawSoundData;
        size_t rawDataSize;
-        SGSoundSample *SoundData;
+        SGSharedPtr<SGSoundSample> SoundData;
 
        // A map of words vs. byte position and length in rawSoundData
        atc_word_map_type wordMap;
index 80de7d86046190e23a8bb0ac2c1bd2cf5a18c8d2..f2c2bdeb8a84ffaf6997469116f252bd3ee79575 100644 (file)
@@ -98,7 +98,7 @@ private:
     float _last_volume;
     string _adf_ident;
 
-    SGSampleGroup *_sgr;
+    SGSharedPtr<SGSampleGroup> _sgr;
 };
 
 
index 0653b06d9833bced5749c01b72d0390dc7fff665..e59beba7b729cc2b6a340f000a8b69ff95b84f13 100644 (file)
@@ -105,7 +105,7 @@ class FGKR_87 : public SGSubsystem
     // internal periodic station search timer
     double _time_before_search_sec;
 
-    SGSampleGroup *_sgr;
+    SGSharedPtr<SGSampleGroup> _sgr;
 
 public:
 
index 774e37f81267b3d88cba349a140caa981d335b39..3a98c11cd7accea4ae07f3174e125f3febe3df39 100644 (file)
@@ -74,7 +74,7 @@ class FGMarkerBeacon : public SGSubsystem
     // internal periodic station search timer
     double _time_before_search_sec;
 
-    SGSampleGroup *_sgr;
+    SGSharedPtr<SGSampleGroup> _sgr;
 
 public:
 
index f2a4dba2c3801503c5201cb007fb6644ade16d15..a3073136a713076b46d5c5befa365d1759f1ac39 100755 (executable)
@@ -2111,7 +2111,7 @@ MK_VIII::VoicePlayer::Speaker::bind (SGPropertyNode *node)
 void
 MK_VIII::VoicePlayer::Speaker::update_configuration ()
 {
-  map<string, SGSoundSample *>::iterator iter;
+  map< string, SGSharedPtr<SGSoundSample> >::iterator iter;
   for (iter = player->samples.begin(); iter != player->samples.end(); iter++)
     {
       SGSoundSample *sample = (*iter).second;
index 077ea52aba5e575590dbe7bc034f28a8ba599280..3e48ea2b4807eb1f66fed8db93d6f9f20e7c9b99 100755 (executable)
@@ -747,11 +747,11 @@ public:
 
       class SampleElement : public Element
       {
-       SGSoundSample   *_sample;
-       float           _volume;
+       SGSharedPtr<SGSoundSample>      _sample;
+       float                           _volume;
 
       public:
-       inline SampleElement (SGSoundSample *sample, float volume = 1.0)
+       inline SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
          : _sample(sample), _volume(volume) { silence = false; }
 
         virtual inline void play (float volume) { if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); } }
@@ -928,10 +928,10 @@ public:
 
     MK_VIII *mk;
 
-    SGSampleGroup *_sgr;
+    SGSharedPtr<SGSampleGroup> _sgr;
     Speaker speaker;
 
-    map<string, SGSoundSample *>       samples;
+    map< string, SGSharedPtr<SGSoundSample> >  samples;
     vector<Voice *>                    _voices;
 
     bool looped;
index 978e77d6f9da33cb6f7417d464f9a4ec1926ba62..6dbe3b78e1775afaf91516ef316f96d276dfb9bc 100644 (file)
@@ -160,7 +160,7 @@ class FGNavRadio : public SGSubsystem
     // realism setting, are false courses and GS lobes enabled?
     bool _falseCoursesEnabled;
 
-    SGSampleGroup *_sgr;
+    SGSharedPtr<SGSampleGroup> _sgr;
     
     bool updateWithPower(double aDt);
 
index c751b699c6a54b68ee4c3ea501da390dd6c37c39..f9917a1d79ebcdf250a4ddda042a7d1bb00aa5b2 100644 (file)
@@ -45,17 +45,17 @@ private:
 
   SGModelPlacement * _aircraft;
   SGVec3d _velocity;
-  FGFX * _fx;
-
-  SGPropertyNode * _lon;
-  SGPropertyNode * _lat;
-  SGPropertyNode * _alt;
-  SGPropertyNode * _pitch;
-  SGPropertyNode * _roll;
-  SGPropertyNode * _heading;
-  SGPropertyNode * _speed_n;
-  SGPropertyNode * _speed_e;
-  SGPropertyNode * _speed_d;
+  SGSharedPtr<FGFX>  _fx;
+
+  SGPropertyNode_ptr _lon;
+  SGPropertyNode_ptr _lat;
+  SGPropertyNode_ptr _alt;
+  SGPropertyNode_ptr _pitch;
+  SGPropertyNode_ptr _roll;
+  SGPropertyNode_ptr _heading;
+  SGPropertyNode_ptr _speed_n;
+  SGPropertyNode_ptr _speed_e;
+  SGPropertyNode_ptr _speed_d;
 };
 
 #endif // __ACMODEL_HXX
index c874ae3eb2eada42a9c0d0c3f145ef5b32a97369..88b30ae757f8641dea0ced9fda68bd5231a5bec5 100644 (file)
@@ -51,11 +51,11 @@ public:
 
     virtual void update (double dt);
 
-    inline void add (SGSoundSample *msg) { _messages.push(msg); }
+    inline void add (SGSharedPtr<SGSoundSample> msg) { _messages.push(msg); }
 
 private:
 
-    std::queue<SGSoundSample *> _messages;
+    std::queue< SGSharedPtr<SGSoundSample> > _messages;
 
     bool last_pause;
     double last_volume;