Use shared pointers for any reference to SGSoundSample
This commit is contained in:
parent
f9445874a0
commit
430fbe99fa
13 changed files with 42 additions and 43 deletions
|
@ -29,8 +29,6 @@ using std::string;
|
||||||
|
|
||||||
#include "AIPlane.hxx"
|
#include "AIPlane.hxx"
|
||||||
|
|
||||||
SGSampleGroup *FGAIPlane::_sgr = 0;
|
|
||||||
|
|
||||||
FGAIPlane::FGAIPlane() {
|
FGAIPlane::FGAIPlane() {
|
||||||
leg = LEG_UNKNOWN;
|
leg = LEG_UNKNOWN;
|
||||||
tuned_station = NULL;
|
tuned_station = NULL;
|
||||||
|
@ -198,7 +196,7 @@ void FGAIPlane::Render(const string& refname, const float volume, bool repeating
|
||||||
voice = (voiceOK && fgGetBool("/sim/sound/voice"));
|
voice = (voiceOK && fgGetBool("/sim/sound/voice"));
|
||||||
if(voice) {
|
if(voice) {
|
||||||
sizte_t len;
|
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)) {
|
if(voice && (volume > 0.05)) {
|
||||||
SGSoundSample* simple = new SGSoundSample(buf, len, 8000 );
|
SGSoundSample* simple = new SGSoundSample(buf, len, 8000 );
|
||||||
simple->set_volume(volume);
|
simple->set_volume(volume);
|
||||||
|
|
|
@ -160,7 +160,7 @@ private:
|
||||||
double _tgtRoll;
|
double _tgtRoll;
|
||||||
bool _rollSuspended; // Set true when a derived class has suspended AIPlane's roll control
|
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
|
#endif // _FG_AI_PLANE_HXX
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <simgear/misc/sgstream.hxx>
|
#include <simgear/misc/sgstream.hxx>
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -212,7 +213,7 @@ protected:
|
||||||
bool _voiceOK; // Flag - true if at least one voice has loaded OK
|
bool _voiceOK; // Flag - true if at least one voice has loaded OK
|
||||||
FGATCVoice* _vPtr;
|
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
|
bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
|
||||||
|
|
|
@ -72,10 +72,10 @@ bool FGATCVoice::LoadVoice(const string& voice) {
|
||||||
|
|
||||||
string full_path = path.str();
|
string full_path = path.str();
|
||||||
int format, freq;
|
int format, freq;
|
||||||
SGSoundMgr *smgr = globals->get_soundmgr();
|
SGSoundMgr *smgr = globals->get_soundmgr();
|
||||||
void *data;
|
void *data;
|
||||||
if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq))
|
if (!smgr->load(full_path, &data, &format, &rawDataSize, &freq))
|
||||||
return false;
|
return false;
|
||||||
rawSoundData = (char*)data;
|
rawSoundData = (char*)data;
|
||||||
#ifdef VOICE_TEST
|
#ifdef VOICE_TEST
|
||||||
cout << "ATCVoice: format: " << format
|
cout << "ATCVoice: format: " << format
|
||||||
|
@ -118,7 +118,7 @@ bool FGATCVoice::LoadVoice(const string& voice) {
|
||||||
*p = tolower(*p);
|
*p = tolower(*p);
|
||||||
if (*p == '-') *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 << wrd << "\t\t" << wrdOffset << "\t\t" << wrdLength << '\n';
|
||||||
//cout << i << '\n';
|
//cout << i << '\n';
|
||||||
|
@ -134,7 +134,7 @@ typedef tokenList_type::iterator tokenList_iterator;
|
||||||
|
|
||||||
// Given a desired message, return a string containing the
|
// Given a desired message, return a string containing the
|
||||||
// sound-sample data
|
// 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?
|
// What should we do here?
|
||||||
// First - parse the message into a list of tokens.
|
// 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.
|
// 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.
|
// There is no need for this - 2 should be sufficient - we can probably ditch the tokenList.
|
||||||
size_t n1 = 1+strlen(message);
|
char* msg = (char *)message.c_str();
|
||||||
boost::shared_array<char> msg(new char[n1]);
|
|
||||||
strncpy(msg.get(), message, n1); // strtok requires a non-const char*
|
|
||||||
char* token;
|
char* token;
|
||||||
int numWords = 0;
|
int numWords = 0;
|
||||||
const char delimiters[] = " \t.,;:\"\n";
|
const char delimiters[] = " \t.,;:\"\n";
|
||||||
char* context;
|
char* context;
|
||||||
token = strtok_r(msg.get(), delimiters, &context);
|
token = strtok_r(msg, delimiters, &context);
|
||||||
while(token != NULL) {
|
while(token != NULL) {
|
||||||
for (char *t = token; *t; t++) {
|
for (char *t = token; *t; t++) {
|
||||||
*t = tolower(*t); // canonicalize the case, to
|
*t = tolower(*t); // canonicalize the case, to
|
||||||
|
@ -173,7 +171,7 @@ void* FGATCVoice::WriteMessage(const char* message, size_t* len) {
|
||||||
while(tokenListItr != tokenList.end()) {
|
while(tokenListItr != tokenList.end()) {
|
||||||
if(wordMap.find(*tokenListItr) == wordMap.end()) {
|
if(wordMap.find(*tokenListItr) == wordMap.end()) {
|
||||||
// Oh dear - the token isn't in the sound file
|
// 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");
|
<< *tokenListItr << "' not found");
|
||||||
} else {
|
} else {
|
||||||
wdptr.push_back(wordMap[*tokenListItr]);
|
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());
|
unsigned int offsetIn = (int)(cumLength * sg_random());
|
||||||
if(offsetIn > cumLength) offsetIn = cumLength;
|
if(offsetIn > cumLength) offsetIn = cumLength;
|
||||||
|
|
||||||
void *data = malloc(cumLength);
|
unsigned char *data = (unsigned char *)calloc(1, cumLength);
|
||||||
memcpy(data, tmpbuf.get(), cumLength);
|
|
||||||
*len = cumLength;
|
*len = cumLength;
|
||||||
// string front(tmpbuf.get(), offsetIn);
|
#if 0
|
||||||
// string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
|
memcpy(data, tmpbuf.get() + offsetIn, cumLength - offsetIn);
|
||||||
|
memcpy(data + cumLength - offsetIn, tmpbuf.get(), offsetIn);
|
||||||
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#define _FG_ATC_VOICE
|
#define _FG_ATC_VOICE
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#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.
|
// 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.
|
// 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:
|
private:
|
||||||
|
|
||||||
// the sound and word position data
|
// the sound and word position data
|
||||||
char* rawSoundData;
|
char* rawSoundData;
|
||||||
size_t rawDataSize;
|
size_t rawDataSize;
|
||||||
SGSoundSample *SoundData;
|
SGSharedPtr<SGSoundSample> SoundData;
|
||||||
|
|
||||||
// A map of words vs. byte position and length in rawSoundData
|
// A map of words vs. byte position and length in rawSoundData
|
||||||
atc_word_map_type wordMap;
|
atc_word_map_type wordMap;
|
||||||
|
|
|
@ -98,7 +98,7 @@ private:
|
||||||
float _last_volume;
|
float _last_volume;
|
||||||
string _adf_ident;
|
string _adf_ident;
|
||||||
|
|
||||||
SGSampleGroup *_sgr;
|
SGSharedPtr<SGSampleGroup> _sgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ class FGKR_87 : public SGSubsystem
|
||||||
// internal periodic station search timer
|
// internal periodic station search timer
|
||||||
double _time_before_search_sec;
|
double _time_before_search_sec;
|
||||||
|
|
||||||
SGSampleGroup *_sgr;
|
SGSharedPtr<SGSampleGroup> _sgr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class FGMarkerBeacon : public SGSubsystem
|
||||||
// internal periodic station search timer
|
// internal periodic station search timer
|
||||||
double _time_before_search_sec;
|
double _time_before_search_sec;
|
||||||
|
|
||||||
SGSampleGroup *_sgr;
|
SGSharedPtr<SGSampleGroup> _sgr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -2111,7 +2111,7 @@ MK_VIII::VoicePlayer::Speaker::bind (SGPropertyNode *node)
|
||||||
void
|
void
|
||||||
MK_VIII::VoicePlayer::Speaker::update_configuration ()
|
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++)
|
for (iter = player->samples.begin(); iter != player->samples.end(); iter++)
|
||||||
{
|
{
|
||||||
SGSoundSample *sample = (*iter).second;
|
SGSoundSample *sample = (*iter).second;
|
||||||
|
|
|
@ -747,11 +747,11 @@ public:
|
||||||
|
|
||||||
class SampleElement : public Element
|
class SampleElement : public Element
|
||||||
{
|
{
|
||||||
SGSoundSample *_sample;
|
SGSharedPtr<SGSoundSample> _sample;
|
||||||
float _volume;
|
float _volume;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline SampleElement (SGSoundSample *sample, float volume = 1.0)
|
inline SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
|
||||||
: _sample(sample), _volume(volume) { silence = false; }
|
: _sample(sample), _volume(volume) { silence = false; }
|
||||||
|
|
||||||
virtual inline void play (float volume) { if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); } }
|
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;
|
MK_VIII *mk;
|
||||||
|
|
||||||
SGSampleGroup *_sgr;
|
SGSharedPtr<SGSampleGroup> _sgr;
|
||||||
Speaker speaker;
|
Speaker speaker;
|
||||||
|
|
||||||
map<string, SGSoundSample *> samples;
|
map< string, SGSharedPtr<SGSoundSample> > samples;
|
||||||
vector<Voice *> _voices;
|
vector<Voice *> _voices;
|
||||||
|
|
||||||
bool looped;
|
bool looped;
|
||||||
|
|
|
@ -160,7 +160,7 @@ class FGNavRadio : public SGSubsystem
|
||||||
// realism setting, are false courses and GS lobes enabled?
|
// realism setting, are false courses and GS lobes enabled?
|
||||||
bool _falseCoursesEnabled;
|
bool _falseCoursesEnabled;
|
||||||
|
|
||||||
SGSampleGroup *_sgr;
|
SGSharedPtr<SGSampleGroup> _sgr;
|
||||||
|
|
||||||
bool updateWithPower(double aDt);
|
bool updateWithPower(double aDt);
|
||||||
|
|
||||||
|
|
|
@ -45,17 +45,17 @@ private:
|
||||||
|
|
||||||
SGModelPlacement * _aircraft;
|
SGModelPlacement * _aircraft;
|
||||||
SGVec3d _velocity;
|
SGVec3d _velocity;
|
||||||
FGFX * _fx;
|
SGSharedPtr<FGFX> _fx;
|
||||||
|
|
||||||
SGPropertyNode * _lon;
|
SGPropertyNode_ptr _lon;
|
||||||
SGPropertyNode * _lat;
|
SGPropertyNode_ptr _lat;
|
||||||
SGPropertyNode * _alt;
|
SGPropertyNode_ptr _alt;
|
||||||
SGPropertyNode * _pitch;
|
SGPropertyNode_ptr _pitch;
|
||||||
SGPropertyNode * _roll;
|
SGPropertyNode_ptr _roll;
|
||||||
SGPropertyNode * _heading;
|
SGPropertyNode_ptr _heading;
|
||||||
SGPropertyNode * _speed_n;
|
SGPropertyNode_ptr _speed_n;
|
||||||
SGPropertyNode * _speed_e;
|
SGPropertyNode_ptr _speed_e;
|
||||||
SGPropertyNode * _speed_d;
|
SGPropertyNode_ptr _speed_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __ACMODEL_HXX
|
#endif // __ACMODEL_HXX
|
||||||
|
|
|
@ -51,11 +51,11 @@ public:
|
||||||
|
|
||||||
virtual void update (double dt);
|
virtual void update (double dt);
|
||||||
|
|
||||||
inline void add (SGSoundSample *msg) { _messages.push(msg); }
|
inline void add (SGSharedPtr<SGSoundSample> msg) { _messages.push(msg); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::queue<SGSoundSample *> _messages;
|
std::queue< SGSharedPtr<SGSoundSample> > _messages;
|
||||||
|
|
||||||
bool last_pause;
|
bool last_pause;
|
||||||
double last_volume;
|
double last_volume;
|
||||||
|
|
Loading…
Add table
Reference in a new issue