00001
00002
00003
00004
00005
00006
00007
00008 #ifndef SOUNDMANAGER_H_
00009 #define SOUNDMANAGER_H_
00010
00011
00012 #include <iostream>
00013 #include <cstring>
00014 #include <vector>
00015
00016 #include <OgreVector3.h>
00017 #include <OgreQuaternion.h>
00018 #include <OgreFrameListener.h>
00019
00020 #include <enums.h>
00021 #include <GraphicsInteractionManager.h>
00022
00023 #include <wave.h>
00024 #include <AL/al.h>
00025 #include <AL/alc.h>
00026
00027
00028 namespace OgreSND {
00029 const int soundPerEnt = 3;
00030 const int maxAudioBuffers = 63;
00031 const int maxAudioSources = 15;
00032 const std::string backgroundMusicFilename = "data/watercraft/sounds/backgroundMusic.wav";
00034
00035
00036 typedef struct {
00037 ALuint source;
00038 bool inUse;
00039 } SourceInfo;
00040
00041 typedef struct {
00042 ALuint buffer;
00043 std::string bufferFilename;
00044 WaveInfo *wave;
00045 } BufferInfo;
00046
00047 class SoundMgr : public Ogre::FrameListener{
00048 private:
00049 OgreGFX::GraphicsInteractionManager *gim;
00050 ALCdevice *device;
00051 ALCcontext *context;
00052 ALfloat position[3];
00053 ALfloat velocity[3];
00054 ALfloat orientation[6];
00055
00056
00057
00058 SourceInfo sourceInfo[maxAudioSources];
00059 BufferInfo bufferInfo[maxAudioBuffers];
00060
00061
00062 ALuint backgroundMusicBuffer, backgroundMusicSource;
00063 ALuint battleSoundSource;
00064 WaveInfo *backgroundWaveInfo;
00065
00066 unsigned int soundDictionary[FastEcslent::NENTITYTYPES];
00067 std::vector <std::string> sourceDictionary;
00068
00069
00070 int creationSoundsDictionary[FastEcslent::NENTITYTYPES][soundPerEnt];
00071 int selectionSoundsDictionary[FastEcslent::NENTITYTYPES][soundPerEnt];
00072 int battleSoundsDictionary[FastEcslent::NENTITYTYPES][soundPerEnt];
00073
00074
00075 std::string getFQFNFromFilename(std::string filename);
00076 int getBufferId(std::string filename);
00077
00078 int getEmptySourceIndex();
00079 bool resetSource(ALuint sid);
00080
00081 bool isEnabled;
00082
00083 public:
00084 SoundMgr(OgreGFX::GraphicsInteractionManager *gim);
00085 ~SoundMgr();
00086
00087 void initialize();
00088 void crosslink();
00089 void loadLevel();
00090 void tick(double dtime);
00091 void releaseLevel();
00092 void cleanup ();
00093
00094 void enable();
00095 void disable();
00096
00097 virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
00098 virtual bool frameStarted(const Ogre::FrameEvent& evt);
00099 virtual bool frameEnded(const Ogre::FrameEvent& evt);
00100
00101
00102 void printAudioDevices(const ALCchar *devices);
00103 int printError(const char *ermsg);
00104 inline ALenum toALFormat(short channels, short samples);
00105 void syncListenerToCamera();
00106 void attachSelectedNodeToSoundIndex(OgreGFX::GFXNode *gfxNode, unsigned int index);
00107 bool playEntityBornSound(FastEcslent::EntityType et, OgreGFX::GFXNode *gfxNode);
00108 bool playExplosionSound(FastEcslent::EntityType et, OgreGFX::GFXNode *gfxNode);
00109 bool playExplosionSound(OgreGFX::GFXNode *gfxNode);
00110 bool playSelectionSound(FastEcslent::EntityType et, OgreGFX::GFXNode *gfxNode);
00111
00112
00113 bool loadAudio(std::string filename, int sid);
00114
00115 bool loadStartBackground();
00116 bool stopBackground();
00117 bool pauseBackground();
00118 bool resumeBackground();
00119
00120 bool registerCreate(FastEcslent::EntityType et, std::string filename);
00121 bool registerSelection(FastEcslent::EntityType et, std::string filename);
00122 bool registerBattleSound(FastEcslent::EntityType et, std::string filename);
00123 bool isEntityShip(FastEcslent::EntityType et);
00124 bool initWatercraftSounds();
00125
00126 bool reserveAudio(std::string filename, bool loop, unsigned int &alSourceInfoIndex);
00127 bool releaseSource(ALuint audioId);
00128 bool releaseSourceIndex(int sid);
00129
00130
00131
00132 bool playAudio(ALuint audioId, bool forceRestart );
00133 bool playAudio(ALuint audioId);
00134 bool playAudioSourceIndex(int sid, bool forceRestart );
00135 bool playAudioSourceIndex(int sid);
00136
00137 void copySoundState();
00138
00139 bool isAudioPlaying(ALuint audioId);
00140 bool stopAudio(ALuint audioID );
00141 bool stopAllAudio( void );
00142 bool stopAudioSourceIndex(int sid);
00143
00144 bool pauseAudio(ALuint audioID );
00145 bool pauseAllAudio( void );
00146 bool pauseAudioSourceIndex(int sid );
00147
00148 bool resumeAudio(ALuint audioID );
00149 bool resumeAllAudio( void );
00150 bool resumeAudioSourceIndex(int sid);
00151
00152 bool setSoundPosition(ALuint audioID, Ogre::Vector3 position );
00153
00154 bool setSoundDisposition(ALuint audioID, Ogre::Vector3 position, Ogre::Vector3 velocity, Ogre::Vector3 direction );
00155
00156 bool setSound(ALuint audioID, Ogre::Vector3 position,
00157 Ogre::Vector3 velocity, Ogre::Vector3 direction, float maxDistance,
00158 bool playNow, bool forceRestart, float minGain );
00159
00160 bool setListenerDisposition( Ogre::Vector3 position, Ogre::Vector3 velocity, Ogre::Quaternion orientation );
00161
00162 };
00163
00164
00165
00166
00167
00168 }
00169
00170
00171 #endif