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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<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() {
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user