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