]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_openal.hxx
Merge branch 'jmt/magvar' into next
[simgear.git] / simgear / sound / sample_openal.hxx
index 070cba89815e1cda0f339d516c13ed007d1915a9..d2cb1824763a7a76b3769397bc80a0956c9464e0 100644 (file)
@@ -35,7 +35,6 @@
 #endif
 
 #include <string>
-#include <memory>
 
 #include <simgear/compiler.h>
 #include <simgear/debug/logstream.hxx>
@@ -70,12 +69,14 @@ public:
      * Constructor.
      * @param data Pointer to a memory buffer containing this audio sample data
        The application may free the data by calling free_data(), otherwise it
-       will be resident untill the class is destroyed.
+       will be resident untill the class is destroyed. This pointer will be
+       set to NULL after calling this function.
      * @param len Byte length of array
      * @param freq Frequency of the provided data (bytes per second)
      * @param format OpenAL format id of the data
      */
-    SGSoundSample( std::auto_ptr<unsigned char>& data, int len, int freq,
+    SGSoundSample( void** data, int len, int freq, int format=AL_FORMAT_MONO8 );
+    SGSoundSample( const unsigned char** data, int len, int freq,
                    int format = AL_FORMAT_MONO8 );
 
     /**
@@ -122,7 +123,7 @@ public:
      * 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.
@@ -150,24 +151,28 @@ public:
     inline bool is_playing() { return _playing; }
 
     /**
-     * sSt the data associated with this audio sample
+     * Set the data associated with this audio sample
      * @param data Pointer to a memory block containg this audio sample data.
+       This pointer will be set to NULL after calling this function.
      */
-    inline void set_data( std::auto_ptr<unsigned char>& data ) {
-        _data = data;
+    inline void set_data( const unsigned char **data ) {
+        _data = (unsigned char*)*data; *data = NULL;
+    }
+    inline void set_data( void **data ) {
+        _data = (unsigned char*)*data; *data = NULL;
     }
 
     /**
      * Return the data associated with this audio sample.
      * @return A pointer to this sound data of this audio sample.
      */
-    inline void* get_data() const { return _data.get(); }
+    inline void* get_data() const { return _data; }
 
     /**
      * Free the data associated with this audio sample
      */
     void free_data() {
-        free( _data.release() );
+        if ( _data != NULL ) free( _data ); _data = NULL;
     }
 
     /**
@@ -225,7 +230,10 @@ public:
      * Should be between 0.0 and 2.0 for maximum compatibility.
      * @param p Pitch
      */
-    inline void set_pitch( float p ) { _pitch = p; _changed = true; }
+    inline void set_pitch( float p ) {
+        if (p > 2.0) p = 2.0; else if (p < 0.01) p = 0.01;
+        _pitch = p; _changed = true;
+    }
 
     /**
      * Get the current pitch value of this audio sample.
@@ -240,6 +248,7 @@ public:
      * @param v Volume
      */
     inline void set_master_volume( float v ) {
+        if (v > 1.0) v = 1.0; else if (v < 0.0) v = 0.0;
         _master_volume = v; _changed = true;
     }
 
@@ -249,7 +258,10 @@ public:
      * volume.
      * @param v Volume
      */
-    inline void set_volume( float v ) { _volume = v; _changed = true; }
+    inline void set_volume( float v ) {
+        if (v > 1.0) v = 1.0; else if (v < 0.0) v = 0.0;
+        _volume = v; _changed = true;
+    }
 
     /**
      * Get the final volume value of this audio sample.
@@ -273,7 +285,7 @@ public:
      * Set the frequency (in Herz) of this audio sample.
      * @param freq Frequency
      */
-    inline void set_frequency( int freq ) { _freq = freq; _changed = true; }
+    inline void set_frequency( int freq ) { _freq = freq; }
 
     /**
      * Returns the frequency (in Herz) of this audio sample.
@@ -298,45 +310,55 @@ public:
      * This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
      * @param pos Relative position of this sound
      */
-    void set_relative_position( const SGVec3f& pos );
+    inline void set_relative_position( const SGVec3f& pos ) {
+        _relative_pos = toVec3d(pos); _changed = true;
+    }
 
     /**
-     * Set the base position of this sound in Geodetic coordinates.
-     * @param pos Geodetic position
+     * Set the base position in Cartesian coordinates
+     * @param pos position in Cartesian coordinates
      */
-    void set_position( const SGGeod& pos );
+    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
      */
-    float *get_position() const { return toVec3f(_absolute_pos).data(); }
+    SGVec3d& get_position() { return _absolute_pos; }
 
     /**
      * Set the orientation of this sound.
      * @param ori Quaternation containing the orientation information
      */
-    void set_orientation( const SGQuatd& ori );
+    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
      */
-    void set_direction( const SGVec3d& dir );
+    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 1 degree will result in 0.5 degrees to both sides.
+     * 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;
+        _inner_angle = inner; _outer_angle = outer; _outer_gain = gain;
         _static_changed = true;
     }
 
@@ -345,7 +367,7 @@ public:
      * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
      * @return Orientaton vector
      */
-    float *get_orientation() { return _orivec.data(); }
+    SGVec3f& get_orientation() { return _orivec; }
 
     /**
      * Get the inner angle of the audio cone.
@@ -367,10 +389,10 @@ public:
 
     /**
      * Set the velocity vector (in meters per second) of this sound.
-     * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
+     * This is in the local frame coordinate system; x=north, y=east, z=down
      * @param Velocity vector
      */
-    inline void set_velocity( const SGVec3d& vel ) {
+    inline void set_velocity( const SGVec3f& vel ) {
         _velocity = vel; _changed = true;
     }
 
@@ -379,7 +401,7 @@ public:
      * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
      * @return Velocity vector
      */
-    float *get_velocity() { return toVec3f(_velocity).data(); }
+    SGVec3f& get_velocity() { return _velocity; }
 
 
     /**
@@ -421,21 +443,25 @@ public:
      */
     inline std::string get_sample_name() const { return _refname; }
 
+    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
-    SGVec3d _velocity;          // Velocity of the source sound.
+    SGVec3f _velocity;          // Velocity of the source sound.
 
     // The position and orientation of this sound
     SGQuatd _orientation;       // base orientation
     SGVec3f _orivec;           // orientation vector for OpenAL
-    SGGeod _base_pos;          // base position
+    SGVec3d _base_pos;         // base position
+
+    SGQuatd _rotation;
 
     std::string _refname;      // name or file path
-    std::auto_ptr<unsigned char> _data;
+    unsigned char* _data;
 
     // configuration values
     int _format;
@@ -467,7 +493,6 @@ private:
     bool _static_changed;
     bool _is_file;
 
-    void update_absolute_position();
     string random_string();
 };