X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fsample_group.cxx;h=e2a2b2c73188894f89daeca7316ebd5946ff5910;hb=1f37095087fa7aa3d210ba134058b86c3bd6d69e;hp=de173dbdf770c2d9b2539a770c91fbb945799d3b;hpb=bc85767f197d8e039333202199fc2a2cc4d6e1b1;p=simgear.git diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index de173dbd..e2a2b2c7 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -244,23 +244,6 @@ SGSoundSample *SGSampleGroup::find( const string &refname ) { } -// stop playing all associated samples -void -SGSampleGroup::suspend () -{ - _pause = true; - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; - - if ( sample->is_valid_source() && sample->is_playing() ) { - alSourcePause( sample->get_source() ); - } - } - testForALError("suspend"); -} - void SGSampleGroup::stop () { @@ -271,34 +254,59 @@ SGSampleGroup::stop () SGSoundSample *sample = sample_current->second; if ( sample->is_valid_source() ) { + ALint source = sample->get_source(); if ( sample->is_playing() ) { - alSourcePause( sample->get_source() ); + alSourceStop( source ); + alSourcei( source, AL_BUFFER, 0 ); } - _smgr->release_source( sample->get_source() ); + _smgr->release_source( source ); sample->no_valid_source(); + } + if (sample->is_valid_buffer() ) { _smgr->release_buffer( sample ); sample->no_valid_buffer(); } } - testForALError("suspend"); + testForALError("stop"); +} + +// stop playing all associated samples +void +SGSampleGroup::suspend () +{ + if (_active && _pause == false) { + _pause = true; + sample_map_iterator sample_current = _samples.begin(); + sample_map_iterator sample_end = _samples.end(); + for ( ; sample_current != sample_end; ++sample_current ) { + SGSoundSample *sample = sample_current->second; + + if ( sample->is_valid_source() && sample->is_playing() ) { + alSourcePause( sample->get_source() ); + } + } + testForALError("suspend"); + } } // resume playing all associated samples void SGSampleGroup::resume () { - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; - - if ( sample->is_valid_source() && sample->is_playing() ) { - alSourcePlay( sample->get_source() ); + if (_active && _pause == true) { + sample_map_iterator sample_current = _samples.begin(); + sample_map_iterator sample_end = _samples.end(); + for ( ; sample_current != sample_end; ++sample_current ) { + SGSoundSample *sample = sample_current->second; + + if ( sample->is_valid_source() && sample->is_playing() ) { + alSourcePlay( sample->get_source() ); + } } + testForALError("resume"); + _pause = false; } - testForALError("resume"); - _pause = false; } @@ -340,9 +348,12 @@ bool SGSampleGroup::stop( const string& refname ) { void SGSampleGroup::set_volume( float vol ) { - _volume = vol; - if (_volume < 0.0) _volume = 0.0; - if (_volume > 1.0) _volume = 1.0; + if (vol > _volume*1.01 || vol < _volume*0.99) { + _volume = vol; + if (_volume < 0.0) _volume = 0.0; + if (_volume > 1.0) _volume = 1.0; + _changed = true; + } } // set the source position and orientation of all managed sounds