soundmgr_openal.hxx

00001 // soundmgr.hxx -- Sound effect management class
00002 //
00003 // Sound manager initially written by David Findlay
00004 // <david_j_findlay@yahoo.com.au> 2001
00005 //
00006 // C++-ified by Curtis Olson, started March 2001.
00007 //
00008 // Copyright (C) 2001  Curtis L. Olson - http://www.flightgear.org/~curt
00009 //
00010 // This program is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public License as
00012 // published by the Free Software Foundation; either version 2 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This program is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with this program; if not, write to the Free Software
00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 //
00024 // $Id: soundmgr__openal_8hxx-source.html,v 1.7 2007-12-17 15:37:11 curt Exp $
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     // Position of the listener.
00074     ALfloat listener_pos[3];
00075 
00076     // Velocity of the listener.
00077     ALfloat listener_vel[3];
00078 
00079     // Orientation of the listener. (first 3 elements are "at", second
00080     // 3 are "up")
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 

Generated on Mon Dec 17 09:30:55 2007 for SimGear by  doxygen 1.5.1