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
|
// allocate and initialize sound samples
|
||||||
bool FGMorse::cust_init(const int freq ) {
|
bool FGMorse::cust_init(const int freq ) {
|
||||||
int i, j;
|
int i;
|
||||||
|
|
||||||
// Make DIT
|
// Make DIT
|
||||||
make_tone( cust_dit, freq, DIT_SIZE - COUNT_SIZE, DIT_SIZE,
|
make_tone( cust_dit, freq, DIT_SIZE - COUNT_SIZE, DIT_SIZE,
|
||||||
|
|
|
@ -87,8 +87,11 @@ FGSoundMgr::~FGSoundMgr() {
|
||||||
|
|
||||||
// initialize the sound manager
|
// initialize the sound manager
|
||||||
bool FGSoundMgr::init() {
|
bool FGSoundMgr::init() {
|
||||||
|
last.stamp();
|
||||||
|
safety = 0.5;
|
||||||
|
|
||||||
audio_mixer -> setMasterVolume ( 80 ) ; /* 80% of max volume. */
|
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 current = sounds.begin();
|
||||||
sound_map_iterator end = sounds.end();
|
sound_map_iterator end = sounds.end();
|
||||||
|
@ -109,6 +112,23 @@ bool FGSoundMgr::init() {
|
||||||
|
|
||||||
// run the audio scheduler
|
// run the audio scheduler
|
||||||
bool FGSoundMgr::update() {
|
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() ) {
|
if ( !audio_sched->not_working() ) {
|
||||||
audio_sched -> update();
|
audio_sched -> update();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include <plib/sl.h>
|
#include <plib/sl.h>
|
||||||
#include <plib/sm.h>
|
#include <plib/sm.h>
|
||||||
|
|
||||||
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
|
||||||
SG_USING_STD(map);
|
SG_USING_STD(map);
|
||||||
SG_USING_STD(string);
|
SG_USING_STD(string);
|
||||||
|
|
||||||
|
@ -86,6 +88,9 @@ class FGSoundMgr {
|
||||||
smMixer *audio_mixer;
|
smMixer *audio_mixer;
|
||||||
sound_map sounds;
|
sound_map sounds;
|
||||||
|
|
||||||
|
SGTimeStamp last;
|
||||||
|
double safety;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGSoundMgr();
|
FGSoundMgr();
|
||||||
|
|
Loading…
Add table
Reference in a new issue