From: ehofman Date: Sat, 24 Oct 2009 12:57:50 +0000 (+0000) Subject: Use shared pointers for any reference to SGSoundSample X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=430fbe99fa7a1fbb3649ccdedb31beab87a5c040;p=flightgear.git Use shared pointers for any reference to SGSoundSample --- diff --git a/src/ATCDCL/AIPlane.cxx b/src/ATCDCL/AIPlane.cxx index 3a46ee051..3f22dafa1 100644 --- a/src/ATCDCL/AIPlane.cxx +++ b/src/ATCDCL/AIPlane.cxx @@ -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); diff --git a/src/ATCDCL/AIPlane.hxx b/src/ATCDCL/AIPlane.hxx index e099cdfac..53158f929 100644 --- a/src/ATCDCL/AIPlane.hxx +++ b/src/ATCDCL/AIPlane.hxx @@ -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 _sgr; }; #endif // _FG_AI_PLANE_HXX diff --git a/src/ATCDCL/ATC.hxx b/src/ATCDCL/ATC.hxx index 8b05d6ca0..dd3fc8be2 100644 --- a/src/ATCDCL/ATC.hxx +++ b/src/ATCDCL/ATC.hxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -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 _sgr; // default sample group; bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog diff --git a/src/ATCDCL/ATCVoice.cxx b/src/ATCDCL/ATCVoice.cxx index 5659b1132..3648bfedd 100644 --- a/src/ATCDCL/ATCVoice.cxx +++ b/src/ATCDCL/ATCVoice.cxx @@ -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 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; } diff --git a/src/ATCDCL/ATCVoice.hxx b/src/ATCDCL/ATCVoice.hxx index 6ec4f3932..5128cc55d 100644 --- a/src/ATCDCL/ATCVoice.hxx +++ b/src/ATCDCL/ATCVoice.hxx @@ -22,6 +22,7 @@ #define _FG_ATC_VOICE #include +#include #include #include @@ -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 SoundData; // A map of words vs. byte position and length in rawSoundData atc_word_map_type wordMap; diff --git a/src/Instrumentation/adf.hxx b/src/Instrumentation/adf.hxx index 80de7d860..f2c2bdeb8 100644 --- a/src/Instrumentation/adf.hxx +++ b/src/Instrumentation/adf.hxx @@ -98,7 +98,7 @@ private: float _last_volume; string _adf_ident; - SGSampleGroup *_sgr; + SGSharedPtr _sgr; }; diff --git a/src/Instrumentation/kr_87.hxx b/src/Instrumentation/kr_87.hxx index 0653b06d9..e59beba7b 100644 --- a/src/Instrumentation/kr_87.hxx +++ b/src/Instrumentation/kr_87.hxx @@ -105,7 +105,7 @@ class FGKR_87 : public SGSubsystem // internal periodic station search timer double _time_before_search_sec; - SGSampleGroup *_sgr; + SGSharedPtr _sgr; public: diff --git a/src/Instrumentation/marker_beacon.hxx b/src/Instrumentation/marker_beacon.hxx index 774e37f81..3a98c11cd 100644 --- a/src/Instrumentation/marker_beacon.hxx +++ b/src/Instrumentation/marker_beacon.hxx @@ -74,7 +74,7 @@ class FGMarkerBeacon : public SGSubsystem // internal periodic station search timer double _time_before_search_sec; - SGSampleGroup *_sgr; + SGSharedPtr _sgr; public: diff --git a/src/Instrumentation/mk_viii.cxx b/src/Instrumentation/mk_viii.cxx index f2a4dba2c..a3073136a 100755 --- a/src/Instrumentation/mk_viii.cxx +++ b/src/Instrumentation/mk_viii.cxx @@ -2111,7 +2111,7 @@ MK_VIII::VoicePlayer::Speaker::bind (SGPropertyNode *node) void MK_VIII::VoicePlayer::Speaker::update_configuration () { - map::iterator iter; + map< string, SGSharedPtr >::iterator iter; for (iter = player->samples.begin(); iter != player->samples.end(); iter++) { SGSoundSample *sample = (*iter).second; diff --git a/src/Instrumentation/mk_viii.hxx b/src/Instrumentation/mk_viii.hxx index 077ea52ab..3e48ea2b4 100755 --- a/src/Instrumentation/mk_viii.hxx +++ b/src/Instrumentation/mk_viii.hxx @@ -747,11 +747,11 @@ public: class SampleElement : public Element { - SGSoundSample *_sample; - float _volume; + SGSharedPtr _sample; + float _volume; public: - inline SampleElement (SGSoundSample *sample, float volume = 1.0) + inline SampleElement (SGSharedPtr 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 _sgr; Speaker speaker; - map samples; + map< string, SGSharedPtr > samples; vector _voices; bool looped; diff --git a/src/Instrumentation/navradio.hxx b/src/Instrumentation/navradio.hxx index 978e77d6f..6dbe3b78e 100644 --- a/src/Instrumentation/navradio.hxx +++ b/src/Instrumentation/navradio.hxx @@ -160,7 +160,7 @@ class FGNavRadio : public SGSubsystem // realism setting, are false courses and GS lobes enabled? bool _falseCoursesEnabled; - SGSampleGroup *_sgr; + SGSharedPtr _sgr; bool updateWithPower(double aDt); diff --git a/src/Model/acmodel.hxx b/src/Model/acmodel.hxx index c751b699c..f9917a1d7 100644 --- a/src/Model/acmodel.hxx +++ b/src/Model/acmodel.hxx @@ -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 _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 diff --git a/src/Sound/sample_queue.hxx b/src/Sound/sample_queue.hxx index c874ae3eb..88b30ae75 100644 --- a/src/Sound/sample_queue.hxx +++ b/src/Sound/sample_queue.hxx @@ -51,11 +51,11 @@ public: virtual void update (double dt); - inline void add (SGSoundSample *msg) { _messages.push(msg); } + inline void add (SGSharedPtr msg) { _messages.push(msg); } private: - std::queue _messages; + std::queue< SGSharedPtr > _messages; bool last_pause; double last_volume;