[3060] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Erwin 'vaiursch' Herrsche |
---|
[6117] | 24 | * Kevin Young |
---|
[6244] | 25 | * Reto Grieder |
---|
[3060] | 26 | * Co-authors: |
---|
| 27 | * ... |
---|
| 28 | */ |
---|
[6117] | 29 | |
---|
[3196] | 30 | #ifndef _SoundManager_H__ |
---|
| 31 | #define _SoundManager_H__ |
---|
[3060] | 32 | |
---|
| 33 | #include "OrxonoxPrereqs.h" |
---|
| 34 | |
---|
[3196] | 35 | #include <list> |
---|
[6203] | 36 | #include <map> |
---|
[6117] | 37 | #include <string> |
---|
[6254] | 38 | #include <boost/shared_ptr.hpp> |
---|
[6203] | 39 | |
---|
[3370] | 40 | #include "util/Singleton.h" |
---|
[6184] | 41 | #include "core/OrxonoxClass.h" |
---|
[3196] | 42 | |
---|
[6244] | 43 | // forward declaration |
---|
| 44 | typedef int ALenum; |
---|
| 45 | |
---|
[6184] | 46 | // tolua_begin |
---|
[3060] | 47 | namespace orxonox |
---|
| 48 | { |
---|
[6203] | 49 | // forward declaration |
---|
| 50 | class SoundBuffer; |
---|
[6186] | 51 | |
---|
| 52 | //! Enum for the sound type. |
---|
| 53 | namespace SoundType |
---|
| 54 | { |
---|
| 55 | enum Value |
---|
| 56 | { |
---|
| 57 | none, |
---|
| 58 | ambient, |
---|
| 59 | effects |
---|
| 60 | }; |
---|
| 61 | } |
---|
| 62 | |
---|
[3060] | 63 | /** |
---|
| 64 | * The SoundManager class manages the OpenAL device, context and listener |
---|
[5929] | 65 | * position. It is a singleton. |
---|
[3060] | 66 | * |
---|
| 67 | */ |
---|
[6184] | 68 | class _OrxonoxExport SoundManager |
---|
| 69 | // tolua_end |
---|
| 70 | : public Singleton<SoundManager>, public OrxonoxClass |
---|
| 71 | { // tolua_export |
---|
[3370] | 72 | friend class Singleton<SoundManager>; |
---|
[6117] | 73 | |
---|
[3060] | 74 | public: |
---|
| 75 | SoundManager(); |
---|
| 76 | ~SoundManager(); |
---|
| 77 | |
---|
[6183] | 78 | void preUpdate(const Clock& time); |
---|
[6117] | 79 | void setConfigValues(); |
---|
[6184] | 80 | |
---|
[6244] | 81 | // tolua_begin |
---|
| 82 | static SoundManager& getInstance() |
---|
| 83 | { return Singleton<SoundManager>::getInstance(); } |
---|
[6117] | 84 | |
---|
[6244] | 85 | std::string getDeviceName(unsigned int index) const |
---|
| 86 | { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); } |
---|
| 87 | // tolua_end |
---|
| 88 | |
---|
[5929] | 89 | void setListenerPosition(const Vector3& position); |
---|
| 90 | void setListenerOrientation(const Quaternion& orientation); |
---|
| 91 | |
---|
[6117] | 92 | void registerAmbientSound(AmbientSound* newAmbient); |
---|
| 93 | void unregisterAmbientSound(AmbientSound* oldAmbient); |
---|
| 94 | void pauseAmbientSound(AmbientSound* ambient); |
---|
[6184] | 95 | |
---|
[6194] | 96 | void setVolume(float vol, SoundType::Value type); |
---|
[6186] | 97 | float getVolume(SoundType::Value type); // tolua_export |
---|
[6184] | 98 | |
---|
[6186] | 99 | void toggleMute(SoundType::Value type); // tolua_export |
---|
| 100 | bool getMute(SoundType::Value type); // tolua_export |
---|
[6117] | 101 | |
---|
[6203] | 102 | shared_ptr<SoundBuffer> getSoundBuffer(shared_ptr<ResourceInfo> fileInfo); |
---|
[6254] | 103 | void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer); |
---|
[6203] | 104 | |
---|
[6244] | 105 | static std::string getALErrorString(ALenum error); |
---|
| 106 | |
---|
[3060] | 107 | private: |
---|
[6117] | 108 | void processCrossFading(float dt); |
---|
| 109 | void fadeIn(AmbientSound* sound); |
---|
| 110 | void fadeOut(AmbientSound* sound); |
---|
| 111 | |
---|
| 112 | void checkFadeStepValidity(); |
---|
[6186] | 113 | bool checkVolumeValidity(SoundType::Value type); |
---|
| 114 | void checkSoundVolumeValidity(void); |
---|
| 115 | void checkAmbientVolumeValidity(void); |
---|
| 116 | void checkEffectsVolumeValidity(void); |
---|
[6184] | 117 | |
---|
[6186] | 118 | float checkVolumeRange(float vol); |
---|
| 119 | |
---|
| 120 | void updateVolume(SoundType::Value type); |
---|
| 121 | |
---|
| 122 | void setVolumeInternal(float vol, SoundType::Value type); |
---|
| 123 | float getVolumeInternal(SoundType::Value type); |
---|
[6117] | 124 | |
---|
[6244] | 125 | std::vector<std::string> deviceNames_; |
---|
[3280] | 126 | ALCdevice* device_; |
---|
[3060] | 127 | ALCcontext* context_; |
---|
[6117] | 128 | |
---|
| 129 | typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; |
---|
| 130 | AmbientList ambientSounds_; |
---|
| 131 | |
---|
| 132 | float crossFadeStep_; //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading |
---|
| 133 | std::list<AmbientSound*> fadeInList_; |
---|
| 134 | std::list<AmbientSound*> fadeOutList_; |
---|
| 135 | |
---|
[6186] | 136 | float soundVolume_; |
---|
[6184] | 137 | float ambientVolume_; |
---|
| 138 | float effectsVolume_; |
---|
[6186] | 139 | std::map<SoundType::Value, bool> mute_; |
---|
[6203] | 140 | |
---|
[6254] | 141 | static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024; |
---|
| 142 | unsigned int effectsPoolSize_; |
---|
| 143 | typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList; |
---|
| 144 | EffectsPoolList effectsPool_; |
---|
| 145 | typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap; |
---|
| 146 | SoundBufferMap soundBuffers_; |
---|
[6184] | 147 | |
---|
[3370] | 148 | static SoundManager* singletonPtr_s; |
---|
[6184] | 149 | }; // tolua_export |
---|
| 150 | } // tolua_export |
---|
[3060] | 151 | |
---|
[3196] | 152 | #endif /* _SoundManager_H__ */ |
---|