]> git.mxchange.org Git - flightgear.git/commitdiff
Dynamically adjust audio safety margin (how much audio we stuff in the
authorcurt <curt>
Thu, 29 Mar 2001 05:18:29 +0000 (05:18 +0000)
committercurt <curt>
Thu, 29 Mar 2001 05:18:29 +0000 (05:18 +0000)
pipe in advance) based on frame rates.

src/Sound/morse.cxx
src/Sound/soundmgr.cxx
src/Sound/soundmgr.hxx

index ac8df8fd7332af975760e0849552ef771f51f477..507cf54eb0f858ca8128cd79d0e506d973d2156e 100644 (file)
@@ -133,7 +133,7 @@ bool FGMorse::init() {
 
 // allocate and initialize sound samples
 bool FGMorse::cust_init(const int freq ) {
-    int i, j;
+    int i;
 
     // Make DIT
     make_tone( cust_dit, freq, DIT_SIZE - COUNT_SIZE, DIT_SIZE,
index a4c4878096a119ce086eb3939df8e76963f4577a..b0154535de30867d1a72ef12f0c89604b932649c 100644 (file)
@@ -87,8 +87,11 @@ FGSoundMgr::~FGSoundMgr() {
 
 // 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();
@@ -109,6 +112,23 @@ bool FGSoundMgr::init() {
 
 // 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;
index 3beb06949e3280c69f3b9429b244f6eaed2b42f6..1d7e51f2d0988ec2a0e12f9856eb97892432427b 100644 (file)
@@ -39,6 +39,8 @@
 #include <plib/sl.h>
 #include <plib/sm.h>
 
+#include <simgear/timing/timestamp.hxx>
+
 SG_USING_STD(map);
 SG_USING_STD(string);
 
@@ -86,6 +88,9 @@ class FGSoundMgr {
     smMixer *audio_mixer;
     sound_map sounds;
 
+    SGTimeStamp last;
+    double safety;
+
 public:
 
     FGSoundMgr();