smgr->update(1.0);
printf("playing sample\n");
sleep(3);
- sgr->stop("sound1");
+ sample1->stop();
smgr->update(3.0);
sleep(1);
- printf("source at lat,lon = (10,-10), listener at (0.999,-0.999)\n");
+ printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n");
sample1->set_position( SGGeod::fromDeg(10,-10) );
smgr->set_position( SGVec3d::fromGeod(SGGeod::fromDeg(9.99,-9.99)) );
sample1->play_looped();
smgr->update(1.0);
printf("playing sample\n");
sleep(3);
- sgr->stop("sound1");
+ sample1->stop();
smgr->update(3.0);
sleep(1);
+ sgr->remove("sound1");
smgr->unbind();
sleep(2);
delete smgr;
sample->stop();
sample->no_valid_source();
_smgr->release_source( sample->get_source() );
- } else {
+ } else if ( _smgr->has_changed() ) {
update_sample_config( sample );
}
}
// set source velocity of all managed sounds
-void SGSampleGroup::set_velocity( const SGVec3d &vel ) {
+void SGSampleGroup::set_velocity( const SGVec3f &vel ) {
if ( isnan(vel[0]) || isnan(vel[1]) || isnan(vel[2]) )
{
SG_LOG( SG_GENERAL, SG_ALERT, "NAN's found in SampleGroup velocity");
}
void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
- if ( sample->is_valid_source() ) {
- unsigned int source = sample->get_source();
-
- float *position, *orientation, *velocity;
- if ( _tied_to_listener ) {
- position = _smgr->get_position().data();
- orientation = _smgr->get_direction().data();
- velocity = _smgr->get_velocity().data();
- } else {
- sample->update_absolute_position();
- position = sample->get_position();
- orientation = sample->get_orientation();
- velocity = sample->get_velocity();
- }
+ SGVec3f orientation, velocity;
+ SGVec3d position;
+
+ if ( _tied_to_listener ) {
+ orientation = _smgr->get_direction();
+ position = _smgr->get_position();
+ velocity = _smgr->get_velocity();
+ } else {
+ sample->update_absolute_position();
+ orientation = sample->get_orientation();
+ position = sample->get_position();
+ velocity = sample->get_velocity();
+ }
- if (dist(_smgr->get_position(), sample->get_position_vec()) > 50000)
- printf("source and listener distance greater than 50km!\n");
- if (isNaN(position)) printf("NaN in source position\n");
- if (isNaN(orientation)) printf("NaN in source orientation\n");
- if (isNaN(velocity)) printf("NaN in source velocity\n");
-
- alSourcefv( source, AL_POSITION, position );
- alSourcefv( source, AL_VELOCITY, velocity );
- alSourcefv( source, AL_DIRECTION, orientation );
- testForALError("position and orientation");
-
- alSourcef( source, AL_PITCH, sample->get_pitch() );
- alSourcef( source, AL_GAIN, sample->get_volume() );
- testForALError("pitch and gain");
-
- if ( sample->has_static_data_changed() ) {
- 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() );
- testForALError("audio cone");
-
- alSourcef( source, AL_MAX_DISTANCE, sample->get_max_dist() );
- alSourcef( source, AL_REFERENCE_DISTANCE,
- sample->get_reference_dist() );
- testForALError("distance rolloff");
- }
+ if (dist(position, _smgr->get_position()) > 10000)
+ printf("source and listener distance greater than 20km!\n");
+ if (isNaN(position)) printf("NaN in source position\n");
+ if (isNaN(orientation)) printf("NaN in source orientation\n");
+ if (isNaN(velocity)) printf("NaN in source velocity\n");
+
+ unsigned int source = sample->get_source();
+ alSourcefv( source, AL_POSITION, toVec3f(position).data() );
+ alSourcefv( source, AL_VELOCITY, velocity.data() );
+ alSourcefv( source, AL_DIRECTION, orientation.data() );
+ testForALError("position and orientation");
+
+ alSourcef( source, AL_PITCH, sample->get_pitch() );
+ alSourcef( source, AL_GAIN, sample->get_volume() );
+ testForALError("pitch and gain");
+
+ if ( sample->has_static_data_changed() ) {
+ 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() );
+ testForALError("audio cone");
+
+ alSourcef( source, AL_MAX_DISTANCE, sample->get_max_dist() );
+ alSourcef( source, AL_REFERENCE_DISTANCE,
+ sample->get_reference_dist() );
+ testForALError("distance rolloff");
}
}
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
* @param vel Velocity vector
*/
- void set_velocity( const SGVec3d& vel );
+ void set_velocity( const SGVec3f& vel );
/**
* Set the position of this sample group.
float _volume;
bool _tied_to_listener;
- SGVec3d _velocity;
+ SGVec3f _velocity;
SGQuatd _orientation;
SGGeod _position;
// The cartesian position of the base sound coordinate
SGVec3d position = SGVec3d::fromGeod(_base_pos);
- _absolute_pos = position + (sc2body*q).backTransform(_relative_pos);
- _orivec = toVec3f( (sc2body*q).backTransform(_direction) );
+ _absolute_pos = position; // + (sc2body*q).backTransform(_relative_pos);
+ if ( !(_direction[0] == 0 && _direction[1] == 0 && _direction[2] == 0) ) {
+ _orivec = toVec3f((sc2body*q).backTransform(toVec3d(_direction)));
+ }
}
string SGSoundSample::random_string() {
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
* @return Absolute position
*/
- float *get_position() const { return toVec3f(_absolute_pos).data(); }
- SGVec3f get_position_vec() const { return toVec3f(_absolute_pos); }
+ SGVec3d& get_position() { return _absolute_pos; }
/**
* Set the orientation of this sound.
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right
* @param dir Sound emission direction
*/
- inline void set_direction( const SGVec3d& dir ) {
+ inline void set_direction( const SGVec3f& dir ) {
_direction = dir; _changed = true;
}
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right
* @return Orientaton vector
*/
- float *get_orientation() { return _orivec.data(); }
+ SGVec3f& get_orientation() { return _orivec; }
+ SGVec3f& get_direction() { return _direction; }
/**
* Get the inner angle of the audio cone.
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right
* @param Velocity vector
*/
- inline void set_velocity( const SGVec3d& vel ) {
+ inline void set_velocity( const SGVec3f& vel ) {
_velocity = vel; _changed = true;
}
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right
* @return Velocity vector
*/
- float *get_velocity() { return toVec3f(_velocity).data(); }
+ SGVec3f& get_velocity() { return _velocity; }
/**
// Position of the source sound.
SGVec3d _absolute_pos; // absolute position
SGVec3d _relative_pos; // position relative to the base position
- SGVec3d _direction; // orientation offset
- SGVec3d _velocity; // Velocity of the source sound.
+ SGVec3f _direction; // orientation offset
+ SGVec3f _velocity; // Velocity of the source sound.
// The position and orientation of this sound
SGQuatd _orientation; // base orientation
if (_changed) {
if (isNaN(_at_up_vec)) printf("NaN in listener orientation\n");
if (isNaN(toVec3f(_position).data())) printf("NaN in listener position\n");
-if (isNaN(toVec3f(_velocity).data())) printf("NaN in listener velocity\n");
+if (isNaN(_velocity.data())) printf("NaN in listener velocity\n");
alListenerf( AL_GAIN, _volume );
alListenerfv( AL_ORIENTATION, _at_up_vec );
alListenerfv( AL_POSITION, toVec3f(_position).data() );
- alListenerfv( AL_VELOCITY, toVec3f(_velocity).data() );
+ alListenerfv( AL_VELOCITY, _velocity.data() );
// alDopplerVelocity(340.3); // TODO: altitude dependent
testForALError("update");
_changed = false;
_orientation = ori;
_orient_offs = offs;
- SGVec3d sgv_up = _orient_offs.rotate(SGVec3d::e2());
- SGVec3d sgv_at = _orient_offs.rotate(SGVec3d::e3());
+ SGVec3d sgv_up = offs.rotate(SGVec3d::e2());
+ SGVec3d sgv_at = offs.rotate(SGVec3d::e3());
_at_up_vec[0] = sgv_at[0];
_at_up_vec[1] = sgv_at[1];
_at_up_vec[2] = sgv_at[2];
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right
* @return OpenAL listener position
*/
- SGVec3f get_position() { return toVec3f(_position); }
+ SGVec3d& get_position() { return _position; }
/**
* Set the velocity vector of the sound manager
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
* @param vel Velocity vector of the OpenAL listener
*/
- void set_velocity( SGVec3d& vel ) {
+ void set_velocity( SGVec3f& vel ) {
_velocity = vel; _changed = true;
}
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
* @return Velocity vector of the OpenAL listener
*/
- inline SGVec3f get_velocity() { return toVec3f(_velocity); }
+ inline SGVec3f& get_velocity() { return _velocity; }
/**
* Set the orientation of the sound manager
SGVec3d _position;
// Velocity of the listener.
- SGVec3d _velocity;
+ SGVec3f _velocity;
// Orientation of the listener.
// first 3 elements are "at" vector, second 3 are "up" vector
//
// Orientation
//
- SGVec3d dir = SGVec3d::zeros();
+ SGVec3f dir = SGVec3f::zeros();
float inner = 360.0;
float outer = 360.0;
float outer_gain = 0.0;
prop = node->getChild("orientation");
if ( prop != NULL ) {
- 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);
+ dir = SGVec3f(prop->getFloatValue("y", 0.0),
+ prop->getFloatValue("z", 0.0),
+ prop->getFloatValue("x", 0.0));
+ inner = prop->getFloatValue("inner-angle", 360.0);
+ outer = prop->getFloatValue("outer-angle", 360.0);
+ outer_gain = prop->getFloatValue("outer-gain", 0.0);
}
//