00001 00005 /* Copyright © 2010 James Legg. 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 */ 00011 00012 #ifndef ENGINE_AUDIO_H 00013 #define ENGINE_AUDIO_H 00014 00015 #include <AL/alut.h> 00016 #include <LinearMath/btVector3.h> 00017 #include <LinearMath/btTransform.h> 00018 #include <boost/shared_ptr.hpp> 00019 #include <vector> 00020 00021 namespace Engine 00022 { 00023 00024 class SoundSource; 00025 class SoundListener; 00026 class SoundInstance; 00027 class ALSoundSource; 00028 00031 class Audio 00032 { 00033 private: 00034 Audio(); 00035 public: 00036 ~Audio(); 00037 static Audio & get_instance(); 00039 void pause(); 00041 void resume(); 00046 bool get_paused(); 00052 void commit(); 00056 void attach_listner(SoundListener * listener); 00060 void attach_source(SoundSource * source); 00064 void forget_listener(SoundListener * listener); 00067 void forget_source(SoundSource * source); 00068 private: 00074 std::vector<boost::shared_ptr<SoundInstance> > m_instances; 00078 std::vector<SoundListener *> m_listeners; 00082 std::vector<SoundSource *> m_sources; 00089 std::vector<boost::shared_ptr<ALSoundSource> > m_al_sources; 00090 00095 ALfloat m_speed_of_sound; 00096 00098 bool m_paused; 00099 }; 00100 00105 class SoundBuffer 00106 { 00107 public: 00109 SoundBuffer(const char * filename); 00110 ~SoundBuffer(); 00111 // get the openAL buffer name. 00112 ALuint get_al_buffer() const; 00113 private: 00114 ALuint m_buffer; 00115 // no copying or assignment 00116 SoundBuffer(const SoundBuffer & source); 00117 SoundBuffer & operator=(const SoundBuffer & source); 00118 }; 00119 00124 class SoundListener 00125 { 00126 friend class Audio; 00127 public: 00128 SoundListener(); 00129 ~SoundListener(); 00136 void set_position(btVector3 position, btVector3 forward, btVector3 up); 00142 void set_velocity(btVector3 velocity); 00143 private: 00144 btVector3 m_position; 00145 btVector3 m_forward; 00146 btVector3 m_up; 00147 btVector3 m_velocity; 00148 btTransform m_inverse_transform; 00149 // no copying or assignment 00150 SoundListener(const SoundListener & source); 00151 SoundListener & operator=(const SoundListener & source); 00152 }; 00153 00162 class SoundSource 00163 { 00164 friend class Audio; 00165 public: 00170 SoundSource(const SoundBuffer & buffer); 00171 ~SoundSource(); 00175 void set_looping(bool loop = true); 00176 00178 void set_position(btVector3 position); 00180 void set_velocity(btVector3 velocity); 00184 void set_gain(ALfloat gain); 00185 00186 void set_pitch(ALfloat pitch); 00187 00189 void play(); 00190 00192 void stop(); 00193 00194 const SoundBuffer & get_buffer() const; 00195 private: 00196 const SoundBuffer & m_buffer; 00197 00198 bool m_looping; 00199 ALfloat m_gain; 00200 ALfloat m_pitch; 00201 btVector3 m_position; 00202 btVector3 m_velocity; 00203 bool m_playing; 00207 bool m_started; 00208 // no copying or assignment 00209 SoundSource(const SoundSource & source); 00210 SoundSource & operator=(const SoundSource & source); 00211 }; 00212 00218 class SoundInstance 00219 { 00220 public: 00223 SoundInstance(ALuint buffer); 00225 ALuint get_buffer(); 00227 bool get_assigned(); 00229 unsigned int get_index(); 00235 void assign(ALSoundSource & source, unsigned int index); 00237 void unassign(); 00242 void set_gain(ALfloat gain); 00244 ALfloat get_gain(); 00246 void set_pitch(ALfloat pitch); 00248 void set_position(btVector3 position); 00257 void set_looping(bool looping = true); 00259 bool get_looping(); 00260 00262 void play(); 00264 void stop(); 00266 bool get_playing(); 00267 00269 void update_al(); 00270 private: 00271 ALSoundSource * m_source; 00272 unsigned int m_source_index; 00273 ALuint m_buffer; 00274 ALfloat m_gain; 00275 ALfloat m_pitch; 00276 btVector3 m_position; 00277 bool m_looping; 00278 bool m_playing; 00279 bool m_assigning; 00280 }; 00281 00284 class ALSoundSource 00285 { 00286 public: 00287 ALSoundSource(); 00288 ~ALSoundSource(); 00289 ALuint get_name(); 00291 SoundInstance * get_instance(); 00293 void assign(SoundInstance & si); 00296 void unassign(); 00297 private: 00298 ALuint m_name; 00299 SoundInstance * m_instance; 00300 // no copying or assignment 00301 ALSoundSource (const ALSoundSource & source); 00302 ALSoundSource & operator=(const ALSoundSource & source); 00303 }; 00304 00305 class AudioError 00306 { 00307 }; 00308 00309 }// namespace Engine 00310 00311 #endif // ndef ENGINE_AUDIO_H 00312
Generated at Mon Sep 6 00:41:12 2010 by Doxygen version 1.4.7 for Racer version svn335.