Erik Hofman:
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
This commit is contained in:
parent
de667227c4
commit
57ba57a18b
2 changed files with 18 additions and 6 deletions
|
@ -70,7 +70,8 @@ FGSound::FGSound()
|
|||
_mode(FGSound::ONCE),
|
||||
_prev_value(0),
|
||||
_dt_play(0.0),
|
||||
_dt_stop(0.0)
|
||||
_dt_stop(0.0),
|
||||
_stopping(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -270,12 +271,19 @@ FGSound::update (double dt)
|
|||
{
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
|
||||
#include "soundmgr.hxx"
|
||||
|
||||
static const double MAX_TRANSIT_TIME = 0.01; // 10 ms.
|
||||
|
||||
|
||||
/**
|
||||
* Class for handling one sound event.
|
||||
*
|
||||
|
@ -56,7 +59,6 @@ protected:
|
|||
enum { ONCE=0, LOOPED, IN_TRANSIT };
|
||||
enum { LEVEL=0, INVERTED, FLIPFLOP };
|
||||
|
||||
|
||||
// Sound properties
|
||||
typedef struct {
|
||||
SGPropertyNode * prop;
|
||||
|
@ -83,6 +85,8 @@ private:
|
|||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue