Dynamically adjust audio safety margin (how much audio we stuff in the
pipe in advance) based on frame rates.
This commit is contained in:
parent
31047f65ac
commit
f8e234bb27
3 changed files with 27 additions and 2 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue