X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSound%2Fsoundmgr.cxx;h=b303a11cdcfe8acf06b38fd16d24df29969c31d7;hb=198b88ca9b4a4b123b2e9ccdc85ea17eeaea70c6;hp=eb2f41fd7461f10386f3b176de39d0bf2951e521;hpb=97cc733ac8565c55bb903b11bf17c052a581a0ab;p=flightgear.git diff --git a/src/Sound/soundmgr.cxx b/src/Sound/soundmgr.cxx index eb2f41fd7..b303a11cd 100644 --- a/src/Sound/soundmgr.cxx +++ b/src/Sound/soundmgr.cxx @@ -41,8 +41,7 @@ // 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 ); @@ -55,8 +54,7 @@ FGSimpleSound::FGSimpleSound( string 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 ); @@ -74,14 +72,12 @@ FGSimpleSound::~FGSimpleSound() { 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 { @@ -94,18 +90,6 @@ void FGSimpleSound::play( slScheduler *sched, bool looped ) { void FGSimpleSound::stop( slScheduler *sched, bool quick ) { - if ( quick ) { - requests = 0; - } else { - if ( --requests < 0 ) { - requests = 0; - } - } - - if ( requests > 0 ) { - return; - } - sched->stopSample( sample ); } @@ -141,6 +125,8 @@ FGSoundMgr::~FGSoundMgr() { sample_map_iterator sample_end = samples.end(); for ( ; sample_current != sample_end; ++sample_current ) { sample_ref *sr = sample_current->second; + + audio_sched->stopSample(sr->sample); delete sr->sample; delete sr; } @@ -152,6 +138,9 @@ FGSoundMgr::~FGSoundMgr() { sound_map_iterator sound_end = sounds.end(); for ( ; sound_current != sound_end; ++sound_current ) { FGSimpleSound *s = sound_current->second; + + audio_sched->stopSample(s->get_sample()); + delete s->get_sample(); delete s; } @@ -162,7 +151,6 @@ FGSoundMgr::~FGSoundMgr() { // initialize the sound manager void FGSoundMgr::init() { - last.stamp(); safety = FG_MAX_SOUND_SAFETY; // audio_mixer -> setMasterVolume ( 80 ) ; /* 80% of max volume. */ @@ -176,6 +164,8 @@ void FGSoundMgr::init() { sample_map_iterator sample_end = samples.end(); for ( ; sample_current != sample_end; ++sample_current ) { sample_ref *sr = sample_current->second; + + audio_sched->stopSample(sr->sample); delete sr->sample; delete sr; } @@ -188,6 +178,8 @@ void FGSoundMgr::init() { sound_map_iterator sound_end = sounds.end(); for ( ; sound_current != sound_end; ++sound_current ) { FGSimpleSound *s = sound_current->second; + + audio_sched->stopSample(s->get_sample()); delete s->get_sample(); delete s; } @@ -195,11 +187,13 @@ void FGSoundMgr::init() { } + void FGSoundMgr::bind () { // no properties yet } + void FGSoundMgr::unbind () { // no properties yet @@ -207,17 +201,11 @@ void FGSoundMgr::unbind () // 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; @@ -230,6 +218,20 @@ void FGSoundMgr::update(int dt) { } +void +FGSoundMgr::pause () +{ + audio_sched->pauseSample(0, 0); +} + + +void +FGSoundMgr::resume () +{ + audio_sched->resumeSample(0, 0); +} + + // add a sound effect, return true if successful bool FGSoundMgr::add( FGSimpleSound *sound, const string& refname ) {