SGSampleGroup::SGSampleGroup () :
_smgr(NULL),
_active(false),
- _changed(true),
- _position_changed(true),
_position(SGVec3d::zeros().data()),
- _orientation(SGVec3f::zeros().data())
+ _orientation(SGVec3f::zeros().data()),
+ _tied_to_listener(false)
{
_samples.clear();
}
SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
_smgr(smgr),
_active(false),
- _changed(true),
- _position_changed(true),
_position(SGVec3d::zeros().data()),
- _orientation(SGVec3f::zeros().data())
+ _orientation(SGVec3f::zeros().data()),
+ _tied_to_listener(false)
{
_smgr->add(this, refname);
_active = _smgr->is_working();
sample->set_buffer(buffer);
}
+ if ( _tied_to_listener && _smgr->has_changed() ) {
+ sample->set_base_position( _smgr->get_position_vec() );
+ sample->set_orientation( _smgr->get_direction() );
+ sample->set_velocity( _smgr->get_velocity() );
+ }
+
// start playing the sample
ALuint buffer = sample->get_buffer();
ALuint source = _smgr->request_source();
return;
}
- sample_map_iterator sample_current = _samples.begin();
- sample_map_iterator sample_end = _samples.end();
- for ( ; sample_current != sample_end; ++sample_current ) {
- SGSoundSample *sample = sample_current->second;
- sample->set_base_position( pos );
+ if ( !_tied_to_listener ) {
+ sample_map_iterator sample_current = _samples.begin();
+ sample_map_iterator sample_end = _samples.end();
+ for ( ; sample_current != sample_end; ++sample_current ) {
+ SGSoundSample *sample = sample_current->second;
+ sample->set_base_position( pos );
+ }
}
}
*/
void load_file(SGSoundSample *sound);
+ inline void tie_to_listener() { _tied_to_listener = true; }
+
+
protected:
SGSoundMgr *_smgr;
bool _active;
private:
- bool _changed;
- bool _position_changed;
-
float _volume;
-
SGVec3d _position;
SGVec3f _orientation;
+ bool _tied_to_listener;
sample_map _samples;
// run the audio scheduler
void SGSoundMgr::update_late( double dt ) {
if (_working) {
- // alcSuspendContext(_context);
+ alcSuspendContext(_context);
sample_group_map_iterator sample_grp_current = _sample_groups.begin();
sample_group_map_iterator sample_grp_end = _sample_groups.end();
testForALError("update");
_changed = false;
}
- // alcProcessContext(_context);
+ alcProcessContext(_context);
}
}
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
_changed = true;
}
- inline double *get_position() {
- return _listener_pos.data();
- }
+ inline double *get_position() { return _listener_pos.data(); }
+ inline SGVec3d get_position_vec() { return _listener_pos; };
/**
* set the velocity of the listener (in opengl coordinates)
_changed = true;
}
+ inline SGVec3f get_velocity() { return _listener_vel; }
+
/**
* set the orientation of the listener (in opengl coordinates)
*/
void set_orientation( SGQuatd ori );
+ inline SGVec3f get_direction() {
+ return SGVec3f(_listener_ori[0], _listener_ori[1], _listener_ori[2]);
+ }
+
enum {
NO_SOURCE = (unsigned int)-1,
NO_BUFFER = (unsigned int)-1
*/
void release_source( unsigned int source );
+
+ /**
+ * returns true if the position has changed
+ */
+ inline bool has_changed() { return _changed; }
+
static bool load(string &samplepath, void **data, int *format,
unsigned int*size, int *freq );
+
private:
static int _alut_init;