audio.h

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software
00006 // and you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00032 #ifndef __AUDIO_HEADER__
00033 #define __AUDIO_HEADER__
00034 
00035 #ifdef __APPLE__
00036   #include <SDL_mixer/SDL_mixer.h>
00037 #else
00038   #include <SDL/SDL_mixer.h>
00039 #endif
00040 
00041 #include "utils.h"
00042 #include "defs.h"
00043 #include "audio_sound.h"
00044 #include "audio_music.h"
00045 
00046 namespace hoa_audio {
00047 
00049 extern GameAudio* AudioManager;
00051 extern bool AUDIO_DEBUG;
00052 
00057 const uint8 AUDIO_STATE_UNLOADED     = 0x01;
00058 const uint8 AUDIO_STATE_STOPPED      = 0x02;
00059 const uint8 AUDIO_STATE_PAUSED       = 0x04;
00060 const uint8 AUDIO_STATE_PLAYING      = 0x08;
00061 const uint8 AUDIO_STATE_FADING_IN    = 0x10;
00062 const uint8 AUDIO_STATE_FADING_OUT   = 0x20;
00064 
00069 
00070 const int32 AUDIO_LOOP_FOREVER = -1;
00072 const int32 AUDIO_LOOP_ONCE = 0;
00074 const uint32 AUDIO_NO_FADE = 0;
00076 const uint32 AUDIO_STANDARD_FADE = 500;
00078 
00083 const uint32 AUDIO_ERROR_NONE          = 0x00000000;
00084 const uint32 AUDIO_ERROR_NO_DATA       = 0x00000001;
00085 const uint32 AUDIO_ERROR_PLAY_FAILURE  = 0x00000002;
00087 
00088 namespace private_audio {
00089 
00091 const uint32 SOUND_CHANNELS = 16;
00093 const int32 ALL_CHANNELS = -1;
00095 const int32 ANY_CHANNEL = -1;
00097 const int32 BUFFER_SIZE = 1024;
00098 
00099 } // namespace private_audio
00100 
00101 /*!****************************************************************************
00102  * \brief A singleton class for managing and interfacing with audio data.
00103  *
00104  * This class manages all audio data allocation and manipulation. The OpenAL sources
00105  * are wrapped inside this class and OpenAL buffers (which are represented by the
00106  * SoundDescriptor and MusicObject classes) grab these sources as they need them. The
00107  * buffers are stored in map structures so that audio data is not loaded when it already
00108  * exists.
00109  *
00110  * \note 1) Operations that load audio data should be done during parts of the game
00111  * when game modes are being created and destroyed. In other words, ideally you should
00112  * load data into SoundSource and MusicSource objects when a new game mode class object is created,
00113  * instead of creating them only immediately before they are needed.
00114  *
00115  * \note 2) This audio engine uses smart memory management so that loaded audio
00116  * data is not re-loaded if the user requests a load operation on the same
00117  * data. Audio data is only freed once there are no more references to the
00118  * data.
00119  *****************************************************************************/
00120 class GameAudio : public hoa_utils::Singleton<GameAudio>
00121 {
00122   friend class hoa_utils::Singleton<GameAudio>;
00123   friend class private_audio::SoundData;
00124   friend class SoundDescriptor;
00125   friend class private_audio::MusicData;
00126   friend class MusicDescriptor;
00127 
00128 public:
00129   ~GameAudio();
00130 
00131   bool SingletonInitialize ();
00132 
00139   uint32 CheckErrors()
00140     { uint32 return_code; return_code = _audio_errors; _audio_errors = AUDIO_ERROR_NONE; return return_code; }
00141 
00146   void Update();
00147 
00162   float GetMusicVolume()
00163     { return _music_volume; }
00164   float GetSoundVolume()
00165     { return _sound_volume; }
00166   void SetMusicVolume(float vol);
00167   void SetSoundVolume(float vol);
00169 
00176   void PlaySound(std::string filename);
00177 
00188   void PauseAudio();
00189   void ResumeAudio();
00190   void StopAudio();
00191   void RewindAudio();
00193 
00198   void PauseAllSounds();
00199   void ResumeAllSounds();
00200   void StopAllSounds();
00201 //  void RewindAllSounds();
00203 
00212   void PauseAllMusic();
00213   void ResumeAllMusic();
00214   void StopAllMusic();
00215   void RewindAllMusic();
00217 
00219   void DEBUG_PrintInfo();
00220 
00221 private:
00222   GameAudio();
00223 
00225   float _music_volume;
00227   float _sound_volume;
00229   uint32 _audio_errors;
00230 
00239   std::map<std::string, private_audio::MusicData*> _music_data;
00240   std::map<std::string, private_audio::SoundData*> _sound_data;
00242 
00256   private_audio::SoundData* _AcquireSoundData(std::string filename);
00257   private_audio::MusicData* _AcquireMusicData(std::string filename);
00259 
00264   std::list<SoundDescriptor*> _temp_sounds;
00265 
00266 }; // class GameAudio
00267 
00268 } // namespace hoa_audio
00269 
00270 #endif /* #ifndef __AUDIO_HEADER__ */

Generated on Fri Jul 6 23:11:09 2007 for Hero of Allacrost by  doxygen 1.5.1