]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/voiceplayer.cxx
apt.dat parser: clearer log and exception messages
[flightgear.git] / src / Sound / voiceplayer.cxx
index de178b70e7fdf04e8c1a13444fc7598ea99fe07e..c4ca5d2bdb33e2b54df71be1c9d729d977ad540b 100644 (file)
@@ -33,7 +33,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
-#include <math.h>
+#include <cmath>
 
 #include <string>
 #include <sstream>
@@ -65,6 +65,12 @@ using std::vector;
 // FGVoicePlayer::Voice::SampleElement ///////////////////////////
 /////////////////////////////////////////////////////////////////////////
 
+FGVoicePlayer::Voice::SampleElement::SampleElement (SGSharedPtr<SGSoundSample> sample, float volume)
+: _sample(sample), _volume(volume)
+{
+  silence = false;
+}
+
 void FGVoicePlayer::Voice::SampleElement::play (float volume)
 {
   if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); }
@@ -179,7 +185,9 @@ FGVoicePlayer::FGVoicePlayer (PropertiesHandler* properties_handler, string _dev
 : volume(1.0), voice(NULL), next_voice(NULL), paused(false),
 dev_name(_dev_name), dir_prefix(""),
 speaker(this,properties_handler)
-{}
+{
+  _sgr = NULL;
+}
 
 FGVoicePlayer::~FGVoicePlayer ()
 {
@@ -200,7 +208,7 @@ FGVoicePlayer::bind (SGPropertyNode *node, const char* default_dir_prefix)
 void
 FGVoicePlayer::init ()
 {
-    SGSoundMgr *smgr = globals->get_soundmgr();
+    SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
     _sgr = smgr->find("avionics", true);
     _sgr->tie_to_listener();
     speaker.update_configuration();
@@ -241,16 +249,8 @@ FGVoicePlayer::get_sample (const char *name)
     if (! sample)
     {
         string filename = dir_prefix + string(name) + ".wav";
-        try
-        {
-            sample = new SGSoundSample(filename.c_str(), SGPath());
-        }
-        catch (const sg_exception &e)
-        {
-            SG_LOG(SG_SOUND, SG_ALERT, "Error loading sound sample \"" + filename + "\": " + e.getFormattedMessage());
-            exit(1);
-        }
-
+        sample = new SGSoundSample(filename.c_str(), SGPath());
+        
         _sgr->add(sample, refname);
         samples[refname] = sample;
     }
@@ -339,3 +339,10 @@ FGVoicePlayer::update ()
         }
     }
 }
+
+void
+FGVoicePlayer::append (Voice *voice, const char *sample_name)
+{
+  voice->append(new Voice::SampleElement(get_sample(sample_name)));
+}
+