[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 |
---|
[3060] | 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | */ |
---|
[6117] | 28 | |
---|
[3196] | 29 | #ifndef _SoundManager_H__ |
---|
| 30 | #define _SoundManager_H__ |
---|
[3060] | 31 | |
---|
| 32 | #include "OrxonoxPrereqs.h" |
---|
| 33 | |
---|
[3196] | 34 | #include <list> |
---|
[6117] | 35 | #include <string> |
---|
[6186] | 36 | #include <map> |
---|
[3370] | 37 | #include "util/Singleton.h" |
---|
[6184] | 38 | #include "core/OrxonoxClass.h" |
---|
[3196] | 39 | |
---|
[6184] | 40 | // tolua_begin |
---|
[3060] | 41 | namespace orxonox |
---|
| 42 | { |
---|
[6186] | 43 | |
---|
| 44 | //! Enum for the sound type. |
---|
| 45 | namespace SoundType |
---|
| 46 | { |
---|
| 47 | enum Value |
---|
| 48 | { |
---|
| 49 | none, |
---|
| 50 | ambient, |
---|
| 51 | effects |
---|
| 52 | }; |
---|
| 53 | } |
---|
| 54 | |
---|
[3060] | 55 | /** |
---|
| 56 | * The SoundManager class manages the OpenAL device, context and listener |
---|
[5929] | 57 | * position. It is a singleton. |
---|
[3060] | 58 | * |
---|
| 59 | */ |
---|
[6184] | 60 | class _OrxonoxExport SoundManager |
---|
| 61 | // tolua_end |
---|
| 62 | : public Singleton<SoundManager>, public OrxonoxClass |
---|
| 63 | { // tolua_export |
---|
[3370] | 64 | friend class Singleton<SoundManager>; |
---|
[6117] | 65 | |
---|
[3060] | 66 | public: |
---|
| 67 | SoundManager(); |
---|
| 68 | ~SoundManager(); |
---|
| 69 | |
---|
[6183] | 70 | void preUpdate(const Clock& time); |
---|
[6117] | 71 | void setConfigValues(); |
---|
[6184] | 72 | |
---|
| 73 | static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } // tolua_export |
---|
[6117] | 74 | |
---|
[5929] | 75 | void setListenerPosition(const Vector3& position); |
---|
| 76 | void setListenerOrientation(const Quaternion& orientation); |
---|
| 77 | |
---|
[6117] | 78 | void registerAmbientSound(AmbientSound* newAmbient); |
---|
| 79 | void unregisterAmbientSound(AmbientSound* oldAmbient); |
---|
| 80 | void pauseAmbientSound(AmbientSound* ambient); |
---|
[6184] | 81 | |
---|
[6194] | 82 | void setVolume(float vol, SoundType::Value type); |
---|
[6186] | 83 | float getVolume(SoundType::Value type); // tolua_export |
---|
[6184] | 84 | |
---|
[6186] | 85 | void toggleMute(SoundType::Value type); // tolua_export |
---|
| 86 | bool getMute(SoundType::Value type); // tolua_export |
---|
[6117] | 87 | |
---|
[3060] | 88 | private: |
---|
[6117] | 89 | void processCrossFading(float dt); |
---|
| 90 | void fadeIn(AmbientSound* sound); |
---|
| 91 | void fadeOut(AmbientSound* sound); |
---|
| 92 | |
---|
| 93 | void checkFadeStepValidity(); |
---|
[6186] | 94 | bool checkVolumeValidity(SoundType::Value type); |
---|
| 95 | void checkSoundVolumeValidity(void); |
---|
| 96 | void checkAmbientVolumeValidity(void); |
---|
| 97 | void checkEffectsVolumeValidity(void); |
---|
[6184] | 98 | |
---|
[6186] | 99 | float checkVolumeRange(float vol); |
---|
| 100 | |
---|
| 101 | void updateVolume(SoundType::Value type); |
---|
| 102 | |
---|
| 103 | void setVolumeInternal(float vol, SoundType::Value type); |
---|
| 104 | float getVolumeInternal(SoundType::Value type); |
---|
[6117] | 105 | |
---|
[3280] | 106 | ALCdevice* device_; |
---|
[3060] | 107 | ALCcontext* context_; |
---|
[6117] | 108 | |
---|
| 109 | typedef std::list<std::pair<AmbientSound*, bool> > AmbientList; |
---|
| 110 | AmbientList ambientSounds_; |
---|
| 111 | |
---|
| 112 | float crossFadeStep_; //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading |
---|
| 113 | std::list<AmbientSound*> fadeInList_; |
---|
| 114 | std::list<AmbientSound*> fadeOutList_; |
---|
| 115 | |
---|
[6186] | 116 | float soundVolume_; |
---|
[6184] | 117 | float ambientVolume_; |
---|
| 118 | float effectsVolume_; |
---|
[6186] | 119 | std::map<SoundType::Value, bool> mute_; |
---|
[6184] | 120 | |
---|
[3370] | 121 | static SoundManager* singletonPtr_s; |
---|
[6184] | 122 | }; // tolua_export |
---|
| 123 | } // tolua_export |
---|
[3060] | 124 | |
---|
[3196] | 125 | #endif /* _SoundManager_H__ */ |
---|