X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fsoundmgr_openal.hxx;h=749d84272bffd28f78e313f96d9819a058c375e7;hb=04a47dfb8d96a58352b16658eb12d4aed90a97e8;hp=ac94788f8a48feb5f12fafc9bfa5671fe515ee90;hpb=31dd77c6949818f8b3b51832bbf06038ea4b7427;p=simgear.git diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index ac94788f..749d8427 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -35,28 +35,19 @@ #ifndef _SG_SOUNDMGR_OPENAL_HXX #define _SG_SOUNDMGR_OPENAL_HXX 1 -#ifndef __cplusplus -# error This library requires C++ -#endif - #include #include #include #if defined(__APPLE__) -# define AL_ILLEGAL_ENUM AL_INVALID_ENUM -# define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION # include # include -# include #elif defined(OPENALSDK) # include # include -# include #else # include # include -# include #endif #include @@ -64,9 +55,6 @@ #include #include "sample_group.hxx" -#include "sample_openal.hxx" - -using std::string; struct refUint { unsigned int refctr; @@ -77,11 +65,11 @@ struct refUint { ~refUint() {}; }; -typedef std::map < string, refUint > buffer_map; +typedef std::map < std::string, refUint > buffer_map; typedef buffer_map::iterator buffer_map_iterator; typedef buffer_map::const_iterator const_buffer_map_iterator; -typedef std::map < string, SGSharedPtr > sample_group_map; +typedef std::map < std::string, SGSharedPtr > sample_group_map; typedef sample_group_map::iterator sample_group_map_iterator; typedef sample_group_map::const_iterator const_sample_group_map_iterator; @@ -95,11 +83,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(); @@ -116,13 +103,13 @@ public: /** * Set the sound manager to a working condition. */ - inline void activate() { _active = true; } + void activate(); /** * Test is the sound manager is in an active and working condition. * @return true is the sound manager is active */ - inline bool is_active() const { return (_working && _active); } + inline bool is_active() const { return _active; } /** * Register a sample group to the sound manager. @@ -130,21 +117,21 @@ public: * @param refname Reference name of the sample group * @return true if successful, false otherwise */ - bool add( SGSampleGroup *sgrp, const string& refname ); + bool add( SGSampleGroup *sgrp, const std::string& refname ); /** * Remove a sample group from the sound manager. * @param refname Reference name of the sample group to remove * @return true if successful, false otherwise */ - bool remove( const string& refname ); + bool remove( const std::string& refname ); /** * Test if a specified sample group is registered at the sound manager * @param refname Reference name of the sample group test for * @return true if the specified sample group exists */ - bool exists( const string& refname ); + bool exists( const std::string& refname ); /** * Find a specified sample group in the sound manager @@ -154,13 +141,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 +157,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 +179,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 +248,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 +268,17 @@ public: bool load(string &samplepath, void **data, int *format, size_t *size, int *freq ); + /** + * Get a list of available playback devices. + */ + std::vector get_available_devices(); + + /** + * Get the current OpenAL vendor or rendering backend. + */ + const std::string& get_vendor() { return _vendor; } + const std::string& get_renderer() { return _renderer; } + private: static int _alut_init; @@ -282,7 +291,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; @@ -295,16 +307,19 @@ private: sample_group_map _sample_groups; buffer_map _buffers; - vector _free_sources; - vector _sources_in_use; + std::vector _free_sources; + std::vector _sources_in_use; - char *_devname; + bool _bad_doppler; + std::string _renderer; + std::string _vendor; - bool testForALError(string s); - bool testForALCError(string s); - bool testForALUTError(string s); - bool testForError(void *p, string s); + bool testForALError(std::string s); + bool testForALCError(std::string s); + bool testForALUTError(std::string s); + bool testForError(void *p, std::string s); + void update_pos_and_orientation(); void update_sample_config( SGSampleGroup *sound ); };