#include "soundmgr_openal_private.hxx"
#include "sample_group.hxx"
-using std::string;
+#ifdef HAVE_STD_ISNAN
+using std::isnan;
+#endif
bool isNaN(float *v) {
return (isnan(v[0]) || isnan(v[1]) || isnan(v[2]));
_samples.clear();
}
-SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
+SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr,
+ const std::string &refname ):
_smgr(smgr),
_refname(refname),
_active(false),
}
// add a sound effect, return true if successful
-bool SGSampleGroup::add( SGSharedPtr<SGSoundSample> sound, const string& refname ) {
-
+bool SGSampleGroup::add( SGSharedPtr<SGSoundSample> sound,
+ const std::string& refname )
+{
sample_map_iterator sample_it = _samples.find( refname );
if ( sample_it != _samples.end() ) {
// sample name already exists
// remove a sound effect, return true if successful
-bool SGSampleGroup::remove( const string &refname ) {
+bool SGSampleGroup::remove( const std::string &refname ) {
sample_map_iterator sample_it = _samples.find( refname );
if ( sample_it == _samples.end() ) {
// return true of the specified sound exists in the sound manager system
-bool SGSampleGroup::exists( const string &refname ) {
+bool SGSampleGroup::exists( const std::string &refname ) {
sample_map_iterator sample_it = _samples.find( refname );
if ( sample_it == _samples.end() ) {
// sample was not found
// return a pointer to the SGSoundSample if the specified sound exists
// in the sound manager system, otherwise return NULL
-SGSoundSample *SGSampleGroup::find( const string &refname ) {
+SGSoundSample *SGSampleGroup::find( const std::string &refname ) {
sample_map_iterator sample_it = _samples.find( refname );
if ( sample_it == _samples.end() ) {
// sample was not found
// tell the scheduler to play the indexed sample in a continuous loop
-bool SGSampleGroup::play( const string &refname, bool looping = false ) {
+bool SGSampleGroup::play( const std::string &refname,
+ bool looping )
+{
SGSoundSample *sample = find( refname );
if ( sample == NULL ) {
// return true of the specified sound is currently being played
-bool SGSampleGroup::is_playing( const string& refname ) {
+bool SGSampleGroup::is_playing( const std::string& refname ) {
SGSoundSample *sample = find( refname );
if ( sample == NULL ) {
}
// immediate stop playing the sound
-bool SGSampleGroup::stop( const string& refname ) {
+bool SGSampleGroup::stop( const std::string& refname ) {
SGSoundSample *sample = find( refname );
if ( sample == NULL ) {
// 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();
+
+ SGVec3d base_position = SGVec3d::fromGeod(_base_pos);
+ SGVec3d smgr_position = _smgr->get_position();
SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos);
SGQuatd ec2body = hlOr*_orientation;
sample->set_master_volume( _volume );
sample->set_orientation( _orientation );
sample->set_rotation( ec2body );
- sample->set_position( position );
+ sample->set_position(base_position);
sample->set_velocity( velocity );
// Test if a sample is farther away than max distance, if so
// stop the sound playback and free it's source.
if (!_tied_to_listener) {
+ sample->update_pos_and_orientation();
+ SGVec3d position = sample->get_position() - smgr_position;
float max2 = sample->get_max_dist() * sample->get_max_dist();
float dist2 = position[0]*position[0]
+ position[1]*position[1] + position[2]*position[2];
} else {
sample->update_pos_and_orientation();
orientation = sample->get_orientation();
- position = sample->get_position();
+ position = sample->get_position() - _smgr->get_position();
velocity = sample->get_velocity();
}
#endif
}
-bool SGSampleGroup::testForError(void *p, string s)
+bool SGSampleGroup::testForError(void *p, std::string s)
{
if (p == NULL) {
SG_LOG( SG_SOUND, SG_ALERT, "Error (sample group): " << s);
return false;
}
-bool SGSampleGroup::testForALError(string s)
+bool SGSampleGroup::testForALError(std::string s)
{
#ifdef SG_C
ALenum error = alGetError();