X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fsample_group.cxx;h=e2a2b2c73188894f89daeca7316ebd5946ff5910;hb=1f37095087fa7aa3d210ba134058b86c3bd6d69e;hp=bd1bf4851b238176f5c613a2d49a766cf30e034c;hpb=6cd8db7b28b675f75ab22c2073832980d9f8d6a4;p=simgear.git diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index bd1bf485..e2a2b2c7 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -39,6 +39,7 @@ SGSampleGroup::SGSampleGroup () : _active(false), _changed(false), _pause(false), + _volume(1.0), _tied_to_listener(false), _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()) @@ -52,6 +53,7 @@ SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) : _active(false), _changed(false), _pause(false), + _volume(1.0), _tied_to_listener(false), _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()) @@ -242,9 +244,8 @@ SGSoundSample *SGSampleGroup::find( const string &refname ) { } -// stop playing all associated samples void -SGSampleGroup::suspend () +SGSampleGroup::stop () { _pause = true; sample_map_iterator sample_current = _samples.begin(); @@ -252,28 +253,60 @@ SGSampleGroup::suspend () for ( ; sample_current != sample_end; ++sample_current ) { SGSoundSample *sample = sample_current->second; - if ( sample->is_valid_source() && sample->is_playing() ) { - alSourcePause( sample->get_source() ); + if ( sample->is_valid_source() ) { + ALint source = sample->get_source(); + if ( sample->is_playing() ) { + alSourceStop( source ); + alSourcei( source, AL_BUFFER, 0 ); + } + _smgr->release_source( source ); + sample->no_valid_source(); + } + + if (sample->is_valid_buffer() ) { + _smgr->release_buffer( sample ); + sample->no_valid_buffer(); + } + } + 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"); } - 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; } @@ -315,20 +348,24 @@ 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 void SGSampleGroup::update_pos_and_orientation() { SGVec3d position = SGVec3d::fromGeod(_base_pos) - _smgr->get_position(); - SGQuatd ec2body= SGQuatd::fromLonLat(_base_pos) * _orientation; + SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos); + SGQuatd ec2body = hlOr*_orientation; SGVec3f velocity = SGVec3f::zeros(); if ( _velocity[0] || _velocity[1] || _velocity[2] ) { - velocity = toVec3f( ec2body.backTransform(_velocity*SG_FEET_TO_METER) ); + velocity = toVec3f( hlOr.backTransform(_velocity*SG_FEET_TO_METER) ); } sample_map_iterator sample_current = _samples.begin(); @@ -358,9 +395,14 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) { velocity = sample->get_velocity(); } + if (_smgr->bad_doppler_effect()) { + velocity *= 100.0f; + } + #if 0 if (length(position) > 20000) - printf("source and listener distance greater than 20km!\n"); + printf("%s source and listener distance greater than 20km!\n", + _refname.c_str()); if (isNaN(toVec3f(position).data())) printf("NaN in source position\n"); if (isNaN(orientation.data())) printf("NaN in source orientation\n"); if (isNaN(velocity.data())) printf("NaN in source velocity\n");