00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00033 #ifndef _SG_SOUNDMGR_OPENAL_HXX
00034 #define _SG_SOUNDMGR_OPENAL_HXX 1
00035
00036 #ifndef __cplusplus
00037 # error This library requires C++
00038 #endif
00039
00040 #include <simgear/compiler.h>
00041
00042 #include STL_STRING
00043 #include <map>
00044
00045 #if defined( __APPLE__ )
00046 # include <OpenAL/al.h>
00047 # include <OpenAL/alc.h>
00048 #else
00049 # include <AL/al.h>
00050 # include <AL/alc.h>
00051 #endif
00052
00053 #include "sample_openal.hxx"
00054
00055 SG_USING_STD(map);
00056 SG_USING_STD(string);
00057
00058
00059 typedef map < string, SGSharedPtr<SGSoundSample> > sample_map;
00060 typedef sample_map::iterator sample_map_iterator;
00061 typedef sample_map::const_iterator const_sample_map_iterator;
00062
00063
00067 class SGSoundMgr
00068 {
00069
00070 ALCdevice *dev;
00071 ALCcontext *context;
00072
00073
00074 ALfloat listener_pos[3];
00075
00076
00077 ALfloat listener_vel[3];
00078
00079
00080
00081 ALfloat listener_ori[6];
00082
00083 sample_map samples;
00084
00085 bool working;
00086 double safety;
00087
00088 public:
00089
00090 SGSoundMgr();
00091 ~SGSoundMgr();
00092
00093
00097 void init();
00098
00099
00103 void bind();
00104
00105
00109 void unbind();
00110
00111
00115 void update(double dt);
00116
00117
00121 void pause();
00122
00123
00127 void resume();
00128
00129
00133 inline bool is_working() const { return working; }
00134
00138 inline void reinit() { init(); }
00139
00143 bool add( SGSoundSample *sound, const string& refname);
00144
00148 bool remove( const string& refname );
00149
00153 bool exists( const string& refname );
00154
00159 SGSoundSample *find( const string& refname );
00160
00165 bool play_looped( const string& refname );
00166
00170 bool play_once( const string& refname );
00171
00175 bool is_playing( const string& refname );
00176
00180 bool stop( const string& refname );
00181
00186 inline void set_volume( const ALfloat vol ) {
00187 if ( vol > 0.0 ) {
00188 alListenerf( AL_GAIN, vol );
00189 }
00190 }
00191
00195 inline void set_listener_pos( ALfloat *pos ) {
00196 listener_pos[0] = pos[0];
00197 listener_pos[1] = pos[1];
00198 listener_pos[2] = pos[2];
00199 alListenerfv( AL_POSITION, listener_pos );
00200 }
00201
00205 inline void set_listener_vel( ALfloat *vel ) {
00206 listener_vel[0] = vel[0];
00207 listener_vel[1] = vel[1];
00208 listener_vel[2] = vel[2];
00209 #ifdef USE_OPEN_AL_DOPPLER
00210 alListenerfv( AL_VELOCITY, listener_vel );
00211 #endif
00212 }
00213
00225 inline void set_listener_orientation( ALfloat *ori ) {
00226 listener_ori[0] = ori[0];
00227 listener_ori[1] = ori[1];
00228 listener_ori[2] = ori[2];
00229 listener_ori[3] = ori[3];
00230 listener_ori[4] = ori[4];
00231 listener_ori[5] = ori[5];
00232 alListenerfv( AL_ORIENTATION, listener_ori );
00233 }
00234
00238 void set_source_pos_all( ALfloat *pos );
00239
00243 void set_source_vel_all( ALfloat *pos );
00244 };
00245
00246
00247 #endif // _SG_SOUNDMGR_OPENAL_HXX
00248
00249