sample1->set_pitch(1.0);
sample1->play_looped();
sgr->add(sample1, "sound1");
- smgr->update_late(1.0);
+ smgr->update(1.0);
printf("playing sample1\n");
sleep(1);
sample2->set_pitch(0.4);
sample2->play_looped();
sgr->add(sample2, "sound2");
- smgr->update_late(1.0);
+ smgr->update(1.0);
printf("playing sample2\n");
sleep(1);
sample3->set_pitch(0.8);
sample3->play_looped();
sgr->add(sample3, "sound3");
- smgr->update_late(1.0);
+ smgr->update(1.0);
printf("playing sample3\n");
sleep(1);
sample4->set_pitch(1.2);
sample4->play_looped();
sgr->add(sample4, "sound4");
- smgr->update_late(1.0);
+ smgr->update(1.0);
printf("playing sample4\n");
sleep(1);
sample5->set_pitch(1.6);
sample5->play_looped();
sgr->add(sample5, "sound5");
- smgr->update_late(1.0);
+ smgr->update(1.0);
printf("playing sample5\n");
sleep(1);
sample6->set_pitch(2.0);
sample6->play_looped();
sgr->add(sample6, "sound6");
- smgr->update_late(1.0);
+ smgr->update(1.0);
printf("playing sample6\n");
sleep(1);
for (int i=0; i<10; i++) {
sleep(1);
- smgr->update_late(1);
+ smgr->update(1);
}
sgr->stop("sound1");
sgr->stop("sound2");
sgr->stop("sound3");
sleep(0.5);
- smgr->update_late(0.5);
+ smgr->update(0.5);
sgr->stop("sound4");
sgr->stop("sound5");
sgr->stop("sound6");
- smgr->update_late(1);
+ smgr->update(1);
sleep(1);
smgr->unbind();
unsigned int size = _removed_samples.size();
for (unsigned int i=0; i<size; ) {
SGSoundSample *sample = _removed_samples[i];
- ALint result;
+ ALint result = AL_STOPPED;
+
+ if ( sample->is_valid_source() ) {
+ if ( sample->is_looping() ) {
+ sample->no_valid_source();
+ _smgr->release_source( sample->get_source() );
+ }
+ else
+ alGetSourcei( sample->get_source(), AL_SOURCE_STATE, &result );
+ }
- alGetSourcei( sample->get_source(), AL_SOURCE_STATE, &result );
if ( result == AL_STOPPED ) {
ALuint buffer = sample->get_buffer();
alDeleteBuffers( 1, &buffer );
sample->set_source( source );
update_sample_config( sample );
- ALboolean looping = sample->get_looping() ? AL_TRUE : AL_FALSE;
+ ALboolean looping = sample->is_looping() ? AL_TRUE : AL_FALSE;
alSourcei( source, AL_LOOPING, looping );
alSourcef( source, AL_ROLLOFF_FACTOR, 1.0 );
alSourcei( source, AL_SOURCE_RELATIVE, AL_FALSE );
float *position, *orientation, *velocity;
if ( _tied_to_listener ) {
position = _smgr->get_position().data();
- orientation = _smgr->get_velocity().data();
- velocity = _smgr->get_direction().data();
+ orientation = _smgr->get_direction().data();
+ velocity = _smgr->get_velocity().data();
} else {
sample->update_absolute_position();
position = sample->get_position();
- orientation = sample->get_velocity();
- velocity = sample->get_orientation();
+ orientation = sample->get_orientation();
+ velocity = sample->get_velocity();
}
+
if (dist(_smgr->get_position(), sample->get_position_vec()) > 50000)
printf("source and listener distance greater than 50km!\n");
if (isNaN(position)) printf("NaN in source position\n");
samplepath.append( file );
}
_refname = samplepath.str();
-
- SG_LOG( SG_GENERAL, SG_DEBUG, "From file sounds sample = "
- << samplepath.str() );
}
// constructor
// destructor
SGSoundSample::~SGSoundSample() {
- if (_data) free( _data );
- _data = NULL;
+ if (_data) free(_data);
}
void SGSoundSample::update_absolute_position() {
string SGSoundSample::random_string() {
static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- string rstr;
+ string rstr = "System generated name: ";
for (int i=0; i<10; i++) {
rstr.push_back( r[rand() % strlen(r)] );
}
* Check if this audio sample is set to be continuous looping.
* @return Return true if this audio sample is set to looping.
*/
- inline bool get_looping() { return _loop; }
+ inline bool is_looping() { return _loop; }
/**
* Schedule this audio sample to stop playing.
_position(SGVec3d::zeros()),
_velocity(SGVec3d::zeros()),
_orientation(SGQuatd::zeros()),
+ _orient_offs(SGQuatd::zeros()),
_devname(NULL)
{
#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
}
// run the audio scheduler
-void SGSoundMgr::update_late( double dt ) {
+void SGSoundMgr::update( double dt ) {
if (_active) {
sample_group_map_iterator sample_grp_current = _sample_groups.begin();
sample_group_map_iterator sample_grp_end = _sample_groups.end();
* is undefined. If the two vectors are linearly dependent,
* behavior is undefined.
*/
-void SGSoundMgr::set_orientation( SGQuatd ori )
+void SGSoundMgr::set_orientation( const SGQuatd& ori, const SGQuatd& offs )
{
_orientation = ori;
+ _orient_offs = offs;
- SGVec3d sgv_up = ori.rotate(SGVec3d::e2());
- SGVec3d sgv_at = ori.rotate(SGVec3d::e3());
+ SGVec3d sgv_up = _orient_offs.rotate(SGVec3d::e2());
+ SGVec3d sgv_at = _orient_offs.rotate(SGVec3d::e3());
_at_up_vec[0] = sgv_at[0];
_at_up_vec[1] = sgv_at[1];
_at_up_vec[2] = sgv_at[2];
void init();
void bind();
void unbind();
- void update(double dt) {};
- void update_late(double dt);
+ void update(double dt);
void suspend();
void resume();
* This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
* @param vel Velocity vector of the OpenAL listener
*/
- void set_velocity( SGVec3d& dir ) {
- _velocity = dir;
- _changed = true;
+ void set_velocity( SGVec3d& vel ) {
+ _velocity = vel; _changed = true;
}
/**
* Set the orientation of the sound manager
* @param ori Quaternation containing the orientation information
*/
- void set_orientation( SGQuatd ori );
+ void set_orientation( const SGQuatd& ori, const SGQuatd& offs );
/**
* Get the orientation of the sound manager
* @return Quaternation containing the orientation information
*/
inline const SGQuatd& get_orientation() { return _orientation; }
+ inline const SGQuatd& get_orientation_offset() { return _orient_offs; }
/**
* Get the direction vector of the sound manager
// Orientation of the listener.
// first 3 elements are "at" vector, second 3 are "up" vector
SGQuatd _orientation;
+ SGQuatd _orient_offs;
ALfloat _at_up_vec[6];
sample_group_map _sample_groups;