From 57ba57a18bba9391f72a2534cb00978fb1f18da3 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 28 Sep 2002 12:16:37 +0000 Subject: [PATCH] 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 --- src/Sound/fg_sound.cxx | 18 +++++++++++++----- src/Sound/fg_sound.hxx | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Sound/fg_sound.cxx b/src/Sound/fg_sound.cxx index 28ebafb70..bcd95d824 100644 --- a/src/Sound/fg_sound.cxx +++ b/src/Sound/fg_sound.cxx @@ -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; diff --git a/src/Sound/fg_sound.hxx b/src/Sound/fg_sound.hxx index f6c21b80b..e3c0cda46 100644 --- a/src/Sound/fg_sound.hxx +++ b/src/Sound/fg_sound.hxx @@ -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;