]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/soundmgr_openal.hxx
Merge branch 'jmt/magvar' into next
[simgear.git] / simgear / sound / soundmgr_openal.hxx
index 5d86c6bebd8bfdfbee06e2217201d6af4f519bf4..9b9e0a126fd52e8b979f763d4f8681d38bd19589 100644 (file)
 # include <AL/alut.h>
 #endif
 
+#ifndef ALC_ALL_DEVICES_SPECIFIER
+# define ALC_ALL_DEVICES_SPECIFIER     0x1013
+#endif
+
 #include <simgear/compiler.h>
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/math/SGMathFwd.hxx>
@@ -95,11 +99,10 @@ public:
     SGSoundMgr();
     ~SGSoundMgr();
 
-    void init();
+    void init(const char *devname = NULL);
     void bind();
     void unbind();
-    void update(double dt) {};
-    void update_late(double dt);
+    void update(double dt);
     
     void suspend();
     void resume();
@@ -154,13 +157,15 @@ public:
     SGSampleGroup *find( const string& refname, bool create = false );
 
     /**
-     * Set the position of the sound manager.
-     * This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
+     * Set the Cartesian position of the sound manager.
      * @param pos OpenAL listener position
      */
-    void set_position( const SGVec3d& pos ) {
-        _position = -pos;
-        _changed = true;
+    void set_position( const SGVec3d& pos, const SGGeod& pos_geod ) {
+        _base_pos = pos; _geod_pos = pos_geod; _changed = true;
+    }
+
+    void set_position_offset( const SGVec3d& pos ) {
+        _offset_pos = pos; _changed = true;
     }
 
     /**
@@ -168,16 +173,15 @@ public:
      * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
      * @return OpenAL listener position
      */
-    SGVec3f get_position() { return toVec3f(_position); }
+    SGVec3d& get_position() { return _absolute_pos; }
 
     /**
-     * Set the velocity vector of the sound manager
-     * This is in the same coordinate system as OpenGL; y=up, z=back, x=right.
-     * @param vel Velocity vector of the OpenAL listener
+     * Set the velocity vector (in meters per second) of the sound manager
+     * This is the horizontal local frame; x=north, y=east, z=down
+     * @param Velocity vector
      */
-    void set_velocity( SGVec3d& dir ) {
-        _velocity = dir;
-        _changed = true;
+    void set_velocity( const SGVec3d& vel ) {
+        _velocity = vel; _changed = true;
     }
 
     /**
@@ -191,7 +195,9 @@ public:
      * 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 ) {
+        _orientation = ori; _changed = true;
+    }
 
     /**
      * Get the orientation of the sound manager
@@ -258,6 +264,14 @@ public:
      */
     inline bool has_changed() { return _changed; }
 
+    /**
+     * Some implementations seem to need the velocity miltyplied by a
+     * factor of 100 to make them distinct. I've not found if this is
+     * a problem in the implementation or in out code. Until then
+     * this function is used to detect the problematic implementations.
+     */
+    inline bool bad_doppler_effect() { return _bad_doppler; }
+
     /**
      * Load a sample file and return it's configuration and data.
      * @param samplepath Path to the file to load
@@ -270,6 +284,17 @@ public:
     bool load(string &samplepath, void **data, int *format,
                                          size_t *size, int *freq );
 
+    /**
+     * Get a list of available playback devices.
+     */
+    vector<const char*> get_available_devices();
+
+    /**
+     * Get the current OpenAL vendor or rendering backend.
+     */
+    const string& get_vendor() { return _vendor; }
+    const string& get_renderer() { return _renderer; }
+
 private:
     static int _alut_init;
 
@@ -282,7 +307,10 @@ private:
     ALCcontext *_context;
 
     // Position of the listener.
-    SGVec3d _position;
+    SGVec3d _absolute_pos;
+    SGVec3d _offset_pos;
+    SGVec3d _base_pos;
+    SGGeod _geod_pos;
 
     // Velocity of the listener.
     SGVec3d _velocity;
@@ -298,13 +326,16 @@ private:
     vector<ALuint> _free_sources;
     vector<ALuint> _sources_in_use;
 
-    char *_devname;
+    bool _bad_doppler;
+    string _renderer;
+    string _vendor;
 
     bool testForALError(string s);
     bool testForALCError(string s);
     bool testForALUTError(string s);
     bool testForError(void *p, string s);
 
+    void update_pos_and_orientation();
     void update_sample_config( SGSampleGroup *sound );
 };