From f8e234bb2718164e3616dc87f92ad9a1e07fd721 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 29 Mar 2001 05:18:29 +0000 Subject: [PATCH] Dynamically adjust audio safety margin (how much audio we stuff in the pipe in advance) based on frame rates. --- src/Sound/morse.cxx | 2 +- src/Sound/soundmgr.cxx | 22 +++++++++++++++++++++- src/Sound/soundmgr.hxx | 5 +++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index ac8df8fd7..507cf54eb 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -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, diff --git a/src/Sound/soundmgr.cxx b/src/Sound/soundmgr.cxx index a4c487809..b0154535d 100644 --- a/src/Sound/soundmgr.cxx +++ b/src/Sound/soundmgr.cxx @@ -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; diff --git a/src/Sound/soundmgr.hxx b/src/Sound/soundmgr.hxx index 3beb06949..1d7e51f2d 100644 --- a/src/Sound/soundmgr.hxx +++ b/src/Sound/soundmgr.hxx @@ -39,6 +39,8 @@ #include #include +#include + 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(); -- 2.39.5