# include <config.h>
#endif
+#include "voiceplayer.hxx"
+
#include <stdio.h>
#include <string.h>
#include <assert.h>
-#include <math.h>
+#include <cmath>
#include <string>
#include <sstream>
#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 //////////////////////////////////////////////////////////////////
#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 //////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
}
}
+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;
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();
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;
}
}
}
}
+
+void
+FGVoicePlayer::append (Voice *voice, const char *sample_name)
+{
+ voice->append(new Voice::SampleElement(get_sample(sample_name)));
+}
+