1
0
Fork 0

Added basic support for using more than one voice. The render function is moved out of ATCmgr and into the ATC base class.

This commit is contained in:
daveluff 2003-02-18 10:44:01 +00:00
parent 317e48ba4f
commit 0ecc199b09
7 changed files with 123 additions and 70 deletions

View file

@ -18,7 +18,12 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <Main/fgfs.hxx>
#include <Main/fg_props.hxx>
#include <Sound/soundmgr.hxx>
#include "ATC.hxx"
#include "ATCdisplay.hxx"
FGATC::~FGATC() {
}
@ -56,6 +61,60 @@ void FGATC::SetData(ATCData* d) {
freq = d->freq;
}
// Render a transmission
// 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 FGATC::Render(string msg, string refname, bool repeating) {
#ifdef ENABLE_AUDIO_SUPPORT
voice = (voiceOK && fgGetBool("/sim/sound/audible")
&& fgGetBool("/sim/sound/voice"));
if(voice) {
int len;
unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice);
if(voice) {
FGSimpleSound* simple = new FGSimpleSound(buf, len);
// 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("/radios/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;
}
#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.
void FGATC::NoRender(string refname) {
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;
}
}
ostream& operator << (ostream& os, atc_type atc) {
switch(atc) {
case(INVALID):

View file

@ -30,6 +30,8 @@
#include STL_IOSTREAM
#include STL_STRING
#include "ATCVoice.hxx"
SG_USING_STD(ostream);
SG_USING_STD(string);
SG_USING_STD(ios);
@ -111,12 +113,28 @@ public:
protected:
// Render a transmission
// 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 Render(string msg, string refname, bool repeating);
// Cease rendering a transmission.
// Requires the sound manager refname if audio, else "".
void NoRender(string refname);
double lon, lat, elev;
double x, y, z;
int freq;
int range;
string ident; // Code of the airport its at.
string name; // Name transmitted in the broadcast.
// Rendering related stuff
bool voice; // Flag - true if we are using voice
bool playing; // Indicates a message in progress
bool voiceOK; // Flag - true if at least one voice has loaded OK
FGATCVoice* vPtr;
};
inline istream&

View file

@ -23,8 +23,6 @@
# include <config.h>
#endif
#include <plib/sl.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx>

View file

@ -21,6 +21,8 @@
#ifndef _FG_ATC_VOICE
#define _FG_ATC_VOICE
#include <plib/sl.h>
#include <simgear/compiler.h>
#if defined( SG_HAVE_STD_INCLUDES ) || defined( __BORLANDC__ ) || (__APPLE__)

View file

@ -53,6 +53,7 @@ FGATCMgr::FGATCMgr() {
}
FGATCMgr::~FGATCMgr() {
delete v1;
}
void FGATCMgr::bind() {
@ -99,7 +100,9 @@ void FGATCMgr::init() {
// Load all available voices.
// For now we'll do one hardwired one
voiceOK = v1.LoadVoice("default");
v1 = new FGATCVoice;
voiceOK = v1->LoadVoice("default");
voice = true;
/* 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
@ -284,62 +287,36 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
return(NULL);
}
// Render a transmission
// 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 FGATCMgr::Render(string msg, string refname, bool repeating) {
#ifdef ENABLE_AUDIO_SUPPORT
voice = (voiceOK && fgGetBool("/sim/sound/audible")
&& fgGetBool("/sim/sound/voice"));
// Return a pointer to an appropriate voice for a given type of ATC
// creating the voice if necessary - ie. make sure exactly one copy
// of every voice in use exists in memory.
//
// TODO - in the future this will get more complex and dole out country/airport
// specific voices, and possible make sure that the same voice doesn't get used
// at different airports in quick succession if a large enough selection are available.
FGATCVoice* FGATCMgr::GetVoicePointer(atc_type type) {
// TODO - implement me better - maintain a list of loaded voices and other voices!!
if(voice) {
int len;
unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice);
if(voice) {
FGSimpleSound* simple = new FGSimpleSound(buf, len);
// 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("/radios/comm[0]/volume"));
globals->get_soundmgr()->add(simple, refname);
if(repeating) {
globals->get_soundmgr()->play_looped(refname);
} else {
globals->get_soundmgr()->play_once(refname);
switch(type) {
case ATIS:
if(voiceOK) {
return(v1);
}
case TOWER:
return(NULL);
case APPROACH:
return(NULL);
case GROUND:
return(NULL);
default:
return(NULL);
}
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.
void FGATCMgr::NoRender(string refname) {
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;
return(NULL);
} else {
return(NULL);
}
}
// Display a dialog box with options relevant to the currently tuned ATC service.
void FGATCMgr::doPopupDialog() {
ATCDoDialog(comm_type[0]); // FIXME - currently hardwired to comm1

View file

@ -24,7 +24,6 @@
#include <Main/fgfs.hxx>
#include <Main/fg_props.hxx>
#include <Sound/soundmgr.hxx>
#include <GUI/gui.h>
#include <string>
@ -131,13 +130,12 @@ private:
FGTower tower;
FGApproach approach;
//FGDeparture departure;
// Rendering related stuff
// Voice related stuff
bool voice; // Flag - true if we are using voice
bool playing; // Indicates a message in progress
#ifdef ENABLE_AUDIO_SUPPORT
bool voiceOK; // Flag - true if at least one voice has loaded OK
FGATCVoice v1;
FGATCVoice* v1;
#endif
public:
@ -159,19 +157,18 @@ 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 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 Render(string msg, string refname, bool repeating);
// Cease rendering a transmission.
// Requires the sound manager refname if audio, else "".
void NoRender(string refname);
// Display a dialog box with options relevant to the currently tuned ATC service.
void doPopupDialog();
// Return a pointer to an appropriate voice for a given type of ATC
// creating the voice if necessary - ie. make sure exactly one copy
// of every voice in use exists in memory.
//
// TODO - in the future this will get more complex and dole out country/airport
// specific voices, and possible make sure that the same voice doesn't get used
// at different airports in quick succession if a large enough selection are available.
FGATCVoice* GetVoicePointer(atc_type type);
atc_type GetComm1ATCType() { return(comm_type[0]); }
FGATC* GetComm1ATCPointer() { return(comm_atc_ptr[0]); }
atc_type GetComm2ATCType() { return(comm_type[1]); }

View file

@ -66,6 +66,8 @@ atis_failed(false),
refname("atis")
//type(ATIS)
{
vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
voiceOK = (vPtr == NULL ? false : true);
}
// Destructor
@ -83,14 +85,14 @@ void FGATIS::Update() {
// We need to get and display the message
UpdateTransmission();
//cout << "ATIS.CXX - calling ATCMgr to render transmission..." << endl;
globals->get_ATC_mgr()->Render(transmission, refname, true);
Render(transmission, refname, true);
displaying = true;
}
} else {
// We shouldn't be displaying
if(displaying) {
//cout << "ATIS.CXX - calling NoRender()..." << endl;
globals->get_ATC_mgr()->NoRender(refname);
NoRender(refname);
displaying = false;
}
}