-// sample.cxx -- Sound sample encapsulation class
+// sample_openal.cxx -- Audio sample encapsulation class
//
// Written by Curtis Olson, started April 2004.
+// Modified to match the new SoundSystem by Erik Hofman, October 2009
//
// Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
+// Copyright (C) 2009 Erik Hofman <erik@ehofman.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// empty constructor
SGSoundSample::SGSoundSample() :
_absolute_pos(SGVec3d::zeros()),
- _relative_pos(SGVec3f::zeros()),
+ _relative_pos(SGVec3d::zeros()),
_direction(SGVec3d::zeros()),
_velocity(SGVec3d::zeros()),
- _base_pos(SGGeod()),
_orientation(SGQuatd::zeros()),
- _sample_name(""),
+ _orivec(SGVec3f::zeros()),
+ _base_pos(SGGeod()),
+ _refname(""),
_data(NULL),
_format(AL_FORMAT_MONO8),
_size(0),
// constructor
SGSoundSample::SGSoundSample( const char *path, const char *file ) :
_absolute_pos(SGVec3d::zeros()),
- _relative_pos(SGVec3f::zeros()),
+ _relative_pos(SGVec3d::zeros()),
_direction(SGVec3d::zeros()),
_velocity(SGVec3d::zeros()),
- _base_pos(SGGeod()),
_orientation(SGQuatd::zeros()),
+ _orivec(SGVec3f::zeros()),
+ _base_pos(SGGeod()),
_format(AL_FORMAT_MONO8),
_size(0),
_freq(0),
if ( strlen(file) ) {
samplepath.append( file );
}
- _sample_name = samplepath.str();
+ _refname = samplepath.str();
SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
<< samplepath.str() );
// constructor
SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format ) :
_absolute_pos(SGVec3d::zeros()),
- _relative_pos(SGVec3f::zeros()),
+ _relative_pos(SGVec3d::zeros()),
_direction(SGVec3d::zeros()),
_velocity(SGVec3d::zeros()),
- _base_pos(SGGeod()),
_orientation(SGQuatd::zeros()),
+ _orivec(SGVec3f::zeros()),
+ _base_pos(SGGeod()),
_data(data),
_format(format),
_size(len),
_static_changed(true),
_is_file(false)
{
- _sample_name = "unknown, data supplied by caller";
+ _refname = "unknown, data supplied by caller";
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" );
}
// destructor
SGSoundSample::~SGSoundSample() {
+ if (_data != NULL) {
+ delete _data;
+ _data = NULL;
+ }
}
-void SGSoundSample::set_orientation( SGQuatd ori ) {
+void SGSoundSample::set_orientation( const SGQuatd& ori ) {
_orientation = ori;
update_absolute_position();
_changed = true;
}
-void SGSoundSample::set_direction( SGVec3d dir ) {
+void SGSoundSample::set_direction( const SGVec3d& dir ) {
_direction = dir;
update_absolute_position();
_changed = true;
}
-float *SGSoundSample::get_orientation() {
- SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation;
- SGVec3d orivec = -orient.rotate(_direction);
- return toVec3f(orivec).data();
-}
-
-void SGSoundSample::set_relative_position( SGVec3f pos ) {
- _relative_pos = pos;
+void SGSoundSample::set_relative_position( const SGVec3f& pos ) {
+ _relative_pos = toVec3d(pos);
update_absolute_position();
_changed = true;
}
-void SGSoundSample::set_position( SGGeod pos ) {
+void SGSoundSample::set_position( const SGGeod& pos ) {
_base_pos = pos;
update_absolute_position();
_changed = true;
}
void SGSoundSample::update_absolute_position() {
- _absolute_pos = -SGVec3d::fromGeod(_base_pos);
- // TODO: add relative position
+ SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation;
+ _orivec = -toVec3f(orient.rotate(_direction));
+
+ orient = SGQuatd::fromRealImag(0, _relative_pos) * _orientation;
+ _absolute_pos = -SGVec3d::fromGeod(_base_pos) -orient.rotate(SGVec3d::e1());
+
+ float vel = length(_velocity);
+ _velocity = toVec3d(_orivec * vel);
}