00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #ifndef _SG_SAMPLE_GROUP_OPENAL_HXX
00030 #define _SG_SAMPLE_GROUP_OPENAL_HXX 1
00031
00032 #ifndef __cplusplus
00033 # error This library requires C++
00034 #endif
00035
00036 #if defined(__APPLE__)
00037 # include <OpenAL/al.h>
00038 #elif defined(OPENALSDK)
00039 # include <al.h>
00040 #else
00041 # include <AL/al.h>
00042 #endif
00043
00044 #include <string>
00045 #include <vector>
00046 #include <map>
00047
00048 #include <simgear/compiler.h>
00049 #include <simgear/math/SGMath.hxx>
00050 #include <simgear/structure/SGReferenced.hxx>
00051 #include <simgear/structure/SGSharedPtr.hxx>
00052 #include <simgear/structure/exception.hxx>
00053
00054 #include "sample_openal.hxx"
00055
00056 using std::map;
00057 using std::string;
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 class SGSoundMgr;
00064
00065 class SGSampleGroup : public SGReferenced
00066 {
00067 public:
00068
00073 SGSampleGroup ();
00074
00082 SGSampleGroup ( SGSoundMgr *smgr, const string &refname );
00083
00087 ~SGSampleGroup ();
00088
00092 inline void activate() { _active = true; }
00093
00100 virtual void update (double dt);
00101
00108 bool add( SGSharedPtr<SGSoundSample> sound, const string& refname );
00109
00115 bool remove( const string& refname );
00116
00122 bool exists( const string& refname );
00123
00129 SGSoundSample *find( const string& refname );
00130
00134 void stop();
00135
00139 void suspend();
00140
00144 void resume();
00145
00152 bool play( const string& refname, bool looping );
00153
00159 inline bool play_looped( const string& refname ) {
00160 return play( refname, true );
00161 }
00162
00168 inline bool play_once( const string& refname ) {
00169 return play( refname, false );
00170 }
00171
00177 bool is_playing( const string& refname );
00178
00184 bool stop( const string& refname );
00185
00190 void set_volume( float vol );
00191
00197 void set_velocity( const SGVec3d& vel ) {
00198 _velocity = vel; _changed = true;
00199 }
00200
00206 void set_position_geod( const SGGeod& pos ) {
00207 _base_pos = pos; _changed = true;
00208 }
00209
00214 void set_orientation( const SGQuatd& ori ) {
00215 _orientation = ori; _changed = true;
00216 }
00217
00221 void tie_to_listener() { _tied_to_listener = true; }
00222
00223 protected:
00224 SGSoundMgr *_smgr;
00225 string _refname;
00226 bool _active;
00227
00228 private:
00229 bool _changed;
00230 bool _pause;
00231 float _volume;
00232 bool _tied_to_listener;
00233
00234 SGVec3d _velocity;
00235 SGGeod _base_pos;
00236 SGQuatd _orientation;
00237
00238 sample_map _samples;
00239 std::vector< SGSharedPtr<SGSoundSample> > _removed_samples;
00240
00241 bool testForALError(string s);
00242 bool testForError(void *p, string s);
00243
00244 void update_pos_and_orientation();
00245 void update_sample_config( SGSoundSample *sound );
00246 };
00247
00248 #endif // _SG_SAMPLE_GROUP_OPENAL_HXX
00249