Changes to support voice rendering of ATC
This commit is contained in:
parent
d3e33e8b53
commit
c65c5f3a4a
2 changed files with 439 additions and 349 deletions
|
@ -20,11 +20,15 @@
|
|||
|
||||
//#include <Time/event.hxx>
|
||||
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include "ATCmgr.hxx"
|
||||
#include "atislist.hxx"
|
||||
//#include "groundlist.hxx"
|
||||
#include "towerlist.hxx"
|
||||
#include "approachlist.hxx"
|
||||
#include "ATCdisplay.hxx"
|
||||
|
||||
/*
|
||||
// periodic radio station search wrapper
|
||||
|
@ -86,6 +90,17 @@ void FGATCMgr::init() {
|
|||
//a->set_by_comm_search = false;
|
||||
|
||||
airport_atc_map[(string)"KEMT"] = a;
|
||||
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
// Load all available voices.
|
||||
// For now we'll do one hardwired one
|
||||
voiceOK = v1.LoadVoice("default");
|
||||
/* I've loaded the voice even if /sim/sound/audible is false
|
||||
* since I know no way of forcing load of the voice if the user
|
||||
* subsequently switches /sim/sound/audible to true. */
|
||||
#else
|
||||
voice = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void FGATCMgr::update(double dt) {
|
||||
|
@ -121,7 +136,9 @@ void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp) {
|
|||
return;
|
||||
} else {
|
||||
// remove
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Remove from list - should only be called from above or similar
|
||||
|
@ -146,6 +163,7 @@ void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//DCL - this routine untested so far.
|
||||
// Find in list - return a currently active ATC pointer given ICAO code and type
|
||||
FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
|
||||
|
@ -158,7 +176,7 @@ FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
|
|||
++atc_list_itr;
|
||||
}
|
||||
// We need a fallback position
|
||||
cout << "*** Failed to find FGATC* in FGATCMgr::FindInList - this should not happen!" << endl;
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "*** Failed to find FGATC* in FGATCMgr::FindInList - this should not happen!");
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
@ -175,6 +193,8 @@ bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
|
|||
|
||||
// Return a pointer to a given sort of ATC at a given airport and activate if necessary
|
||||
// ONLY CALL THIS FUNCTION AFTER FIRST CHECKING THE SERVICE EXISTS BY CALLING GetAirportATCDetails
|
||||
// FIXME - we really ought to take out the necessity for two function calls by simply returning
|
||||
// a NULL pointer if the service doesn't exist and requiring the caller to check for it (NULL).
|
||||
FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
|
||||
AirportATC *a = airport_atc_map[icao];
|
||||
//cout << "a->lon = " << a->lon << '\n';
|
||||
|
@ -202,7 +222,7 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
|
|||
case APPROACH:
|
||||
break;
|
||||
case ATIS:
|
||||
cout << "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer" << endl;
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer");
|
||||
break;
|
||||
case GROUND:
|
||||
break;
|
||||
|
@ -214,12 +234,62 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
|
|||
break;
|
||||
}
|
||||
|
||||
cout << "ERROR IN FGATCMgr - reached end of GetATCPointer\n";
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR IN FGATCMgr - reached end of GetATCPointer");
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
// Render a transmission
|
||||
// Outputs the transmission either on screen or as audio depending on user preference
|
||||
// The repeating flag indicates whether the message should be repeated continuously or played once.
|
||||
void FGATCMgr::Render(string msg, bool repeating) {
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
voice = voiceOK && fgGetBool("/sim/sound/audible");
|
||||
if(voice) {
|
||||
int len;
|
||||
unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice);
|
||||
if(voice) {
|
||||
FGSimpleSound* simple = new FGSimpleSound(buf, len);
|
||||
simple->set_volume(2.0);
|
||||
globals->get_soundmgr()->add(simple, refname);
|
||||
if(repeating) {
|
||||
globals->get_soundmgr()->play_looped(refname);
|
||||
} else {
|
||||
globals->get_soundmgr()->play_once(refname);
|
||||
}
|
||||
}
|
||||
delete[] buf;
|
||||
}
|
||||
#endif // ENABLE_AUDIO_SUPPORT
|
||||
if(!voice) {
|
||||
// first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
|
||||
for(unsigned int i = 0; i < msg.length(); ++i) {
|
||||
if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
|
||||
msg[i] = ' ';
|
||||
}
|
||||
}
|
||||
globals->get_ATC_display()->RegisterRepeatingMessage(msg);
|
||||
}
|
||||
playing = true;
|
||||
}
|
||||
|
||||
|
||||
// Cease rendering a transmission.
|
||||
// At the moment this can handle one transmission active at a time only.
|
||||
void FGATCMgr::NoRender() {
|
||||
if(playing) {
|
||||
if(voice) {
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
globals->get_soundmgr()->stop(refname);
|
||||
globals->get_soundmgr()->remove(refname);
|
||||
#endif
|
||||
} else {
|
||||
globals->get_ATC_display()->CancelRepeatingMessage();
|
||||
}
|
||||
playing = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FGATCMgr::Search() {
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <Main/fgfs.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Sound/soundmgr.hxx>
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
@ -32,8 +33,9 @@
|
|||
#include "atis.hxx"
|
||||
#include "tower.hxx"
|
||||
#include "approach.hxx"
|
||||
//#include "ground.hxx"
|
||||
#include "ground.hxx"
|
||||
#include "ATC.hxx"
|
||||
#include "ATCVoice.hxx"
|
||||
|
||||
SG_USING_STD(string);
|
||||
SG_USING_STD(list);
|
||||
|
@ -143,6 +145,15 @@ private:
|
|||
FGApproach approach;
|
||||
//FGDeparture departure;
|
||||
|
||||
// Rendering related stuff
|
||||
bool voice; // Flag - true if we are using voice
|
||||
bool playing; // Indicates a message in progress
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
string refname; // FIXME - A hack - assumes only one sound to track.
|
||||
bool voiceOK; // Flag - true if at least one voice has loaded OK
|
||||
FGATCVoice v1;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
FGATCMgr();
|
||||
|
@ -162,6 +173,15 @@ public:
|
|||
// Return a pointer to a given sort of ATC at a given airport and activate if necessary
|
||||
FGATC* GetATCPointer(string icao, atc_type type);
|
||||
|
||||
// Render a transmission
|
||||
// Outputs the transmission either on screen or as audio depending on user preference
|
||||
// The repeating flag indicates whether the message should be repeated continuously or played once.
|
||||
void Render(string msg, bool repeating);
|
||||
|
||||
// Cease rendering a transmission.
|
||||
// At the moment this can handle one transmission active at a time only.
|
||||
void NoRender();
|
||||
|
||||
private:
|
||||
|
||||
// Remove a class from the atc_list and delete it from memory
|
||||
|
|
Loading…
Add table
Reference in a new issue