1
0
Fork 0

Use shared pointers for any reference to SGSoundSample

This commit is contained in:
ehofman 2009-10-24 12:57:50 +00:00 committed by Tim Moore
parent f9445874a0
commit 430fbe99fa
13 changed files with 42 additions and 43 deletions

View 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);

View 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

View 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

View 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;
}

View 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;

View file

@ -98,7 +98,7 @@ private:
float _last_volume;
string _adf_ident;
SGSampleGroup *_sgr;
SGSharedPtr<SGSampleGroup> _sgr;
};

View 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:

View 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:

View file

@ -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;

View file

@ -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;

View 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);

View file

@ -45,17 +45,17 @@ private:
SGModelPlacement * _aircraft;
SGVec3d _velocity;
FGFX * _fx;
SGSharedPtr<FGFX> _fx;
SGPropertyNode * _lon;
SGPropertyNode * _lat;
SGPropertyNode * _alt;
SGPropertyNode * _pitch;
SGPropertyNode * _roll;
SGPropertyNode * _heading;
SGPropertyNode * _speed_n;
SGPropertyNode * _speed_e;
SGPropertyNode * _speed_d;
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

View 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;