#include <simgear/debug/logstream.hxx>
-#include <simgear/misc/fgpath.hxx>
+#include <simgear/misc/sg_path.hxx>
#include <Main/globals.hxx>
// constructor
FGSimpleSound::FGSimpleSound( string file ) {
- FGPath slfile( globals->get_fg_root() );
+ SGPath slfile( globals->get_fg_root() );
slfile.append( file );
sample = new slSample ( (char *)slfile.c_str() );
pitch_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
// initialize the sound manager
bool FGSoundMgr::init() {
+ last.stamp();
+ safety = 0.5;
+
audio_mixer -> setMasterVolume ( 80 ) ; /* 80% of max volume. */
- audio_sched -> setSafetyMargin ( 1.0 ) ;
+ audio_sched -> setSafetyMargin ( 2 * safety ) ;
sound_map_iterator current = sounds.begin();
sound_map_iterator end = sounds.end();
// run the audio scheduler
bool FGSoundMgr::update() {
+ SGTimeStamp current;
+ current.stamp();
+
+ double elapsed = (double)(current - last) / 1000000.0;
+ last = current;
+
+ if ( elapsed > safety ) {
+ safety = elapsed;
+ } else {
+ safety = safety * 0.99 + elapsed * 0.01;
+ }
+ if ( safety > 0.5 ) {
+ safety = 0.5;
+ }
+ // cout << "safety = " << safety << endl;
+ audio_sched -> setSafetyMargin ( 2 * safety ) ;
+
if ( !audio_sched->not_working() ) {
audio_sched -> update();
return true;