From: ehofman Date: Fri, 16 Oct 2009 09:45:00 +0000 (+0000) Subject: Alut < 1.0 fixes and finaly fix the sound orientation X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fdfdfedf01776fafa4d769b93e95585e018a00d4;p=simgear.git Alut < 1.0 fixes and finaly fix the sound orientation --- diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index 3d1dd084..fb2f31f0 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -306,7 +306,7 @@ void SGSampleGroup::set_velocity( SGVec3d &vel ) { } } -// ste the source orientation of all managed sounds +// set the source position of all managed sounds void SGSampleGroup::set_position( SGGeod pos ) { sample_map_iterator sample_current = _samples.begin(); @@ -319,7 +319,7 @@ void SGSampleGroup::set_position( SGGeod pos ) { } -// ste the source orientation of all managed sounds +// set the source orientation of all managed sounds void SGSampleGroup::set_orientation( SGQuatd ori ) { if (_orientation != ori) { @@ -356,7 +356,7 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) { alSourcefv( source, AL_DIRECTION, _smgr->get_direction().data() ); alSourcefv( source, AL_VELOCITY, _smgr->get_velocity().data() ); } else { - alSourcefv( source, AL_POSITION, sample->get_position()); + alSourcefv( source, AL_POSITION, sample->get_position() ); alSourcefv( source, AL_DIRECTION, sample->get_orientation() ); alSourcefv( source, AL_VELOCITY, sample->get_velocity() ); } diff --git a/simgear/sound/sample_group.hxx b/simgear/sound/sample_group.hxx index 70b844c3..9cfd8dfb 100644 --- a/simgear/sound/sample_group.hxx +++ b/simgear/sound/sample_group.hxx @@ -153,9 +153,9 @@ public: */ void set_orientation( SGQuatd ori ); - inline void tie_to_listener() { _tied_to_listener = true; } + void tie_to_listener() { _tied_to_listener = true; } - inline void activate() { _active = true; } + void activate() { _active = true; } protected: SGSoundMgr *_smgr; diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 526e27c7..939e5619 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -66,7 +66,8 @@ SGSoundSample::SGSoundSample() : _playing(false), _changed(true), _static_changed(true), - _is_file(false) + _is_file(false), + _orivec(SGVec3f::zeros()) { } @@ -97,7 +98,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : _playing(false), _changed(true), _static_changed(true), - _is_file(true) + _is_file(true), + _orivec(SGVec3f::zeros()) { SGPath samplepath( path ); if ( strlen(file) ) { @@ -137,7 +139,8 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format _playing(false), _changed(true), _static_changed(true), - _is_file(false) + _is_file(false), + _orivec(SGVec3f::zeros()) { _sample_name = "unknown, data supplied by caller"; SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" ); @@ -160,12 +163,6 @@ void SGSoundSample::set_direction( SGVec3d dir ) { _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; update_absolute_position(); @@ -179,6 +176,9 @@ void SGSoundSample::set_position( SGGeod pos ) { } void SGSoundSample::update_absolute_position() { + SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation; + _orivec = -toVec3f(orient.rotate(_direction)); + _absolute_pos = -SGVec3d::fromGeod(_base_pos); // TODO: add relative position } diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 59d26581..49a7c01e 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -93,6 +93,7 @@ private: bool _static_changed; bool _is_file; + SGVec3f _orivec; void update_absolute_position(); public: @@ -359,11 +360,10 @@ public: * Get the orientation of the sound source, the inner or outer angle * or outer gain. */ - float *get_orientation(); - - inline float get_innerangle() { return _inner_angle; } - inline float get_outerangle() { return _outer_angle; } - inline float get_outergain() { return _outer_gain; } + float *get_orientation() { return _orivec.data(); } + float get_innerangle() { return _inner_angle; } + float get_outerangle() { return _outer_angle; } + float get_outergain() { return _outer_gain; } /** * Set velocity of the sound source (uses same coordinate system as opengl) diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index c8bd635c..cbb137ef 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -274,6 +274,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const string& refname ) return false; } + if (_working) sgrp->activate(); _sample_groups[refname] = sgrp; return true; @@ -502,8 +503,8 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt, ALboolean loop; alutLoadWAVFile( fname, &format, &data, &size, &freq, &loop ); # endif - ALenum error = alutGetError(); - if ( error != ALUT_ERROR_NO_ERROR ) { + ALenum error = alGetError(); + if ( error != AL_NO_ERROR ) { string msg = "Failed to load wav file: "; msg.append(alutGetErrorString(error)); throw sg_io_exception(msg.c_str(), sg_location(samplepath));