Changeset 6412 for code/branches/pickup2/src/orxonox/sound/SoundManager.h
- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/orxonox/sound/SoundManager.h
r5929 r6412 22 22 * Author: 23 23 * Erwin 'vaiursch' Herrsche 24 * Kevin Young 25 * Reto Grieder 24 26 * Co-authors: 25 27 * ... 26 28 */ 29 27 30 #ifndef _SoundManager_H__ 28 31 #define _SoundManager_H__ … … 30 33 #include "OrxonoxPrereqs.h" 31 34 32 #include <cassert>33 35 #include <list> 36 #include <map> 37 #include <string> 38 #include <boost/shared_ptr.hpp> 39 34 40 #include "util/Singleton.h" 35 #include "tools/interfaces/Tickable.h" 41 #include "core/OrxonoxClass.h" 42 #include "core/SmartPtr.h" 36 43 44 // tolua_begin 37 45 namespace orxonox 38 46 { 39 /** 40 * The SoundManager class manages the OpenAL device, context and listener 41 * position. It is a singleton. 42 * 43 */ 44 class _OrxonoxExport SoundManager : public Singleton<SoundManager> 47 //! Enum for the sound type. 48 namespace SoundType 45 49 { 50 enum Value 51 { 52 All = 0, 53 Music = 1, 54 Effects = 2 55 }; 56 } 57 58 //! The SoundManager class manages the OpenAL device, context and listener position. 59 class _OrxonoxExport SoundManager 60 // tolua_end 61 : public Singleton<SoundManager>, public OrxonoxClass 62 { // tolua_export 46 63 friend class Singleton<SoundManager>; 64 47 65 public: 48 66 SoundManager(); 49 67 ~SoundManager(); 50 68 69 void preUpdate(const Clock& time); 70 void setConfigValues(); 71 72 // tolua_begin 73 static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } 74 75 std::string getDeviceName(unsigned int index) const 76 { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); } 77 // tolua_end 78 51 79 void setListenerPosition(const Vector3& position); 52 80 void setListenerOrientation(const Quaternion& orientation); 53 81 82 void registerAmbientSound(AmbientSound* newAmbient); 83 void unregisterAmbientSound(AmbientSound* oldAmbient); 84 void pauseAmbientSound(AmbientSound* ambient); 85 86 // tolua_begin 87 void setVolume(float vol, SoundType::Value type); 88 float getVolume(SoundType::Value type); 89 float getRealVolume(SoundType::Value type); 90 91 void toggleMute(SoundType::Value type); 92 bool getMute(SoundType::Value type); 93 // tolua_end 94 95 shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename); 96 void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer); 97 98 ALuint getSoundSource(BaseSound* object); 99 void releaseSoundSource(ALuint source); 100 101 static std::string getALErrorString(ALenum error); 102 54 103 private: 104 void processCrossFading(float dt); 105 void fadeIn(const SmartPtr<AmbientSound>& sound); 106 void fadeOut(const SmartPtr<AmbientSound>& sound); 107 108 void checkFadeStepValidity(); 109 110 void checkVolumeValidity(SoundType::Value type); 111 void checkSoundVolumeValidity() { this->checkVolumeValidity(SoundType::All); } 112 void checkAmbientVolumeValidity() { this->checkVolumeValidity(SoundType::Music); } 113 void checkEffectsVolumeValidity() { this->checkVolumeValidity(SoundType::Effects); } 114 void updateVolume(SoundType::Value type); 115 116 unsigned int createSoundSources(unsigned int n); 117 118 // OpenAL device/context related 119 std::vector<std::string> deviceNames_; 55 120 ALCdevice* device_; 56 121 ALCcontext* context_; 57 122 123 // Ambient sound related 124 typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; 125 AmbientList ambientSounds_; 126 //! Absolute change per second (0.1 means 10% of the nominal volume) for cross fading 127 float crossFadeStep_; 128 std::list<SmartPtr<AmbientSound> > fadeInList_; 129 std::list<SmartPtr<AmbientSound> > fadeOutList_; 130 131 // Volume related 132 float volume_[3]; 133 float mute_[3]; 134 135 // Sound buffer related 136 static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024; 137 unsigned int effectsPoolSize_; 138 typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList; 139 EffectsPoolList effectsPool_; 140 typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap; 141 SoundBufferMap soundBuffers_; 142 143 // Sound source related 144 unsigned int minSources_; 145 unsigned int maxSources_; 146 std::vector<ALuint> availableSoundSources_; 147 std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_; 148 58 149 static SoundManager* singletonPtr_s; 59 }; 60 } 150 }; // tolua_export 151 } // tolua_export 61 152 62 153 #endif /* _SoundManager_H__ */
Note: See TracChangeset
for help on using the changeset viewer.