FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
soundmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_SOUNDMANAGER_H
23 #define FIFE_SOUNDMANAGER_H
24 
25 // Standard C++ library includes
26 #include <queue>
27 
28 // Platform specific includes
29 
30 // 3rd party library includes
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
37 #include "util/base/singleton.h"
38 
39 #include "fife_openal.h"
40 #include "soundconfig.h"
41 
42 namespace FIFE {
43 
54  };
55 
63  };
64 
65  class SoundEffectManager;
66  class SoundEffect;
67  class SoundFilter;
68  class SoundEmitter;
69 
70  class SoundManager : public DynamicSingleton<SoundManager> {
71  public:
72 
73  SoundManager();
74 
75  ~SoundManager();
76 
79  void init();
80 
83  bool isActive() const;
84 
87  ALCcontext* getContext() const;
88 
93  void setVolume(float vol);
94 
97  float getVolume() const;
98 
101  void mute();
102 
105  void unmute();
106 
109  void play();
110 
113  void pause();
114 
117  void stop();
118 
121  void rewind();
122 
126 
130 
133  void setListenerPosition(const AudioSpaceCoordinate& position);
134 
138 
141  void setListenerOrientation(const AudioSpaceCoordinate& orientation);
142 
146 
149  void setListenerVelocity(const AudioSpaceCoordinate& velocity);
150 
154 
157  void setDopplerFactor(float factor);
158 
161  float getDopplerFactor() const;
162 
166  void setListenerMaxDistance(float distance);
167 
170  float getListenerMaxDistance() const;
171 
174  void update();
175 
181  SoundEmitter* getEmitter(uint32_t emitterId) const;
182 
186 
191  SoundEmitter* createEmitter(const std::string& name);
192 
197  void releaseEmitter(uint32_t emitterId);
198 
203  void deleteEmitter(SoundEmitter* emitter);
204 
209  void releaseSource(SoundEmitter* emitter);
210 
215 
220 
224  void deleteSoundEffect(SoundEffect* effect);
225 
228  void enableSoundEffect(SoundEffect* effect);
229 
232  void disableSoundEffect(SoundEffect* effect);
233 
237  void addEmitterToSoundEffect(SoundEffect* effect, SoundEmitter* emitter);
238 
241  void removeEmitterFromSoundEffect(SoundEffect* effect, SoundEmitter* emitter);
242 
246  void addSoundFilterToSoundEffect(SoundEffect* effect, SoundFilter* filter);
247 
251 
254  void activateEffect(SoundEffect* effect, SoundEmitter* emitter);
255 
258  void deactivateEffect(SoundEffect* effect, SoundEmitter* emitter);
259 
264 
268  void deleteSoundFilter(SoundFilter* filter);
269 
272  void enableDirectSoundFilter(SoundFilter* filter);
273 
277 
282 
286 
289  void activateFilter(SoundFilter* filter, SoundEmitter* emitter);
290 
293  void deactivateFilter(SoundFilter* filter, SoundEmitter* emitter);
294 
300  void addToGroup(SoundEmitter* emitter);
301 
307  void removeFromGroup(SoundEmitter* emitter);
308 
313  void removeGroup(const std::string& group);
314 
317  void removeAllGroups();
318 
323  void play(const std::string& group);
324 
329  void pause(const std::string& group);
330 
335  void stop(const std::string& group);
336 
341  void rewind(const std::string& group);
342 
348  void setGain(const std::string& group, float gain);
349 
355  void setMaxGain(const std::string& group, float gain);
356 
362  void setMinGain(const std::string& group, float gain);
363 
364  private:
365  typedef std::map<std::string, std::vector<SoundEmitter*> > EmitterGroups;
366  typedef EmitterGroups::iterator EmitterGroupsIterator;
367 
372  void setEmitterSource(SoundEmitter* emitter);
373 
375  std::vector<SoundEmitter*> m_emitterVec;
377  ALCcontext* m_context;
379  ALCdevice* m_device;
381  float m_muteVol;
383  float m_volume;
390 
396  std::queue<ALuint> m_freeSources;
398  std::map<SoundEmitter*, ALuint> m_activeEmitters;
399 
401 
403  EmitterGroups m_groups;
404  };
405 }
406 #endif
void setMinGain(const std::string &group, float gain)
Sets min gain for all emitters of the group.
void enableDirectSoundFilter(SoundFilter *filter)
Enables given direct SoundFilter.
const uint16_t MAX_SOURCES
Definition: soundconfig.h:196
void setListenerVelocity(const AudioSpaceCoordinate &velocity)
Sets the velocity of the listener (alter ego).
void deleteSoundFilter(SoundFilter *filter)
Deletes given SoundFilter.
void deleteEmitter(SoundEmitter *emitter)
Release given emitter.
void removeFromGroup(SoundEmitter *emitter)
Removes the emitter from group.
SoundManagerState m_state
State of the SoundManager.
Definition: soundmanager.h:389
float m_volume
volume to support setVolume-calls before initialization
Definition: soundmanager.h:383
void unmute()
Unmutes to volume before mute() was called.
float getListenerMaxDistance() const
Return the maximal listener distance.
void setListenerPosition(const AudioSpaceCoordinate &position)
Sets the position of the listener (alter ego).
void addEmitterToDirectSoundFilter(SoundFilter *filter, SoundEmitter *emitter)
Adds given SoundEmitter to the specific direct SoundFilter Note: A SoundEmitter can only have one dir...
SoundEffectPreset
Presets for EAX Reverb.
Definition: soundconfig.h:67
std::map< std::string, std::vector< SoundEmitter * > > EmitterGroups
Definition: soundmanager.h:365
void removeEmitterFromDirectSoundFilter(SoundFilter *filter, SoundEmitter *emitter)
Removes given SoundEmitter from the specific direct SoundFilter.
void enableSoundEffect(SoundEffect *effect)
Enables given SoundEffect.
float getDopplerFactor() const
Return factor for doppler effect.
void stop()
Stops all SoundEmitters.
SoundEffectManager * m_effectManager
Definition: soundmanager.h:400
SoundEmitter * createEmitter()
Returns a pointer to an allocated emitter-instance.
Base class for Efx sound effects.
Definition: soundeffect.h:46
The class defines filters.
Definition: soundfilter.h:43
std::vector< SoundEmitter * > m_emitterVec
emitter-vector, holds all emitters
Definition: soundmanager.h:375
AudioSpaceCoordinate getListenerPosition() const
Return the position of the listener (alter ego).
void disableDirectSoundFilter(SoundFilter *filter)
Disables given SoundFilter.
bool isActive() const
Returns true if audio module is active.
void removeGroup(const std::string &group)
Remove group and resets the group for the affected emitters.
ALCcontext * getContext() const
Returns an openAL context.
EmitterGroups::iterator EmitterGroupsIterator
Definition: soundmanager.h:366
ALuint m_sources[MAX_SOURCES]
Holds handles for sources.
Definition: soundmanager.h:392
SoundDistanceModelType m_distanceModel
Selected distance model.
Definition: soundmanager.h:387
void removeSoundFilterFromSoundEffect(SoundEffect *effect, SoundFilter *filter)
Removes given SoundFilter from the SoundEffect.
void activateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundEffect for the SoundEmitter.
ALCcontext * m_context
OpenAL context.
Definition: soundmanager.h:377
void deactivateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundEffect for the SoundEmitter.
float getVolume() const
Return the Master Volume.
void init()
Initializes the audio system.
SoundEffect * createSoundEffectPreset(SoundEffectPreset type)
Creates EaxReverb SoundEffect and loads the specific preset type.
void deactivateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundFilter for the SoundEmitter.
void setDopplerFactor(float factor)
Sets factor for doppler effect.
AudioSpaceCoordinate getListenerOrientation() const
Return the orientation of the listener (alter ego).
void setVolume(float vol)
Sets the Master Volume.
void removeEmitterFromSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Removes given SoundEmitter from the specific SoundEffect.
std::queue< ALuint > m_freeSources
Holds free handles for sources.
Definition: soundmanager.h:396
void addEmitterToSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Adds given SoundEmitter to the specific SoundEffect.
Another Singleton.
Definition: singleton.h:82
void setMaxGain(const std::string &group, float gain)
Sets max gain for all emitters of the group.
ALCdevice * m_device
OpenAL device.
Definition: soundmanager.h:379
SoundDistanceModelType
Distance model from OpenAL.
Definition: soundmanager.h:46
std::map< SoundEmitter *, ALuint > m_activeEmitters
Map that holds active Emitters together with the used source handle.
Definition: soundmanager.h:398
void removeAllGroups()
Remove all groups and resets the group of affected emitters.
void update()
Called once a frame and updates the sound objects.
void addToGroup(SoundEmitter *emitter)
Adds the emitter to group.
void releaseSource(SoundEmitter *emitter)
Release the source handle.
unsigned short uint16_t
Definition: core.h:39
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198
SoundFilter * createSoundFilter(SoundFilterType type)
Creates SoundFilter of the specific type.
void addSoundFilterToSoundEffect(SoundEffect *effect, SoundFilter *filter)
Adds given SoundFilter to the SoundEffect.
The class for playing audio files.
Definition: soundemitter.h:70
void activateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundFilter for the SoundEmitter.
SoundEffectType
Sound effect type.
Definition: soundconfig.h:48
float m_maxDistance
distance that removes a active Emitter
Definition: soundmanager.h:385
void pause()
Pauses all SoundEmitters.
SoundEffect * createSoundEffect(SoundEffectType type)
Creates SoundEffect of the specific type.
void disableSoundEffect(SoundEffect *effect)
Disables given SoundEffect.
SoundEmitter * getEmitter(uint32_t emitterId) const
Returns a pointer to an emitter-instance given by emitterId.
AudioSpaceCoordinate getListenerVelocity() const
Return the velocity of the listener (alter ego).
void setGain(const std::string &group, float gain)
Sets gain for all emitters of the group.
void setEmitterSource(SoundEmitter *emitter)
Sets the source handle.
SoundFilterType
Sound filter type.
Definition: soundconfig.h:39
void play()
Plays all SoundEmitters.
void releaseEmitter(uint32_t emitterId)
Release an emitter-instance given by emitter-id.
void deleteSoundEffect(SoundEffect *effect)
Deletes given SoundEffect.
SoundManagerState
SoundManager state.
Definition: soundmanager.h:58
void rewind()
Rewinds all SoundEmitters.
void setListenerMaxDistance(float distance)
Sets the maximal listener distance.
uint16_t m_createdSources
Maximal created sources, can be different to MAX_SOURCES.
Definition: soundmanager.h:394
unsigned int uint32_t
Definition: core.h:40
void setDistanceModel(SoundDistanceModelType model)
Sets the distance model.
EmitterGroups m_groups
A map that holds the groups together with the appended emitters.
Definition: soundmanager.h:403
float m_muteVol
volume before mute() was called
Definition: soundmanager.h:381
void setListenerOrientation(const AudioSpaceCoordinate &orientation)
Sets the orientation of the listener (alter ego).
SoundDistanceModelType getDistanceModel() const
Return the distance mode.