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_HXX
00034 #define _SG_SOUNDMGR_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 #include <plib/sl.h>
00046 #include <plib/sm.h>
00047
00048 #include "sample_plib.hxx"
00049
00050 SG_USING_STD(map);
00051 SG_USING_STD(string);
00052
00053
00054 typedef struct {
00055 int n;
00056 slSample *sample;
00057 } sample_ref;
00058
00059 typedef map < string, sample_ref * > sample_map;
00060 typedef sample_map::iterator sample_map_iterator;
00061 typedef sample_map::const_iterator const_sample_map_iterator;
00062
00063 typedef map < string, SGSoundSample * > sound_map;
00064 typedef sound_map::iterator sound_map_iterator;
00065 typedef sound_map::const_iterator const_sound_map_iterator;
00066
00067
00071 class SGSoundMgr
00072 {
00073
00074 slScheduler *audio_sched;
00075 smMixer *audio_mixer;
00076
00077 sound_map sounds;
00078 sample_map samples;
00079
00080 double safety;
00081
00082 public:
00083
00084 SGSoundMgr();
00085 ~SGSoundMgr();
00086
00087
00091 void init();
00092
00093
00097 void bind ();
00098
00099
00103 void unbind ();
00104
00105
00109 void update(double dt);
00110
00111
00115 void pause ();
00116
00117
00121 void resume ();
00122
00123
00127 inline bool is_working() const { return !audio_sched->notWorking(); }
00128
00132 inline void reinit() { init(); }
00133
00137 bool add( SGSoundSample *sound, const string& refname);
00138
00151 SGSoundSample *add( const string& refname,
00152 const char *path, const char *file = NULL );
00153
00157 bool remove( const string& refname );
00158
00162 bool exists( const string& refname );
00163
00168 SGSoundSample *find( const string& refname );
00169
00174 bool play_looped( const string& refname );
00175
00179 bool play_once( const string& refname );
00180
00184 bool is_playing( const string& refname );
00185
00189 bool stop( const string& refname );
00190
00194 inline slScheduler *get_scheduler( ) { return audio_sched; };
00195 };
00196
00197
00198 #endif // _SG_SOUNDMGR_HXX
00199
00200