Orxonox  0.0.5 Codename: Arcturus
SoundManager.h
Go to the documentation of this file.
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 <memory>
39 
40 #include "util/Singleton.h"
42 #include "core/object/StrongPtr.h"
43 #include "core/UpdateListener.h"
44 
45 // tolua_begin
46 namespace orxonox
47 {
49  namespace SoundType
50  {
51  enum Value
52  {
53  All = 0,
54  Music = 1,
55  Effects = 2
56  };
57  }
58 
61  // tolua_end
62  : public Singleton<SoundManager>, public Configurable, public UpdateListener
63  { // tolua_export
64  friend class Singleton<SoundManager>;
65 
66  public:
67  SoundManager();
68  ~SoundManager();
69 
70  virtual void preUpdate(const Clock& time) override;
71  virtual void postUpdate(const Clock& time) override { /*no action*/ }
72  void setConfigValues();
73 
74  // tolua_begin
76  static bool exists() { return Singleton<SoundManager>::exists(); }
77 
78  std::string getDeviceName(unsigned int index) const
79  { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); }
80  // tolua_end
81 
82  void setListenerPosition(const Vector3& position);
83  void setListenerOrientation(const Quaternion& orientation);
84 
85  void registerAmbientSound(AmbientSound* newAmbient);
86  void unregisterAmbientSound(AmbientSound* oldAmbient);
87  void pauseAmbientSound(AmbientSound* ambient);
88 
89  // tolua_begin
90  void setVolume(float vol, SoundType::Value type);
91  float getVolume(SoundType::Value type);
92  float getRealVolume(SoundType::Value type);
93 
94  void toggleMute(SoundType::Value type);
95  bool getMute(SoundType::Value type);
96  // tolua_end
97 
98  std::shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
99  void releaseSoundBuffer(const std::shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
100 
101  ALuint getSoundSource(BaseSound* object);
102  void releaseSoundSource(ALuint source);
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 
113  void checkVolumeValidity(SoundType::Value type);
114  void checkSoundVolumeValidity() { this->checkVolumeValidity(SoundType::All); }
115  void checkAmbientVolumeValidity() { this->checkVolumeValidity(SoundType::Music); }
116  void checkEffectsVolumeValidity() { this->checkVolumeValidity(SoundType::Effects); }
117  void updateVolume(SoundType::Value type);
118 
119  unsigned int createSoundSources(unsigned int n);
120 
121  // OpenAL device/context related
122  std::vector<std::string> deviceNames_;
125 
126  // Ambient sound related
127  typedef std::list<std::pair<AmbientSound*, bool>> AmbientList;
128  AmbientList ambientSounds_;
131  std::list<StrongPtr<AmbientSound>> fadeInList_;
132  std::list<StrongPtr<AmbientSound>> fadeOutList_;
133 
134  // Volume related
135  float volume_[3];
136  float mute_[3];
137 
138  // Sound buffer related
139  static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024;
140  unsigned int effectsPoolSize_;
141  typedef std::list<std::shared_ptr<SoundBuffer>> EffectsPoolList;
142  EffectsPoolList effectsPool_;
143  typedef std::map<std::string, std::shared_ptr<SoundBuffer>> SoundBufferMap;
144  SoundBufferMap soundBuffers_;
145 
146  // Sound source related
147  unsigned int minSources_;
148  unsigned int maxSources_;
149  std::vector<ALuint> availableSoundSources_;
150  std::vector<std::pair<ALuint, BaseSound*>> usedSoundSources_;
151 
153 
155  }; // tolua_export
156 } // tolua_export
157 
158 #endif /* _SoundManager_H__ */
SoundBufferMap soundBuffers_
Definition: SoundManager.h:144
ALCdevice * device_
Definition: SoundManager.h:123
std::vector< ALuint > availableSoundSources_
Definition: SoundManager.h:149
struct ALCdevice_struct ALCdevice
Definition: OrxonoxPrereqs.h:221
void source(const std::string &filename)
Reads the content of a file and executes the commands in it line by line.
Definition: ConsoleCommandCompilation.cc:167
void checkSoundVolumeValidity()
Definition: SoundManager.h:114
unsigned int minSources_
Definition: SoundManager.h:147
void error(const std::string &text)
Prints output with error level.
Definition: ConsoleCommandCompilation.cc:145
::std::string string
Definition: gtest-port.h:756
Inherit from UpdateListener if you need to receive calls before or after the game is ticked...
Definition: UpdateListener.h:52
virtual void postUpdate(const Clock &time) override
Gets called by Core after the framework was ticked (but before graphics are drawn).
Definition: SoundManager.h:71
unsigned int effectsPoolSize_
Definition: SoundManager.h:140
std::list< StrongPtr< AmbientSound > > fadeOutList_
Definition: SoundManager.h:132
float crossFadeStep_
Absolute change per second (0.1 means 10% of the nominal volume) for cross fading.
Definition: SoundManager.h:130
AmbientList ambientSounds_
Definition: SoundManager.h:128
The BaseSound class is the base class for all sound file loader classes.
Definition: BaseSound.h:45
static SoundManager & getInstance()
Definition: SoundManager.h:75
Definition: SoundManager.h:54
int ALenum
Definition: OrxonoxPrereqs.h:224
This is the base class of all objects which may contain config values.
Definition: Configurable.h:47
The SoundManager class manages the OpenAL device, context and listener position.
Definition: SoundManager.h:60
std::list< StrongPtr< AmbientSound > > fadeInList_
Definition: SoundManager.h:131
Value
Definition: SoundManager.h:51
Base for singleton classes.
Definition: Singleton.h:114
static SoundManager * singletonPtr_s
Definition: SoundManager.h:154
std::vector< std::string > deviceNames_
Definition: SoundManager.h:122
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Definition: SoundManager.h:53
std::list< std::shared_ptr< SoundBuffer > > EffectsPoolList
Definition: SoundManager.h:141
Shared library macros, enums, constants and forward declarations for the orxonox library ...
Declaration of Configurable, the base class of all objects which may contain config values...
void checkAmbientVolumeValidity()
Definition: SoundManager.h:115
std::list< std::pair< AmbientSound *, bool > > AmbientList
Definition: SoundManager.h:127
static bool exists()
Definition: SoundManager.h:76
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
bool bDestructorCalled_
Becomes true if the destructor is called - used to prevent ambient sounds from registering after the ...
Definition: SoundManager.h:152
EffectsPoolList effectsPool_
Definition: SoundManager.h:142
Definition of the Singleton template that is used as base class for classes that allow only one insta...
std::string getDeviceName(unsigned int index) const
Definition: SoundManager.h:78
The AmbientSound class is used to play background music.
Definition: AmbientSound.h:44
std::vector< std::pair< ALuint, BaseSound * > > usedSoundSources_
Definition: SoundManager.h:150
Simple real time clock based on Ogre::Timer.
Definition: Clock.h:57
void checkEffectsVolumeValidity()
Definition: SoundManager.h:116
static bool exists()
Tells whether the singleton has been created.
Definition: Singleton.h:125
Definition of StrongPtr<T>, wraps a pointer to an object and keeps it alive.
struct ALCcontext_struct ALCcontext
Definition: OrxonoxPrereqs.h:220
Definition: SoundManager.h:55
unsigned int ALuint
Definition: OrxonoxPrereqs.h:222
static T & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118
std::map< std::string, std::shared_ptr< SoundBuffer > > SoundBufferMap
Definition: SoundManager.h:143
ALCcontext * context_
Definition: SoundManager.h:124
unsigned int maxSources_
Definition: SoundManager.h:148