X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FATCDCL%2FAIPlane.cxx;h=8fd67d13aeb190b837706c8996e27c339f068b90;hb=8b57675aef4930245a964816469be922e3004287;hp=f3bf43b8c2e8a6618ccead66178b330455844642;hpb=0824fe68f3fec838c3d0b8500966560c7397047e;p=flightgear.git diff --git a/src/ATCDCL/AIPlane.cxx b/src/ATCDCL/AIPlane.cxx index f3bf43b8c..8fd67d13a 100644 --- a/src/ATCDCL/AIPlane.cxx +++ b/src/ATCDCL/AIPlane.cxx @@ -47,6 +47,12 @@ FGAIPlane::FGAIPlane() { _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() { @@ -105,7 +111,9 @@ void FGAIPlane::Update(double dt) { 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. @@ -165,7 +173,10 @@ void FGAIPlane::ConditionalTransmit(double timeout, int callback_code) { } 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); } @@ -179,26 +190,19 @@ void FGAIPlane::ProcessCallback(int 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) { @@ -218,8 +222,8 @@ void FGAIPlane::NoRender(const string& refname) { 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;