From 0b26c69222fdb27776767759e37fecc402c578ea Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 19 Nov 2012 15:33:53 +0000 Subject: [PATCH] Remove duplicate members in SGSampleQueue. Remove duplicate members shared by SGSoundSample and SGSampleQueue (which inherits from it). Change SGSoundSample to expose some members as protected data for access by the sample-queue, and hence share nearly all the methods. Also remove 'inline' keyword from virtual methods. --- simgear/sound/openal_test3.cxx | 2 +- simgear/sound/openal_test4.cxx | 6 ++-- simgear/sound/sample_openal.cxx | 50 +++++++++++++++-------------- simgear/sound/sample_openal.hxx | 28 +++++++++-------- simgear/sound/sample_queue.cxx | 42 ++++++++----------------- simgear/sound/sample_queue.hxx | 52 ------------------------------- simgear/sound/soundmgr_openal.cxx | 2 +- 7 files changed, 60 insertions(+), 122 deletions(-) diff --git a/simgear/sound/openal_test3.cxx b/simgear/sound/openal_test3.cxx index a36af07b..bbf5b089 100644 --- a/simgear/sound/openal_test3.cxx +++ b/simgear/sound/openal_test3.cxx @@ -43,7 +43,7 @@ int main( int argc, char *argv[] ) { printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n"); pos = SGGeod::fromDeg(9.99,-9.99); - sample1->set_position( SGVec3d::fromGeod(SGGeod::fromDeg(10,-10)) ); + sgr->set_position_geod( SGGeod::fromDeg(10,-10) ); smgr->set_position( SGVec3d::fromGeod(pos), pos ); sample1->play_looped(); smgr->update(1.0); diff --git a/simgear/sound/openal_test4.cxx b/simgear/sound/openal_test4.cxx index 866426d5..eaf2bcab 100644 --- a/simgear/sound/openal_test4.cxx +++ b/simgear/sound/openal_test4.cxx @@ -27,7 +27,7 @@ int main( int argc, char *argv[] ) { sgr = smgr->find("default", true); smgr->set_volume(0.9); smgr->activate(); - + smgr->set_position( SGVec3d::fromGeod(SGGeod()), SGGeod() ); void *data; size_t len; @@ -36,6 +36,8 @@ int main( int argc, char *argv[] ) { smgr->load(file, &data, &fmt, &len, &freq); squeue = new SGSampleQueue( freq, fmt ); + squeue->set_volume(1.0); + sgr->add(squeue, "queue"); squeue->add( data, len ); @@ -49,7 +51,7 @@ int main( int argc, char *argv[] ) { printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n"); pos = SGGeod::fromDeg(9.99,-9.99); - squeue->set_position( SGVec3d::fromGeod(SGGeod::fromDeg(10,-10)) ); + sgr->set_position_geod( SGGeod::fromDeg(10,-10) ); smgr->set_position( SGVec3d::fromGeod(pos), pos ); squeue->add( data, len ); diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index fb72566c..1fc11661 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -38,6 +38,8 @@ #include "sample_openal.hxx" #include "soundmgr_openal_private.hxx" +#define AL_FALSE 0 + using std::string; // @@ -46,6 +48,12 @@ using std::string; // empty constructor SGSoundSample::SGSoundSample() : + _format(AL_FORMAT_MONO8), + _size(0), + _freq(0), + _changed(true), + _valid_source(false), + _source(SGSoundMgr::NO_SOURCE), _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), @@ -56,13 +64,8 @@ SGSoundSample::SGSoundSample() : _rotation(SGQuatd::zeros()), _refname(random_string()), _data(NULL), - _format(AL_FORMAT_MONO8), - _size(0), - _freq(0), _valid_buffer(false), _buffer(SGSoundMgr::NO_BUFFER), - _valid_source(false), - _source(SGSoundMgr::NO_SOURCE), _inner_angle(360.0), _outer_angle(360.0), _outer_gain(0.0), @@ -73,7 +76,6 @@ SGSoundSample::SGSoundSample() : _max_dist(3000.0), _loop(AL_FALSE), _playing(false), - _changed(true), _static_changed(true), _out_of_range(false), _is_file(false) @@ -82,6 +84,12 @@ SGSoundSample::SGSoundSample() : // constructor SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) : + _format(AL_FORMAT_MONO8), + _size(0), + _freq(0), + _changed(true), + _valid_source(false), + _source(SGSoundMgr::NO_SOURCE), _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), @@ -92,13 +100,8 @@ SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) : _rotation(SGQuatd::zeros()), _refname(file), _data(NULL), - _format(AL_FORMAT_MONO8), - _size(0), - _freq(0), _valid_buffer(false), _buffer(SGSoundMgr::NO_BUFFER), - _valid_source(false), - _source(SGSoundMgr::NO_SOURCE), _inner_angle(360.0), _outer_angle(360.0), _outer_gain(0.0), @@ -109,7 +112,6 @@ SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) : _max_dist(3000.0), _loop(AL_FALSE), _playing(false), - _changed(true), _static_changed(true), _out_of_range(false), _is_file(true) @@ -121,6 +123,12 @@ SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) : // constructor SGSoundSample::SGSoundSample( const unsigned char** data, int len, int freq, int format ) : + _format(format), + _size(len), + _freq(freq), + _changed(true), + _valid_source(false), + _source(SGSoundMgr::NO_SOURCE), _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), @@ -130,13 +138,8 @@ SGSoundSample::SGSoundSample( const unsigned char** data, _base_pos(SGVec3d::zeros()), _rotation(SGQuatd::zeros()), _refname(random_string()), - _format(format), - _size(len), - _freq(freq), _valid_buffer(false), _buffer(SGSoundMgr::NO_BUFFER), - _valid_source(false), - _source(SGSoundMgr::NO_SOURCE), _inner_angle(360.0), _outer_angle(360.0), _outer_gain(0.0), @@ -147,7 +150,6 @@ SGSoundSample::SGSoundSample( const unsigned char** data, _max_dist(3000.0), _loop(AL_FALSE), _playing(false), - _changed(true), _static_changed(true), _out_of_range(false), _is_file(false) @@ -158,6 +160,12 @@ SGSoundSample::SGSoundSample( const unsigned char** data, // constructor SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : + _format(format), + _size(len), + _freq(freq), + _changed(true), + _valid_source(false), + _source(SGSoundMgr::NO_SOURCE), _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), @@ -167,13 +175,8 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : _base_pos(SGVec3d::zeros()), _rotation(SGQuatd::zeros()), _refname(random_string()), - _format(format), - _size(len), - _freq(freq), _valid_buffer(false), _buffer(SGSoundMgr::NO_BUFFER), - _valid_source(false), - _source(SGSoundMgr::NO_SOURCE), _inner_angle(360.0), _outer_angle(360.0), _outer_gain(0.0), @@ -184,7 +187,6 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : _max_dist(3000.0), _loop(AL_FALSE), _playing(false), - _changed(true), _static_changed(true), _out_of_range(false), _is_file(false) diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index aa9c893d..ba3fef3d 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -194,7 +194,7 @@ public: * Set the source id of this source * @param sid OpenAL source-id */ - virtual inline void set_source(unsigned int sid) { + virtual void set_source(unsigned int sid) { _source = sid; _valid_source = true; _changed = true; } @@ -202,18 +202,18 @@ public: * Get the OpenAL source id of this source * @return OpenAL source-id */ - virtual inline unsigned int get_source() { return _source; } + virtual unsigned int get_source() { return _source; } /** * Test if the source-id of this audio sample may be passed to OpenAL. * @return true if the source-id is valid */ - virtual inline bool is_valid_source() const { return _valid_source; } + virtual bool is_valid_source() const { return _valid_source; } /** * Set the source-id of this audio sample to invalid. */ - virtual inline void no_valid_source() { _valid_source = false; } + virtual void no_valid_source() { _valid_source = false; } /** * Set the OpenAL buffer-id of this source @@ -462,6 +462,16 @@ public: void update_pos_and_orientation(); +protected: + int _format; + size_t _size; + int _freq; + bool _changed; + + // Sources are points emitting sound. + bool _valid_source; + unsigned int _source; + private: // Position of the source sound. @@ -481,18 +491,11 @@ private: unsigned char* _data; // configuration values - int _format; - size_t _size; - int _freq; - + // Buffers hold sound data. bool _valid_buffer; unsigned int _buffer; - // Sources are points emitting sound. - bool _valid_source; - unsigned int _source; - // The orientation of this sound (direction and cut-off angles) float _inner_angle; float _outer_angle; @@ -506,7 +509,6 @@ private: bool _loop; bool _playing; - bool _changed; bool _static_changed; bool _out_of_range; bool _is_file; diff --git a/simgear/sound/sample_queue.cxx b/simgear/sound/sample_queue.cxx index a99a4a3d..f74be5bf 100644 --- a/simgear/sound/sample_queue.cxx +++ b/simgear/sound/sample_queue.cxx @@ -1,3 +1,4 @@ + // queue.cxx -- Audio sample encapsulation class // // Written by Curtis Olson, started April 2004. @@ -39,37 +40,19 @@ using std::string; +#define ENABLE_SOUND + // // SGSampleQueue // // empty constructor SGSampleQueue::SGSampleQueue( int freq, int format ) : - _absolute_pos(SGVec3d::zeros()), - _relative_pos(SGVec3d::zeros()), - _direction(SGVec3d::zeros()), - _velocity(SGVec3f::zeros()), - _orientation(SGQuatd::zeros()), - _orivec(SGVec3f::zeros()), - _base_pos(SGVec3d::zeros()), - _rotation(SGQuatd::zeros()), _refname(random_string()), - _format(format), - _freq(freq), - _valid_source(false), - _source(SGSoundMgr::NO_SOURCE), - _inner_angle(360.0), - _outer_angle(360.0), - _outer_gain(0.0), - _pitch(1.0), - _volume(1.0), - _master_volume(1.0), - _reference_dist(500.0), - _max_dist(3000.0), - _loop(false), - _playing(false), - _changed(true) + _playing(false) { + _freq = freq; + _format = format; _buffers.clear(); } @@ -79,6 +62,7 @@ SGSampleQueue::~SGSampleQueue() { void SGSampleQueue::stop() { +#ifdef ENABLE_SOUND ALint num; alGetSourcei(_source, AL_BUFFERS_PROCESSED, &num); for (int i=0; i _buffers; unsigned int _buffer; - // configuration values - int _format; - int _freq; - - // Sources are points emitting sound. - bool _valid_source; - unsigned int _source; - - // The orientation of this sound (direction and cut-off angles) - float _inner_angle; - float _outer_angle; - float _outer_gain; - - float _pitch; - float _volume; - float _master_volume; - float _reference_dist; - float _max_dist; - bool _loop; - bool _playing; - bool _changed; std::string random_string(); }; diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index b1091aa5..3446727d 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -129,13 +129,13 @@ SGSoundMgr::SGSoundMgr() : _changed(true), _volume(0.0), _offset_pos(SGVec3d::zeros()), - _geod_pos(SGGeod::fromCart(SGVec3d::zeros())), _velocity(SGVec3d::zeros()), _bad_doppler(false), _renderer("unknown"), _vendor("unknown") { d.reset(new SoundManagerPrivate); + d->_base_pos = SGVec3d::fromGeod(_geod_pos); } // destructor -- 2.39.5