Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

AudioManager.h

Go to the documentation of this file.
00001 /*
00002  * AudioManager.h
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00036 #ifndef AUDIOMANAGER_H_
00037 #define AUDIOMANAGER_H_
00038 
00039 #include "FlyLegacy.h"
00040 #include <string>
00041 #include <map>
00042 
00043 #ifdef HAVE_OPENAL
00044 #include <al/al.h>
00045 #include <al/alc.h>
00046 #include <al/alut.h>
00047 #endif // HAVE_OPENAL
00048 
00049 
00052 class CSoundEffect {
00053 public:
00054   // Constructor
00055   CSoundEffect (void);
00056 
00057   // Destructor
00058   ~CSoundEffect (void);
00059 
00060 public:
00061   bool        bound;              // Whether the sound effect is bound to a source
00062 #ifdef HAVE_OPENAL
00063   ALuint      source;             // OpenAL Source object
00064   ALuint      buffer;             // OpenAL Buffer object
00065 #endif // HAVE_OPENAL
00066   char        wavfile[256];       // Filename of WAV file
00067   int         name;               // Unique identifier for this sound effect
00068   int         user1, user2;       // User data tags
00069 }; 
00070 
00075 class CAudioManager {
00076 public:
00077   // Constructor
00078   CAudioManager (void);
00079   ~CAudioManager (void);
00080 
00081   // CAudioManager methods
00082   void Init (void);
00083   void SetListenerPosition (SPosition *p);
00084 
00085   int  CreateSource (void);
00086   void SetSourcePosition (int name, SPosition *p);
00087   void SetSourcePosition (int name, SVector *v);
00088   void SetSourceDirection (int name, SVector *v);
00089   void SetSourceVelocity (int name, SVector *v);
00090   void SetSourceFrequency (int name, float freqScalar);
00091   void AssignSfx (int source, int buffer);
00092 
00093   int  CreateSfx (PFS *pfs, const char* wavfile);
00094   int  IsValidSfx (int name);
00095   int  PlaySfx (int source, PFS *pfs, const char* wavfile);
00096   int  PlaySfx (int source, int name);
00097   int  PlaySfxDelay (int source, PFS *pfs, const char* wavfile, float delay, float *length);
00098   int  PlaySfxDelay (int source, int name, float delay, float *length);
00099   void StopSfx (int name);
00100   void StopSfxByUserData (int user1, int user2);
00101   void SetSfxVolume (int name, float volume);
00102   void SetSfxPosition (int name, SPosition *p);
00103   void SetSfxPosition (int name, SVector *v);
00104   void SetSfxDirection (int name, SVector *v);
00105   void SetSfxVelocity (int name, SVector *v);
00106   void SetSfxFrequency (int name, float freqScalar);
00107   void SetSfxUserData (int name, int user1, int user2);
00108 
00109 private:
00110   CSoundEffect *GetSoundEffect (int name);
00111   CSoundEffect *GetFirstSoundEffectByUserData (int user1, int user2);
00112   CSoundEffect *GetNextSoundEffectByUserData (int user1, int user2);
00113 
00114   // Data members
00115 //private:
00116 public:
00117 #ifdef HAVE_OPENAL
00118   // OpenAL
00119   ALCcontext    *context;
00120   ALCdevice     *device;
00121 #endif // HAVE_OPENAL
00122 
00123   // Sound effect cache, indexed by WAV filenames
00124   std::map<std::string,CSoundEffect*> cache;
00125 
00126   // Position/fading/doppler parameters
00127   SPosition     listenerPos;
00128 
00129 private:
00130   // Iterator used to lookup cached sound effects by user data
00131   std::map<std::string,CSoundEffect*>::iterator iterUserData;
00132 };
00133 
00134 #endif // AUDIOMANAGER_H_
00135 
SourceForge.net Logo Documentation generated by doxygen