+
+ /**
+ * Get the final volume value of this audio sample.
+ * @return Volume
+ */
+ inline float get_volume() { return _volume * _master_volume; }
+
+ /**
+ * Set the OpenAL format of this audio sample.
+ * @param format OpenAL format-id
+ */
+ inline void set_format( int format ) { _format = format; }
+
+ /**
+ * Returns the format of this audio sample.
+ * @return OpenAL format-id
+ */
+ inline int get_format() { return _format; }
+
+ /**
+ * Set the frequency (in Herz) of this audio sample.
+ * @param freq Frequency
+ */
+ inline void set_frequency( int freq ) { _freq = freq; }
+
+ /**
+ * Returns the frequency (in Herz) of this audio sample.
+ * @return Frequency
+ */
+ inline int get_frequency() { return _freq; }
+
+ /**
+ * Sets the size (in bytes) of this audio sample.
+ * @param size Data size
+ */
+ inline void set_size( size_t size ) { _size = size; }
+
+ /**
+ * Returns the size (in bytes) of this audio sample.
+ * @return Data size
+ */
+ inline size_t get_size() const { return _size; }
+
+ /**
+ * Set the position of this sound relative to the base position.
+ * This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
+ * @param pos Relative position of this sound
+ */
+ inline void set_relative_position( const SGVec3f& pos ) {
+ _relative_pos = toVec3d(pos); _changed = true;
+ }
+
+ /**
+ * Set the base position in Cartesian coordinates
+ * @param pos position in Cartesian coordinates
+ */
+ inline void set_position( const SGVec3d& pos ) {
+ _base_pos = pos; _changed = true;
+ }
+
+ /**
+ * Get the absolute position of this sound.
+ * This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
+ * @return Absolute position
+ */
+ SGVec3d& get_position() { return _absolute_pos; }
+
+ /**
+ * Set the orientation of this sound.
+ * @param ori Quaternation containing the orientation information
+ */
+ inline void set_orientation( const SGQuatd& ori ) {
+ _orientation = ori; _changed = true;
+ }
+
+ inline void set_rotation( const SGQuatd& ec2body ) {
+ _rotation = ec2body; _changed = true;
+ }
+
+ /**
+ * Set direction of this sound relative to the orientation.
+ * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
+ * @param dir Sound emission direction
+ */
+ inline void set_direction( const SGVec3f& dir ) {
+ _direction = toVec3d(dir); _static_changed = true;
+ }
+
+ /**
+ * Define the audio cone parameters for directional audio.
+ * Note: setting it to 2 degree will result in 1 degree to both sides.
+ * @param inner Inner cone angle (0 - 360 degrees)
+ * @param outer Outer cone angle (0 - 360 degrees)
+ * @param gain Remaining gain at the edge of the outer cone (0.0 - 1.0)
+ */
+ void set_audio_cone( float inner, float outer, float gain ) {
+ _inner_angle = inner; _outer_angle = outer; _outer_gain = gain;
+ _static_changed = true;
+ }
+
+ /**
+ * Get the orientation vector of this sound.
+ * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
+ * @return Orientaton vector
+ */
+ SGVec3f& get_orientation() { return _orivec; }
+
+ /**
+ * Get the inner angle of the audio cone.
+ * @return Inner angle in degrees
+ */
+ float get_innerangle() { return _inner_angle; }
+
+ /**
+ * Get the outer angle of the audio cone.
+ * @return Outer angle in degrees
+ */
+ float get_outerangle() { return _outer_angle; }
+
+ /**
+ * Get the remaining gain at the edge of the outer cone.
+ * @return Gain
+ */
+ float get_outergain() { return _outer_gain; }
+
+ /**
+ * Set the velocity vector (in meters per second) of this sound.
+ * This is in the local frame coordinate system; x=north, y=east, z=down
+ * @param Velocity vector
+ */
+ inline void set_velocity( const SGVec3f& vel ) {
+ _velocity = vel; _changed = true;
+ }
+
+ /**
+ * Get velocity vector (in meters per second) of this sound.
+ * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
+ * @return Velocity vector
+ */
+ SGVec3f& get_velocity() { return _velocity; }
+
+
+ /**
+ * Set reference distance (in meters) of this sound.
+ * This is the distance where the gain will be half.
+ * @param dist Reference distance
+ */
+ inline void set_reference_dist( float dist ) {
+ _reference_dist = dist; _static_changed = true;
+ }
+
+ /**
+ * Get reference distance ((in meters) of this sound.
+ * This is the distance where the gain will be half.
+ * @return Reference distance
+ */
+ inline float get_reference_dist() { return _reference_dist; }
+
+
+ /**
+ * Set maximum distance (in meters) of this sound.
+ * This is the distance where this sound is no longer audible.
+ * @param dist Maximum distance
+ */
+ inline void set_max_dist( float dist ) {
+ _max_dist = dist; _static_changed = true;
+ }
+
+ /**
+ * Get maximum distance (in meters) of this sound.
+ * This is the distance where this sound is no longer audible.
+ * @return dist Maximum distance
+ */
+ inline float get_max_dist() { return _max_dist; }
+
+ /**
+ * Get the reference name of this audio sample.
+ * @return Sample name
+ */
+ inline std::string get_sample_name() const { return _refname; }
+
+ inline virtual bool is_queue() const { return false; }
+
+ void update_pos_and_orientation();
+
+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; // name or file path
+ 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;
+ float _outer_gain;
+
+ float _pitch;
+ float _volume;
+ float _master_volume;
+ float _reference_dist;
+ float _max_dist;
+ bool _loop;
+
+ bool _playing;
+ bool _changed;
+ bool _static_changed;
+ bool _is_file;
+
+ string random_string();