[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" |
---|
[6349] | 42 | #include "core/SmartPtr.h" |
---|
[3196] | 43 | |
---|
[6184] | 44 | // tolua_begin |
---|
[3060] | 45 | namespace orxonox |
---|
| 46 | { |
---|
[6186] | 47 | //! Enum for the sound type. |
---|
| 48 | namespace SoundType |
---|
| 49 | { |
---|
| 50 | enum Value |
---|
| 51 | { |
---|
[6370] | 52 | All = 0, |
---|
| 53 | Music = 1, |
---|
| 54 | Effects = 2 |
---|
[6186] | 55 | }; |
---|
| 56 | } |
---|
[6370] | 57 | |
---|
| 58 | //! The SoundManager class manages the OpenAL device, context and listener position. |
---|
[6184] | 59 | class _OrxonoxExport SoundManager |
---|
| 60 | // tolua_end |
---|
| 61 | : public Singleton<SoundManager>, public OrxonoxClass |
---|
| 62 | { // tolua_export |
---|
[3370] | 63 | friend class Singleton<SoundManager>; |
---|
[6117] | 64 | |
---|
[3060] | 65 | public: |
---|
| 66 | SoundManager(); |
---|
| 67 | ~SoundManager(); |
---|
| 68 | |
---|
[6183] | 69 | void preUpdate(const Clock& time); |
---|
[6117] | 70 | void setConfigValues(); |
---|
[6387] | 71 | |
---|
[6244] | 72 | // tolua_begin |
---|
[6278] | 73 | static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } |
---|
[6117] | 74 | |
---|
[6244] | 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 | |
---|
[6117] | 82 | void registerAmbientSound(AmbientSound* newAmbient); |
---|
| 83 | void unregisterAmbientSound(AmbientSound* oldAmbient); |
---|
| 84 | void pauseAmbientSound(AmbientSound* ambient); |
---|
[6332] | 85 | |
---|
[6370] | 86 | // tolua_begin |
---|
[6194] | 87 | void setVolume(float vol, SoundType::Value type); |
---|
[6370] | 88 | float getVolume(SoundType::Value type); |
---|
| 89 | float getRealVolume(SoundType::Value type); |
---|
[6332] | 90 | |
---|
[6370] | 91 | void toggleMute(SoundType::Value type); |
---|
| 92 | bool getMute(SoundType::Value type); |
---|
| 93 | // tolua_end |
---|
[6117] | 94 | |
---|
[6270] | 95 | shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename); |
---|
[6254] | 96 | void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer); |
---|
[6203] | 97 | |
---|
[6383] | 98 | ALuint getSoundSource(BaseSound* object); |
---|
[6322] | 99 | void releaseSoundSource(ALuint source); |
---|
| 100 | |
---|
[6244] | 101 | static std::string getALErrorString(ALenum error); |
---|
| 102 | |
---|
[3060] | 103 | private: |
---|
[6117] | 104 | void processCrossFading(float dt); |
---|
[6349] | 105 | void fadeIn(const SmartPtr<AmbientSound>& sound); |
---|
| 106 | void fadeOut(const SmartPtr<AmbientSound>& sound); |
---|
[6117] | 107 | |
---|
| 108 | void checkFadeStepValidity(); |
---|
[6332] | 109 | |
---|
[6370] | 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); } |
---|
[6186] | 114 | void updateVolume(SoundType::Value type); |
---|
[6332] | 115 | |
---|
[6409] | 116 | unsigned int createSoundSources(unsigned int n); |
---|
| 117 | |
---|
[6370] | 118 | // OpenAL device/context related |
---|
[6244] | 119 | std::vector<std::string> deviceNames_; |
---|
[3280] | 120 | ALCdevice* device_; |
---|
[3060] | 121 | ALCcontext* context_; |
---|
[6332] | 122 | |
---|
[6370] | 123 | // Ambient sound related |
---|
[6117] | 124 | typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; |
---|
[6370] | 125 | AmbientList ambientSounds_; |
---|
| 126 | //! Absolute change per second (0.1 means 10% of the nominal volume) for cross fading |
---|
| 127 | float crossFadeStep_; |
---|
[6349] | 128 | std::list<SmartPtr<AmbientSound> > fadeInList_; |
---|
| 129 | std::list<SmartPtr<AmbientSound> > fadeOutList_; |
---|
[6332] | 130 | |
---|
[6370] | 131 | // Volume related |
---|
| 132 | float volume_[3]; |
---|
| 133 | float mute_[3]; |
---|
[6203] | 134 | |
---|
[6370] | 135 | // Sound buffer related |
---|
[6254] | 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_; |
---|
[6322] | 142 | |
---|
[6370] | 143 | // Sound source related |
---|
[6409] | 144 | unsigned int minSources_; |
---|
[6322] | 145 | unsigned int maxSources_; |
---|
[6383] | 146 | std::vector<ALuint> availableSoundSources_; |
---|
| 147 | std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_; |
---|
[6332] | 148 | |
---|
[3370] | 149 | static SoundManager* singletonPtr_s; |
---|
[6184] | 150 | }; // tolua_export |
---|
| 151 | } // tolua_export |
---|
[3060] | 152 | |
---|
[3196] | 153 | #endif /* _SoundManager_H__ */ |
---|