]> git.mxchange.org Git - simgear.git/commitdiff
Remove duplicate members in SGSampleQueue.
authorJames Turner <zakalawe@mac.com>
Mon, 19 Nov 2012 15:33:53 +0000 (15:33 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 19 Nov 2012 15:33:53 +0000 (15:33 +0000)
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
simgear/sound/openal_test4.cxx
simgear/sound/sample_openal.cxx
simgear/sound/sample_openal.hxx
simgear/sound/sample_queue.cxx
simgear/sound/sample_queue.hxx
simgear/sound/soundmgr_openal.cxx

index a36af07bf6803b26608af43c4bc86df8d8532b76..bbf5b089633aa078aaa92a0db48d10168fbd47df 100644 (file)
@@ -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);
index 866426d577e56db7eb659adb2c0895dd4bd663a1..eaf2bcab56c8327cffb6e34657febd32b9d3151d 100644 (file)
@@ -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 );
index fb72566ca38cfc26d7bd6f8e92209aa42ebd7c94..1fc11661d23b4af0913d8a1bf56cb119e034b838 100644 (file)
@@ -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)
index aa9c893d9d27f89ed35dbcde15c7f72f5c271c80..ba3fef3d3ac750504e77f3abb63f91261b6d0f9a 100644 (file)
@@ -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;
index a99a4a3d0074bada8aa2c6100bf491e385b9e37a..f74be5bf054c565ac810fd9d7956c893ff4a1e72 100644 (file)
@@ -1,3 +1,4 @@
+
 // queue.cxx -- Audio sample encapsulation class
 // 
 // Written by Curtis Olson, started April 2004.
 
 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<num; i++) {
@@ -87,13 +71,14 @@ void SGSampleQueue::stop()
         alDeleteBuffers(1, &buffer);
     }
     _buffers.clear();
-
+#endif
     _playing = false;
     _changed = true;
 }
 
 void SGSampleQueue::add( const void* smp_data, size_t len )
 {
+#ifdef ENABLE_SOUND
     const ALvoid *data = (const ALvoid *)smp_data;
     ALuint buffer;
     ALint num;
@@ -114,14 +99,13 @@ void SGSampleQueue::add( const void* smp_data, size_t len )
         alBufferData(buffer, _format, data, len, _freq);
         _buffers.push_back(buffer);
     }
+#endif
 }
 
 void SGSampleQueue::set_source( unsigned int sid )
 {
-    _source = sid;
-    _valid_source = true;
-    _changed = true;
-
+    SGSoundSample::set_source(sid);
+#ifdef ENABLE_SOUND
     ALuint num = _buffers.size();
     for (unsigned int i=0; i < num; i++)
     {
@@ -129,7 +113,7 @@ void SGSampleQueue::set_source( unsigned int sid )
         alSourceQueueBuffers(_source, 1, &buffer);
     }
     _buffers.clear();
-
+#endif
 }
 
 string SGSampleQueue::random_string() {
index dedaee3ce43fbbfcb275775884a3198ca62d6ce3..781aaed50749dc0980e7e3ca529962d8b92a78ff 100644 (file)
@@ -80,23 +80,6 @@ public:
      */
     virtual void set_source(unsigned int sid);
 
-    /**
-     * Get the OpenAL source id of this source
-     * @return OpenAL source-id
-     */
-    virtual inline 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; }
-
-    /**
-     * Set the source-id of this audio sample to invalid.
-     */
-    virtual inline void no_valid_source() { _valid_source = false; }
-
     /**
      * Test if the buffer-id of this audio sample may be passed to OpenAL.
      * @return false for sample queue
@@ -106,46 +89,11 @@ public:
     inline virtual bool is_queue() const { return true; }
 
 private:
-
-    // Position of the source sound.
-    SGVec3d _absolute_pos;      // absolute position
-    SGVec3d _relative_pos;      // position relative to the base position
-    SGVec3d _direction;         // orientation offset
-    SGVec3f _velocity;          // Velocity of the source sound.
-
-    // The position and orientation of this sound
-    SGQuatd _orientation;       // base orientation
-    SGVec3f _orivec;           // orientation vector for OpenAL
-    SGVec3d _base_pos;         // base position
-
-    SGQuatd _rotation;
-
     std::string _refname;      // sample name
     std::vector<unsigned int> _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();
 };
index b1091aa59dcde6231ec2522346f5879a79d31137..3446727df5406bec22c753dcfbcf3e94d9e51864 100644 (file)
@@ -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