[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 |
---|
[6767] | 24 | * |
---|
| 25 | * Co-authors: |
---|
[6417] | 26 | * Kevin Young |
---|
| 27 | * Reto Grieder |
---|
[3060] | 28 | */ |
---|
[6417] | 29 | |
---|
[3196] | 30 | #ifndef _SoundManager_H__ |
---|
| 31 | #define _SoundManager_H__ |
---|
[3060] | 32 | |
---|
[6506] | 33 | #include "sound/SoundPrereqs.h" |
---|
[3060] | 34 | |
---|
[3196] | 35 | #include <list> |
---|
[6417] | 36 | #include <map> |
---|
| 37 | #include <string> |
---|
| 38 | #include <boost/shared_ptr.hpp> |
---|
| 39 | |
---|
[3370] | 40 | #include "util/Singleton.h" |
---|
[6417] | 41 | #include "core/OrxonoxClass.h" |
---|
| 42 | #include "core/SmartPtr.h" |
---|
[3196] | 43 | |
---|
[6417] | 44 | // tolua_begin |
---|
[3060] | 45 | namespace orxonox |
---|
| 46 | { |
---|
[6417] | 47 | //! Enum for the sound type. |
---|
| 48 | namespace SoundType |
---|
[3060] | 49 | { |
---|
[6417] | 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 |
---|
[3370] | 63 | friend class Singleton<SoundManager>; |
---|
[6417] | 64 | |
---|
[3060] | 65 | public: |
---|
| 66 | SoundManager(); |
---|
| 67 | ~SoundManager(); |
---|
| 68 | |
---|
[6417] | 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 | |
---|
[5929] | 79 | void setListenerPosition(const Vector3& position); |
---|
| 80 | void setListenerOrientation(const Quaternion& orientation); |
---|
| 81 | |
---|
[6417] | 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 | |
---|
[3060] | 101 | private: |
---|
[6417] | 102 | void processCrossFading(float dt); |
---|
| 103 | void fadeIn(const SmartPtr<AmbientSound>& sound); |
---|
| 104 | void fadeOut(const SmartPtr<AmbientSound>& sound); |
---|
| 105 | |
---|
| 106 | void checkFadeStepValidity(); |
---|
| 107 | |
---|
| 108 | void checkVolumeValidity(SoundType::Value type); |
---|
| 109 | void checkSoundVolumeValidity() { this->checkVolumeValidity(SoundType::All); } |
---|
| 110 | void checkAmbientVolumeValidity() { this->checkVolumeValidity(SoundType::Music); } |
---|
| 111 | void checkEffectsVolumeValidity() { this->checkVolumeValidity(SoundType::Effects); } |
---|
| 112 | void updateVolume(SoundType::Value type); |
---|
| 113 | |
---|
| 114 | unsigned int createSoundSources(unsigned int n); |
---|
| 115 | |
---|
| 116 | // OpenAL device/context related |
---|
| 117 | std::vector<std::string> deviceNames_; |
---|
[3280] | 118 | ALCdevice* device_; |
---|
[3060] | 119 | ALCcontext* context_; |
---|
| 120 | |
---|
[6417] | 121 | // Ambient sound related |
---|
| 122 | typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; |
---|
| 123 | AmbientList ambientSounds_; |
---|
| 124 | //! Absolute change per second (0.1 means 10% of the nominal volume) for cross fading |
---|
| 125 | float crossFadeStep_; |
---|
| 126 | std::list<SmartPtr<AmbientSound> > fadeInList_; |
---|
| 127 | std::list<SmartPtr<AmbientSound> > fadeOutList_; |
---|
| 128 | |
---|
| 129 | // Volume related |
---|
| 130 | float volume_[3]; |
---|
| 131 | float mute_[3]; |
---|
| 132 | |
---|
| 133 | // Sound buffer related |
---|
| 134 | static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024; |
---|
| 135 | unsigned int effectsPoolSize_; |
---|
| 136 | typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList; |
---|
| 137 | EffectsPoolList effectsPool_; |
---|
| 138 | typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap; |
---|
| 139 | SoundBufferMap soundBuffers_; |
---|
| 140 | |
---|
| 141 | // Sound source related |
---|
| 142 | unsigned int minSources_; |
---|
| 143 | unsigned int maxSources_; |
---|
| 144 | std::vector<ALuint> availableSoundSources_; |
---|
| 145 | std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_; |
---|
| 146 | |
---|
[3370] | 147 | static SoundManager* singletonPtr_s; |
---|
[6417] | 148 | }; // tolua_export |
---|
| 149 | } // tolua_export |
---|
[3060] | 150 | |
---|
[3196] | 151 | #endif /* _SoundManager_H__ */ |
---|