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