]> git.mxchange.org Git - flightgear.git/commitdiff
Added basic support for using more than one voice. The render function is moved...
authordaveluff <daveluff>
Tue, 18 Feb 2003 10:44:01 +0000 (10:44 +0000)
committerdaveluff <daveluff>
Tue, 18 Feb 2003 10:44:01 +0000 (10:44 +0000)
src/ATC/ATC.cxx
src/ATC/ATC.hxx
src/ATC/ATCVoice.cxx
src/ATC/ATCVoice.hxx
src/ATC/ATCmgr.cxx
src/ATC/ATCmgr.hxx
src/ATC/atis.cxx

index 24c0c0d605b609cb7c45274cdb0f7ddbed9e7ac8..2f4d944fb3d7791b67d338478d557ce134b78ee0 100644 (file)
 // 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):
index 1babf06f7208d7d74d27be09f56cfbcac290e5c7..2dda84e0bacc5d3da30e7ed87d1db707a23e4bf5 100644 (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&
index 0ebc217fb163871d6e8d182cc9762c121d68b2aa..3a7c427a651d9cbcee1e93438c773e0fc714f758 100644 (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>
index 8edd8953eb8bdba410ea7b14a8f2528239efafbe..657e5ecb20301ec4cd761d933a0d1f3b606057af 100644 (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__)
index 838de9c7f2e93784c70a63ed9ab4240acc6dd589..412664aee16a28d5facb830fb87c450e38c1d45e 100644 (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);
-                       }
-               }
-               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] = ' ';
+               switch(type) {
+               case ATIS:
+                       if(voiceOK) {
+                               return(v1);
                        }
+               case TOWER:
+                       return(NULL);
+               case APPROACH:
+                       return(NULL);
+               case GROUND:
+                       return(NULL);
+               default:
+                       return(NULL);
                }
-               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
index 284d312113f8736b41b0dfc5c1bb4b341d295b48..992e87f3c9e95dc0992e2ec0b601a296a11fb03c 100644 (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]); }
index 344a3bc2ea39544a29fe2bb808a51ccf0cb5c9bc..cc4f1618a07f7036871755a874d40547c85076a2 100644 (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;
                }
        }