From bcccd06cee0d2372df5b2d40cb4473d3156f3668 Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 6 Oct 2009 12:09:28 +0000 Subject: [PATCH] (try to) properly align model and viewer --- simgear/sound/README | 40 +++++++++++++++++++++++++++++++ simgear/sound/sample_group.cxx | 2 +- simgear/sound/sample_openal.cxx | 6 ----- simgear/sound/soundmgr_openal.cxx | 4 ++-- 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 simgear/sound/README diff --git a/simgear/sound/README b/simgear/sound/README new file mode 100644 index 00000000..8f9546b5 --- /dev/null +++ b/simgear/sound/README @@ -0,0 +1,40 @@ + +All code in this directory uses the OpenAL coordinate system for maximum +useablity. The OpenAL coordinate system is equal to that of OpenGL with the +main difference that objects behind the viewer can still be heard: + - positive x is to the right + - positive y is upwards + - positive z is towards the back of the viewer/listener + +see: http://www.falloutsoftware.com/tutorials/gl/cartesian.gif + +All positions are in cartesian space with a unit length of one meter. + +Velocities are three tuples indicating speed and direction in the same space +as positions do (so they are not in the models local space). + + +There is one SoundMgr that handles multiple SoundGroup classes. +Each SoundGroup class handles multiple SoundSample classes. + +A SoundSample class defines the properties of each individual sound like +pitch, volume, position, orientation, sound cone paramters, etc. This +class can be created all over the code but *has* to be assigned to a +SampelGroup before you can hear it. Current sample groups are "atc", +"avionics" and "fx" for the master airplane effects. The position of a +SoundSample is relative to (0,0,0) of the model and hence relative to +the base position of the SampleGroup. + +A SampleGroup class has to be assigned to the SoundManager to be heard +and holds data of a group of samples (maybe 'sample cloud' might be a +good description). This class has to be created for each individual +model that can produce one or more sounds. The SampleGroup class can be +altered by modifying it's volume, position and orientation. +Repositioning this class also means repositioning all it's associated +samples. Altering it's orientation also means repositioning the absolute +(real world) position (and orientation) of the associated sound samples. + +The SoundMaganer can be repositioned which basically means moving the +listener around. It's also possible to alter the listener orientation en +velocity with this class, together with the master volume. + diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index c01b0cbb..54f6c000 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -149,6 +149,7 @@ void SGSampleGroup::update( double dt ) { alSourcei( source, AL_SOURCE_RELATIVE, AL_FALSE ); alSourcei( source, AL_LOOPING, looping ); + alSourcef( source, AL_ROLLOFF_FACTOR, 1.2 ) alSourcePlay( source ); testForALError("sample play"); } else { @@ -382,7 +383,6 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) { alSourcef( source, AL_CONE_OUTER_GAIN, sample->get_outergain() ); testForALError("audio cone"); - alSourcef( source, AL_ROLLOFF_FACTOR, 1.0 ); alSourcef( source, AL_MAX_DISTANCE, sample->get_max_dist() ); alSourcef( source, AL_REFERENCE_DISTANCE, sample->get_reference_dist() ); diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 917f0596..011e0fd3 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -143,12 +143,6 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format // destructor SGSoundSample::~SGSoundSample() { -#if 0 - if (_data != NULL) { - delete[] _data; - _data = NULL; - } -#endif } void SGSoundSample::set_base_position( SGVec3d pos ) { diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index b204aa13..9bc3e2a0 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -412,8 +412,8 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt, */ void SGSoundMgr::set_orientation( SGQuatd ori ) { - SGVec3d sgv_up = ori.rotate(SGVec3d::e2()); - SGVec3d sgv_at = ori.rotate(SGVec3d::e3()); + SGVec3d sgv_up = ori.rotate(SGVec3d::e3()); + SGVec3d sgv_at = ori.rotate(SGVec3d::e2()); for (int i=0; i<3; i++) { _listener_ori[i] = sgv_at[i]; _listener_ori[i+3] = sgv_up[i]; -- 2.39.5