diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index d3ee7fb7..8bd5eb9b 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -359,29 +359,15 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) { if ( sample->is_valid_source() ) { unsigned int source = sample->get_source(); -#if 1 if ( _tied_to_listener && _smgr->has_changed() ) { alSourcefv( source, AL_POSITION, _smgr->get_position().data() ); alSourcefv( source, AL_VELOCITY, _smgr->get_velocity().data() ); -#if 0 alSourcefv( source, AL_DIRECTION, _smgr->get_direction().data() ); -#endif } else { -float *pos = sample->get_position(); -if (isnan(pos[0]) || isnan(pos[1]) || isnan(pos[2])) printf("NaN detected in source position\n"); alSourcefv( source, AL_POSITION, sample->get_position() ); -float *vel = sample->get_velocity(); -if (isnan(vel[0]) || isnan(vel[1]) || isnan(vel[2])) printf("NaN detected in source velocity\n"); alSourcefv( source, AL_VELOCITY, sample->get_velocity() ); -#if 0 alSourcefv( source, AL_DIRECTION, sample->get_orientation() ); -#endif } -#else - alSourcefv( source, AL_POSITION, SGVec3f::zeros().data() ); - alSourcefv( source, AL_DIRECTION, SGVec3f::zeros().data() ); - alSourcefv( source, AL_VELOCITY, SGVec3f::zeros().data() ); -#endif testForALError("position and orientation"); alSourcef( source, AL_PITCH, sample->get_pitch() ); @@ -389,11 +375,9 @@ if (isnan(vel[0]) || isnan(vel[1]) || isnan(vel[2])) printf("NaN detected in sou testForALError("pitch and gain"); if ( sample->has_static_data_changed() ) { -#if 0 alSourcef( source, AL_CONE_INNER_ANGLE, sample->get_innerangle() ); alSourcef( source, AL_CONE_OUTER_ANGLE, sample->get_outerangle() ); alSourcef( source, AL_CONE_OUTER_GAIN, sample->get_outergain() ); -#endif testForALError("audio cone"); alSourcef( source, AL_MAX_DISTANCE, sample->get_max_dist() ); diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 307b2385..451ece25 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -49,7 +49,7 @@ SGSoundSample::SGSoundSample() : _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), - _base_pos(SGGeod()), + _base_pos(SGGeod::fromDeg(0,0)), _refname(random_string()), _data(NULL), _format(AL_FORMAT_MONO8), @@ -83,7 +83,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), - _base_pos(SGGeod()), + _base_pos(SGGeod::fromDeg(0,0)), _refname(file), _data(NULL), _format(AL_FORMAT_MONO8), @@ -126,7 +126,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data, _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), - _base_pos(SGGeod()), + _base_pos(SGGeod::fromDeg(0,0)), _refname(random_string()), _format(format), _size(len), @@ -161,7 +161,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), - _base_pos(SGGeod()), + _base_pos(SGGeod::fromDeg(0,0)), _refname(random_string()), _format(format), _size(len), @@ -220,11 +220,26 @@ void SGSoundSample::set_position( const SGGeod& pos ) { } void SGSoundSample::update_absolute_position() { - SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation; - _orivec = -toVec3f(orient.rotate(-SGVec3d::e1())); + // SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation; + // _orivec = -toVec3f(orient.rotate(-SGVec3d::e1())); - orient = SGQuatd::fromRealImag(0, _relative_pos) * _orientation; - _absolute_pos = -SGVec3d::fromGeod(_base_pos); // -orient.rotate(SGVec3d::e1()); + // The rotation rotating from the earth centerd frame to + // the horizontal local frame + SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos); + + // Compute the eyepoints orientation and position + // wrt the earth centered frame - that is global coorinates + SGQuatd ec2body = hlOr*_orientation; + + // This is rotates the x-forward, y-right, z-down coordinate system where + // simulation runs into the OpenGL camera system with x-right, y-up, z-back. + SGQuatd q(-0.5, -0.5, 0.5, 0.5); + + // The cartesian position of the basic view coordinate + SGVec3d position = SGVec3d::fromGeod(_base_pos); + + _absolute_pos = position + (ec2body*q).backTransform(_relative_pos); + _orivec = toVec3f( (ec2body*q).backTransform(_direction) ); } string SGSoundSample::random_string() { diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index bfe0a2e7..2d37e30e 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -252,15 +252,8 @@ void SGSoundMgr::update_late( double dt ) { if (_changed) { alListenerf( AL_GAIN, _volume ); -#if 0 alListenerfv( AL_ORIENTATION, _at_up_vec ); -#endif -double *pos = _position.data(); -if (isnan(pos[0]) || isnan(pos[1]) || isnan(pos[2])) printf("NaN detected in listener position\n"); alListenerfv( AL_POSITION, toVec3f(_position).data() ); - -double *vel = _velocity.data(); -if (isnan(vel[0]) || isnan(vel[1]) || isnan(vel[2])) printf("NaN detected in listener velocity\n"); alListenerfv( AL_VELOCITY, toVec3f(_velocity).data() ); // alDopplerVelocity(340.3); // TODO: altitude dependent testForALError("update"); diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index 5d86c6be..58e63111 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -159,7 +159,7 @@ public: * @param pos OpenAL listener position */ void set_position( const SGVec3d& pos ) { - _position = -pos; + _position = pos; _changed = true; } diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 9e3ae813..45b303a1 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -41,8 +41,8 @@ static double _snd_inv(double v) { return (v == 0) ? 1e99 : 1/v; } static double _snd_abs(double v) { return (v >= 0) ? v : -v; } static double _snd_sqrt(double v) { return sqrt(fabs(v)); } -static double _snd_log10(double v) { return log10(fabs(v)); } -static double _snd_log(double v) { return log(fabs(v)); } +static double _snd_log10(double v) { return log10(fabs(v)+1e-9); } +static double _snd_log(double v) { return log(fabs(v)+1e-9); } // static double _snd_sqr(double v) { return v*v; } // static double _snd_pow3(double v) { return v*v*v; } @@ -243,9 +243,9 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, float outer_gain = 0.0; prop = node->getChild("orientation"); if ( prop != NULL ) { - dir = SGVec3d(-prop->getDoubleValue("x", 0.0), - -prop->getDoubleValue("y", 0.0), - -prop->getDoubleValue("z", 0.0)); + dir = SGVec3d(prop->getDoubleValue("y", 0.0), + prop->getDoubleValue("z", 0.0), + prop->getDoubleValue("x", 0.0)); inner = prop->getDoubleValue("inner-angle", 360.0); outer = prop->getDoubleValue("outer-angle", 360.0); outer_gain = prop->getDoubleValue("outer-gain", 0.0);