// constructor
FGSimpleSound::FGSimpleSound( string file )
: pitch(1.0),
- volume(1.0),
- requests(0)
+ volume(1.0)
{
SGPath slfile( globals->get_fg_root() );
slfile.append( file );
FGSimpleSound::FGSimpleSound( unsigned char *buffer, int len )
: pitch(1.0),
- volume(1.0),
- requests(0)
+ volume(1.0)
{
sample = new slSample ( buffer, len );
pitch_envelope = new slEnvelope( 1, SL_SAMPLE_ONE_SHOT );
void FGSimpleSound::play( slScheduler *sched, bool looped ) {
- requests++;
-
// make sure sound isn't already playing
if ( sample->getPlayCount() > 0 ) {
- return;
+ sched->stopSample(sample);
+ // return;
}
- // sched->stopSample(sample);
if ( looped ) {
sched->loopSample(sample);
} else {
void FGSimpleSound::stop( slScheduler *sched, bool quick ) {
- if ( quick ) {
- requests = 0;
- } else {
- if ( --requests < 0 ) {
- requests = 0;
- }
- }
-
- if ( requests > 0 ) {
- return;
- }
-
sched->stopSample( sample );
}
// initialize the sound manager
void FGSoundMgr::init() {
- last.stamp();
safety = FG_MAX_SOUND_SAFETY;
// audio_mixer -> setMasterVolume ( 80 ) ; /* 80% of max volume. */
// run the audio scheduler
-void FGSoundMgr::update(int dt) {
- SGTimeStamp current;
- current.stamp();
-
- double elapsed = (double)(current - last) / 1000000.0;
- last = current;
-
- if ( elapsed > safety ) {
- safety = elapsed;
+void FGSoundMgr::update( double dt ) {
+ if ( dt > safety ) {
+ safety = dt;
} else {
- safety = safety * 0.99 + elapsed * 0.01;
+ safety = safety * 0.99 + dt * 0.01;
}
if ( safety > FG_MAX_SOUND_SAFETY ) {
safety = FG_MAX_SOUND_SAFETY;