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.
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);
sgr = smgr->find("default", true);
smgr->set_volume(0.9);
smgr->activate();
-
+ smgr->set_position( SGVec3d::fromGeod(SGGeod()), SGGeod() );
void *data;
size_t len;
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 );
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 );
#include "sample_openal.hxx"
#include "soundmgr_openal_private.hxx"
+#define AL_FALSE 0
+
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()),
_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),
_max_dist(3000.0),
_loop(AL_FALSE),
_playing(false),
- _changed(true),
_static_changed(true),
_out_of_range(false),
_is_file(false)
// 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()),
_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),
_max_dist(3000.0),
_loop(AL_FALSE),
_playing(false),
- _changed(true),
_static_changed(true),
_out_of_range(false),
_is_file(true)
// 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()),
_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),
_max_dist(3000.0),
_loop(AL_FALSE),
_playing(false),
- _changed(true),
_static_changed(true),
_out_of_range(false),
_is_file(false)
// 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()),
_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),
_max_dist(3000.0),
_loop(AL_FALSE),
_playing(false),
- _changed(true),
_static_changed(true),
_out_of_range(false),
_is_file(false)
* 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;
}
* 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
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.
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;
bool _loop;
bool _playing;
- bool _changed;
bool _static_changed;
bool _out_of_range;
bool _is_file;
+
// 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();
}
void SGSampleQueue::stop()
{
+#ifdef ENABLE_SOUND
ALint num;
alGetSourcei(_source, AL_BUFFERS_PROCESSED, &num);
for (int i=0; i<num; i++) {
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;
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++)
{
alSourceQueueBuffers(_source, 1, &buffer);
}
_buffers.clear();
-
+#endif
}
string SGSampleQueue::random_string() {
*/
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
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();
};
_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