For sounds that play while a value is in transit, use time rather than
the number of frames to judge when to halt the sound because it will be much
more reliable on high performance systems. It currently waits 10 ms.
before stopping the sound, but you might want to fiddle it a little by
changing MAX_TRANSIT_TIME defined int fg_sound.hxx
_mode(FGSound::ONCE),
_prev_value(0),
_dt_play(0.0),
- _dt_stop(0.0)
+ _dt_stop(0.0),
+ _stopping(0.0)
{
}
{
if (_sample->is_playing()) {
- SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
- << " sec: " << _name );
- _sample->stop( _mgr->get_scheduler() );
+
+ if ((_mode != FGSound::IN_TRANSIT) || (_stopping < MAX_TRANSIT_TIME)) {
+
+ _active = false;
+ _sample->stop( _mgr->get_scheduler() );
+
+ SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
+ << " sec: " << _name );
+
+ } else
+ _stopping += dt;
}
- _active = false;
_dt_stop += dt;
_dt_play = 0.0;
#include "soundmgr.hxx"
+static const double MAX_TRANSIT_TIME = 0.01; // 10 ms.
+
+
/**
* Class for handling one sound event.
*
enum { ONCE=0, LOOPED, IN_TRANSIT };
enum { LEVEL=0, INVERTED, FLIPFLOP };
-
// Sound properties
typedef struct {
SGPropertyNode * prop;
double _prev_value;
double _dt_play;
double _dt_stop;
+ double _stopping; // time after the sound should have stopped.
+ // This is usefull for lost packets in in-trasit mode.
vector<_snd_prop> _volume;
vector<_snd_prop> _pitch;