]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/voiceplayer.cxx
Flight-history men usage cap.
[flightgear.git] / src / Sound / voiceplayer.cxx
index 2cd2f127c1fa44974864f2cd19d3f2d383127e35..6e12b083dab3eeebf320346a1b80349e418a4ca8 100644 (file)
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -28,6 +28,8 @@
 #  include <config.h>
 #endif
 
+#include "voiceplayer.hxx"
+
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
+#include <simgear/sound/sample_group.hxx>
 #include <simgear/structure/exception.hxx>
 
 using std::string;
-
-#include "voiceplayer.hxx"
+using std::map;
+using std::vector;
 
 ///////////////////////////////////////////////////////////////////////////////
 // constants //////////////////////////////////////////////////////////////////
@@ -58,6 +61,36 @@ using std::string;
 
 #define test_bits(_bits, _test) (((_bits) & (_test)) != 0)
 
+/////////////////////////////////////////////////////////////////////////
+// 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(); }
+}
+
+void FGVoicePlayer::Voice::SampleElement::stop ()
+{
+  if (_sample) _sample->stop();
+}
+
+bool FGVoicePlayer::Voice::SampleElement::is_playing ()
+{
+  return _sample ? _sample->is_playing() : false;
+}
+
+void FGVoicePlayer::Voice::SampleElement::set_volume (float volume)
+{
+  if (_sample) _sample->set_volume(volume * _volume);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // FGVoicePlayer //////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
@@ -148,6 +181,14 @@ FGVoicePlayer::Voice::update ()
     }
 }
 
+FGVoicePlayer::FGVoicePlayer (PropertiesHandler* properties_handler, string _dev_name)
+: volume(1.0), voice(NULL), next_voice(NULL), paused(false),
+dev_name(_dev_name), dir_prefix(""),
+speaker(this,properties_handler)
+{
+  _sgr = NULL;
+}
+
 FGVoicePlayer::~FGVoicePlayer ()
 {
     vector<Voice *>::iterator iter1;
@@ -306,3 +347,10 @@ FGVoicePlayer::update ()
         }
     }
 }
+
+void
+FGVoicePlayer::append (Voice *voice, const char *sample_name)
+{
+  voice->append(new Voice::SampleElement(get_sample(sample_name)));
+}
+