#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
-#include <simgear/math/point3d.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
#include <math.h>
#include <string>
-SG_USING_STD(string);
+using std::string;
#include "AIPlane.hxx"
_trackSet = false;
_tgtRoll = 0.0;
_rollSuspended = false;
+
+ if ( !_sgr ) {
+ SGSoundMgr *smgr = globals->get_soundmgr();
+ _sgr = smgr->find("atc", true);
+ _sgr->tie_to_listener();
+ }
}
FGAIPlane::~FGAIPlane() {
if(1) {
// For now assume in range !!!
// TODO - implement range checking
- Render(plane.callsign, false);
+ // TODO - at the moment the volume is always set off comm1
+ float volume = fgGetFloat("/instrumentation/comm[0]/volume");
+ Render(plane.callsign, volume, false);
}
}
// Run the callback regardless of whether on same freq as user or not.
}
void FGAIPlane::ImmediateTransmit(int callback_code) {
- Render(plane.callsign, false);
+ // TODO - at the moment the volume is always set off comm1
+ float volume = fgGetFloat("/instrumentation/comm[0]/volume");
+
+ Render(plane.callsign, volume, false);
if(callback_code) {
ProcessCallback(callback_code);
}
// Outputs the transmission either on screen or as audio depending on user preference
// The refname is a string to identify this sample to the sound manager
// The repeating flag indicates whether the message should be repeated continuously or played once.
-void FGAIPlane::Render(const string& refname, bool repeating) {
+void FGAIPlane::Render(const string& refname, const float volume, bool repeating) {
fgSetString("/sim/messages/ai-plane", pending_transmission.c_str());
#ifdef ENABLE_AUDIO_SUPPORT
voice = (voiceOK && fgGetBool("/sim/sound/voice"));
if(voice) {
- int len;
- unsigned char* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), len, voice);
- if(voice) {
- SGSoundSample* simple = new SGSoundSample(buf, len, 8000);
- // TODO - at the moment the volume is always set off comm1
- // and can't be changed after the transmission has started.
- simple->set_volume(5.0 * fgGetDouble("/instrumentation/comm[0]/volume"));
- globals->get_soundmgr()->add(simple, refname);
- if(repeating) {
- globals->get_soundmgr()->play_looped(refname);
- } else {
- globals->get_soundmgr()->play_once(refname);
- }
- }
- delete[] buf;
+ size_t len;
+ void* buf = vPtr->WriteMessage(pending_transmission, &len);
+ if(voice && (volume > 0.05)) {
+ SGSoundSample* simple = new SGSoundSample(&buf, len, 8000 );
+ simple->set_volume(volume);
+ _sgr->add(simple, refname);
+ _sgr->play(refname, repeating);
+ }
}
#endif // ENABLE_AUDIO_SUPPORT
if(!voice) {
if(playing) {
if(voice) {
#ifdef ENABLE_AUDIO_SUPPORT
- globals->get_soundmgr()->stop(refname);
- globals->get_soundmgr()->remove(refname);
+ _sgr->stop(refname);
+ _sgr->remove(refname);
#endif
}
playing = false;