#include "AIPlane.hxx"
-SGSampleGroup *FGAIPlane::_sgr = 0;
-
FGAIPlane::FGAIPlane() {
leg = LEG_UNKNOWN;
tuned_station = NULL;
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);
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
#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>
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
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
*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';
// 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.
// 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
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]);
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;
}
#define _FG_ATC_VOICE
#include <simgear/compiler.h>
+#include <simgear/structure/SGSharedPtr.hxx>
#include <map>
#include <string>
// 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;
float _last_volume;
string _adf_ident;
- SGSampleGroup *_sgr;
+ SGSharedPtr<SGSampleGroup> _sgr;
};
// internal periodic station search timer
double _time_before_search_sec;
- SGSampleGroup *_sgr;
+ SGSharedPtr<SGSampleGroup> _sgr;
public:
// internal periodic station search timer
double _time_before_search_sec;
- SGSampleGroup *_sgr;
+ SGSharedPtr<SGSampleGroup> _sgr;
public:
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;
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(); } }
MK_VIII *mk;
- SGSampleGroup *_sgr;
+ SGSharedPtr<SGSampleGroup> _sgr;
Speaker speaker;
- map<string, SGSoundSample *> samples;
+ map< string, SGSharedPtr<SGSoundSample> > samples;
vector<Voice *> _voices;
bool looped;
// realism setting, are false courses and GS lobes enabled?
bool _falseCoursesEnabled;
- SGSampleGroup *_sgr;
+ SGSharedPtr<SGSampleGroup> _sgr;
bool updateWithPower(double aDt);
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
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;