FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
soundmanager.cpp
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 // Standard C++ library includes
23 
24 // Platform specific includes
25 
26 // 3rd party library includes
27 
28 // FIFE includes
29 // These includes are split up in two parts, separated by one empty line
30 // First block: files included from the FIFE root src directory
31 // Second block: files included from the same folder
33 #include "vfs/vfs.h"
34 #include "util/log/logger.h"
35 #include "util/base/exception.h"
36 
37 #include "soundclipmanager.h"
38 #include "soundemitter.h"
39 #include "soundmanager.h"
40 
41 namespace FIFE {
45  static Logger _log(LM_AUDIO);
46 
48  m_context(0),
49  m_device(0),
50  m_muteVol(0),
51  m_volume(1.0),
52  m_maxDistance(50.0),
53  m_distanceModel(SD_DISTANCE_INVERSE_CLAMPED),
54  m_state(SM_STATE_INACTIV),
55  m_sources(),
56  m_createdSources(0),
57  m_effectManager(NULL) {
58  }
59 
61  // delete all soundemitters
62  for (std::vector<SoundEmitter*>::iterator it = m_emitterVec.begin(); it != m_emitterVec.end(); ++it) {
63  if ((*it) != NULL) {
64  delete (*it);
65  }
66  }
67  m_emitterVec.clear();
68  // delete all sources
69  alDeleteSources(m_createdSources, m_sources);
70  // delete effect manager
71  delete m_effectManager;
72 
73  if (m_device) {
74  alcDestroyContext(m_context);
75  alcCloseDevice(m_device);
76  m_device = NULL;
77  }
78 
79  if (alcGetError(NULL) != ALC_NO_ERROR) {
80  FL_ERR(_log, LMsg() << "error closing openal device");
81  }
82  }
83 
85  m_device = alcOpenDevice(NULL);
86 
87  if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) {
88  FL_ERR(_log, LMsg() << "Could not open audio device - deactivating audio module");
89  m_device = NULL;
90  return;
91  }
92 
93  m_context = alcCreateContext(m_device, NULL);
94  if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) {
95  FL_ERR(_log, LMsg() << "Couldn't create audio context - deactivating audio module");
96  m_device = NULL;
97  return;
98  }
99 
100  alcMakeContextCurrent(m_context);
101  if (alcGetError(m_device) != ALC_NO_ERROR) {
102  FL_ERR(_log, LMsg() << "Couldn't change current audio context - deactivating audio module");
103  m_device = NULL;
104  return;
105  }
106  // create and initialize the effect manager
109 
110  // set listener position
111  alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
112  ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
113  alListenerfv(AL_ORIENTATION, vec1);
114 
115  // set volume
116  alListenerf(AL_GAIN, m_volume);
117 
118  // create max sources
119  for (uint16_t i = 0; i < MAX_SOURCES; i++) {
120  alGenSources(1, &m_sources[i]);
121  if (alGetError() != AL_NO_ERROR) {
122  break;
123  }
124 
125  m_freeSources.push(m_sources[i]);
127  }
129  }
130 
131  bool SoundManager::isActive() const {
132  return m_state != SM_STATE_INACTIV;
133  }
134 
135  ALCcontext* SoundManager::getContext() const {
136  return m_context;
137  }
138 
139  void SoundManager::setVolume(float vol) {
140  m_volume = vol;
141  m_muteVol = vol;
142  if (isActive()) {
143  alListenerf(AL_GAIN, vol);
144  }
145  }
146 
147  float SoundManager::getVolume() const {
148  return m_volume;
149  }
150 
152  if (isActive()) {
153  alGetListenerf(AL_GAIN, &m_muteVol);
154  alListenerf(AL_GAIN, 0);
155  }
156  }
157 
159  if (isActive()) {
160  alListenerf(AL_GAIN, m_muteVol);
161  }
162  }
163 
166  for (std::vector<SoundEmitter*>::iterator it = m_emitterVec.begin(); it != m_emitterVec.end(); ++it) {
167  SoundEmitter* emitter = (*it);
168  if (!emitter) {
169  continue;
170  }
171  emitter->play();
172  }
173  }
174 
177  for (std::vector<SoundEmitter*>::iterator it = m_emitterVec.begin(); it != m_emitterVec.end(); ++it) {
178  SoundEmitter* emitter = (*it);
179  if (!emitter) {
180  continue;
181  }
182  emitter->pause();
183  }
184  }
185 
188  for (std::vector<SoundEmitter*>::iterator it = m_emitterVec.begin(); it != m_emitterVec.end(); ++it) {
189  SoundEmitter* emitter = (*it);
190  if (!emitter) {
191  continue;
192  }
193  emitter->stop();
194  }
195  }
196 
198  for (std::vector<SoundEmitter*>::iterator it = m_emitterVec.begin(); it != m_emitterVec.end(); ++it) {
199  SoundEmitter* emitter = (*it);
200  if (!emitter) {
201  continue;
202  }
203  emitter->rewind();
204  }
205  }
206 
208  m_distanceModel = model;
209  if (!isActive()) {
210  return;
211  }
212 
213  switch (m_distanceModel) {
214  case SD_DISTANCE_NONE:
215  alDistanceModel(AL_NONE);
216  break;
217  case SD_DISTANCE_INVERSE:
218  alDistanceModel(AL_INVERSE_DISTANCE);
219  break;
221  alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
222  break;
223  case SD_DISTANCE_LINEAR:
224  alDistanceModel(AL_LINEAR_DISTANCE);
225  break;
227  alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
228  break;
230  alDistanceModel(AL_EXPONENT_DISTANCE);
231  break;
233  alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
234  break;
235  default:
236  break;
237  }
238  }
239 
241  return m_distanceModel;
242  }
243 
245  if (isActive()) {
246  alListener3f(AL_POSITION, static_cast<ALfloat>(position.x), static_cast<ALfloat>(position.y), static_cast<ALfloat>(position.z));
247  }
248  }
249 
251  if (isActive()) {
252  ALfloat vec[3];
253  alGetListenerfv(AL_POSITION, vec);
254  return AudioSpaceCoordinate(vec[0], vec[1], vec[2]);
255  }
256  return AudioSpaceCoordinate();
257  }
258 
260  if (isActive()) {
261  ALfloat vec[6] = { static_cast<ALfloat>(orientation.x), static_cast<ALfloat>(orientation.y), static_cast<ALfloat>(orientation.z),
262  0.0, 0.0, 1.0 };
263  alListenerfv(AL_ORIENTATION, vec);
264  }
265  }
266 
268  if (isActive()) {
269  ALfloat vec[6];
270  alGetListenerfv(AL_ORIENTATION, vec);
271  return AudioSpaceCoordinate(vec[0], vec[1], vec[2]);
272  }
273  return AudioSpaceCoordinate();
274  }
275 
277  if (isActive()) {
278  alListener3f(AL_VELOCITY, static_cast<ALfloat>(velocity.x), static_cast<ALfloat>(velocity.y), static_cast<ALfloat>(velocity.z));
279  }
280  }
281 
283  if (isActive()) {
284  ALfloat vec[3];
285  alGetListenerfv(AL_VELOCITY, vec);
286  return AudioSpaceCoordinate(vec[0], vec[1], vec[2]);
287  }
288  return AudioSpaceCoordinate();
289  }
290 
291  void SoundManager::setDopplerFactor(float factor) {
292  if (isActive()) {
293  if (factor >= 0.0) {
294  alDopplerFactor(factor);
295  }
296  }
297  }
298 
300  if (isActive()) {
301  return alGetFloat(AL_DOPPLER_FACTOR);
302  }
303  return 0.0;
304  }
305 
308  }
309 
311  return m_maxDistance;
312  }
313 
315  if (m_state != SM_STATE_PLAY) {
316  return;
317  }
319  double maxDistance = static_cast<double>(m_maxDistance);
320 
321  // first check emitters
322  for (std::vector<SoundEmitter*>::iterator it = m_emitterVec.begin(); it != m_emitterVec.end(); ++it) {
323  SoundEmitter* emitter = (*it);
324  if (!emitter) {
325  continue;
326  }
327  emitter->setCheckDifference();
328 
329  bool active = emitter->isActive();
330  bool clip = emitter->getSoundClip();
331  bool plays = !emitter->isFinished();
332  // remove active without clip or stopped
333  if (!clip || !plays) {
334  if (active) {
335  emitter->update();
336  releaseSource(emitter);
337  }
338  continue;
339  }
340 
341  bool inRange = true;
342  if (emitter->isPosition()) {
343  AudioSpaceCoordinate emitterPos = emitter->getPosition();
344  double rx = listenerPos.x - emitterPos.x;
345  double ry = listenerPos.y - emitterPos.y;
346  double rz = listenerPos.z - emitterPos.z;
347  inRange = maxDistance >= Mathd::Sqrt(rx*rx + ry*ry + rz*rz);
348  }
349  // remove active not in range
350  if (!inRange) {
351  if (active) {
352  releaseSource(emitter);
353  }
354  continue;
355  }
356  if (!active && !m_freeSources.empty()) {
357  setEmitterSource(emitter);
358  }
359  }
360  // then update active
361  for (std::map<SoundEmitter*, ALuint>::iterator it = m_activeEmitters.begin(); it != m_activeEmitters.end(); ++it) {
362  it->first->update();
363  }
364  }
365 
367  return m_emitterVec.at(emitterId);
368  }
369 
371  SoundEmitter* ptr = NULL;
372  for (uint32_t i = 0; i < m_emitterVec.size(); i++) {
373  if (m_emitterVec.at(i) == NULL) {
374  ptr = new SoundEmitter(this, i);
375  m_emitterVec.at(i) = ptr;
376  break;
377  }
378  }
379  if (!ptr) {
380  ptr = new SoundEmitter(this, m_emitterVec.size());
381  m_emitterVec.push_back(ptr);
382  }
383  return ptr;
384  }
385 
386  SoundEmitter* SoundManager::createEmitter(const std::string& name) {
387  SoundEmitter* emitter = createEmitter();
388  emitter->setSoundClip(SoundClipManager::instance()->get(name));
389  return emitter;
390  }
391 
393  SoundEmitter** ptr = &m_emitterVec.at(emitterId);
394  if ((*ptr)->isActive()) {
395  releaseSource(*ptr);
396  }
397  delete *ptr;
398  *ptr = NULL;
399  }
400 
402  releaseEmitter(emitter->getId());
403  }
404 
406  std::pair<std::map<SoundEmitter*, ALuint>::iterator, bool> ret;
407  ret = m_activeEmitters.insert(std::pair<SoundEmitter*, ALuint>(emitter, m_freeSources.front()));
408  if (ret.second == false) {
409  FL_WARN(_log, LMsg() << "SoundEmitter already have an source handler");
410  }
411  emitter->setSource(m_freeSources.front());
412  m_freeSources.pop();
413  }
414 
416  if (emitter->isActive()) {
417  std::map<SoundEmitter*, ALuint>::iterator it = m_activeEmitters.find(emitter);
418  if (it != m_activeEmitters.end()) {
419  m_freeSources.push(it->second);
420  m_activeEmitters.erase(it);
421  emitter->setSource(0);
422  } else {
423  FL_WARN(_log, LMsg() << "SoundEmitter can not release source handler");
424  }
425  }
426  }
427 
429  return m_effectManager->createSoundEffect(type);
430  }
431 
434  }
435 
438  }
439 
442  }
443 
446  }
447 
449  m_effectManager->addEmitterToSoundEffect(effect, emitter);
450  }
451 
454  }
455 
458  }
459 
462  }
463 
465  m_effectManager->activateEffect(effect, emitter);
466  }
467 
469  m_effectManager->deactivateEffect(effect, emitter);
470  }
471 
473  return m_effectManager->createSoundFilter(type);
474  }
475 
478  }
479 
482  }
483 
486  }
487 
490  }
491 
494  }
495 
497  m_effectManager->activateFilter(filter, emitter);
498  }
499 
501  m_effectManager->deactivateFilter(filter, emitter);
502  }
503 
505  if (emitter->getGroup() != "") {
506  m_groups[emitter->getGroup()].push_back(emitter);
507  }
508  }
509 
511  std::string group = emitter->getGroup();
512  if (group == "") {
513  return;
514  }
515  EmitterGroupsIterator groupIt = m_groups.find(group);
516  if (groupIt == m_groups.end()) {
517  FL_WARN(_log, LMsg() << "SoundEmitter can not removed from unknown group");
518  return;
519  }
520  bool found = false;
521  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
522  std::vector<SoundEmitter*>::iterator emitterEnd = groupIt->second.end();
523  while (emitterIt != emitterEnd) {
524  if ((*emitterIt) == emitter) {
525  groupIt->second.erase(emitterIt++);
526  found = true;
527  } else {
528  ++emitterIt;
529  }
530  }
531  if (!found) {
532  FL_WARN(_log, LMsg() << "SoundEmitter could not be found in the given group.");
533  return;
534  }
535  }
536 
537  void SoundManager::removeGroup(const std::string& group) {
538  if (group == "") {
539  return;
540  }
541  EmitterGroupsIterator groupIt = m_groups.find(group);
542  if (groupIt == m_groups.end()) {
543  FL_WARN(_log, LMsg() << "SoundEmitter can not remove unknown group");
544  return;
545  }
546  std::vector<SoundEmitter*> emitters = groupIt->second;
547  for (std::vector<SoundEmitter*>::iterator it = emitters.begin(); it != emitters.end(); ++it) {
548  (*it)->setGroup("");
549  }
550  m_groups.erase(group);
551  }
552 
554  std::vector<std::string> groups;
555  for (EmitterGroupsIterator it = m_groups.begin(); it != m_groups.end(); ++it) {
556  groups.push_back(it->first);
557  }
558  for (std::vector<std::string>::iterator it = groups.begin(); it != groups.end(); ++it) {
559  removeGroup(*it);
560  }
561  m_groups.clear();
562  }
563 
564  void SoundManager::play(const std::string& group) {
565  EmitterGroupsIterator groupIt = m_groups.find(group);
566  if (groupIt == m_groups.end()) {
567  FL_WARN(_log, LMsg() << "Unknown group can not played");
568  return;
569  }
570  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
571  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
572  (*emitterIt)->play();
573  }
574  }
575 
576  void SoundManager::pause(const std::string& group) {
577  EmitterGroupsIterator groupIt = m_groups.find(group);
578  if (groupIt == m_groups.end()) {
579  FL_WARN(_log, LMsg() << "Unknown group can not paused");
580  return;
581  }
582  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
583  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
584  (*emitterIt)->pause();
585  }
586  }
587 
588  void SoundManager::stop(const std::string& group) {
589  EmitterGroupsIterator groupIt = m_groups.find(group);
590  if (groupIt == m_groups.end()) {
591  FL_WARN(_log, LMsg() << "Unknown group can not stopped");
592  return;
593  }
594  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
595  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
596  (*emitterIt)->stop();
597  }
598  }
599 
600  void SoundManager::rewind(const std::string& group) {
601  EmitterGroupsIterator groupIt = m_groups.find(group);
602  if (groupIt == m_groups.end()) {
603  FL_WARN(_log, LMsg() << "Unknown group can not rewinded");
604  return;
605  }
606  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
607  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
608  (*emitterIt)->rewind();
609  }
610  }
611 
612  void SoundManager::setGain(const std::string& group, float gain) {
613  EmitterGroupsIterator groupIt = m_groups.find(group);
614  if (groupIt == m_groups.end()) {
615  FL_WARN(_log, LMsg() << "Unknown group can not set gain");
616  return;
617  }
618  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
619  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
620  (*emitterIt)->setGain(gain);
621  }
622  }
623 
624  void SoundManager::setMaxGain(const std::string& group, float gain) {
625  EmitterGroupsIterator groupIt = m_groups.find(group);
626  if (groupIt == m_groups.end()) {
627  FL_WARN(_log, LMsg() << "Unknown group can not set max gain");
628  return;
629  }
630  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
631  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
632  (*emitterIt)->setMaxGain(gain);
633  }
634  }
635 
636  void SoundManager::setMinGain(const std::string& group, float gain) {
637  EmitterGroupsIterator groupIt = m_groups.find(group);
638  if (groupIt == m_groups.end()) {
639  FL_WARN(_log, LMsg() << "Unknown group can not set min gain");
640  return;
641  }
642  std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
643  for (; emitterIt != groupIt->second.end(); ++emitterIt) {
644  (*emitterIt)->setMinGain(gain);
645  }
646  }
647 
648 } //FIFE
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.
#define FL_WARN(logger, msg)
Definition: logger.h:72
void setSource(ALuint source)
Sets openAl-source.
const uint16_t MAX_SOURCES
Definition: soundconfig.h:196
void enableDirectSoundFilter(SoundFilter *filter)
Enables given direct SoundFilter.
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 removeEmitterFromSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Removes given SoundEmitter from the specific SoundEffect.
void removeFromGroup(SoundEmitter *emitter)
Removes the emitter from group.
SoundManagerState m_state
State of the SoundManager.
Definition: soundmanager.h:389
void init(ALCdevice *device)
Initializes the effect system.
static T Sqrt(T _val)
Definition: fife_math.h:277
void deactivateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundFilter for the SoundEmitter.
float m_volume
volume to support setVolume-calls before initialization
Definition: soundmanager.h:383
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Definition: logger.h:82
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
void activateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundEffect for the SoundEmitter.
void update()
Called once a frame from the SoundManager.
const std::string & getGroup()
Return the group name.
void deleteSoundFilter(SoundFilter *filter)
Deletes given SoundFilter.
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.
void setCheckDifference()
Sets the time difference between play and the first check if it&#39;s playable.
bool isPosition() const
Return if it is a positional SoundEmitter.
SoundEffectManager * m_effectManager
Definition: soundmanager.h:400
SoundEmitter * createEmitter()
Returns a pointer to an allocated emitter-instance.
void pause()
Pauses playing the audio file.
SoundEffect * createSoundEffect(SoundEffectType type)
Creates SoundEffect of the specific type.
Base class for Efx sound effects.
Definition: soundeffect.h:46
The class defines filters.
Definition: soundfilter.h:43
DoublePoint3D AudioSpaceCoordinate
Definition: modelcoords.h:36
void addSoundFilterToSoundEffect(SoundEffect *effect, SoundFilter *filter)
Adds given SoundFilter to the SoundEffect.
static Logger _log(LM_AUDIO)
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 disableSoundEffect(SoundEffect *effect)
Disables given SoundEffect.
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.
static SoundClipManager * instance()
Definition: singleton.h:84
void activateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundEffect for the SoundEmitter.
void addEmitterToDirectSoundFilter(SoundFilter *filter, SoundEmitter *emitter)
Adds given SoundEmitter to the specific direct SoundFilter Note: A SoundEmitter can only have one dir...
void removeSoundFilterFromSoundEffect(SoundEffect *effect, SoundFilter *filter)
Removes given SoundFilter from the SoundEffect.
ALCcontext * m_context
OpenAL context.
Definition: soundmanager.h:377
#define FL_ERR(logger, msg)
Definition: logger.h:73
void disableDirectSoundFilter(SoundFilter *filter)
Disables given SoundFilter.
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 play()
Plays the associated audio file.
void addEmitterToSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Adds given SoundEmitter to the specific SoundEffect.
SoundFilter * createSoundFilter(SoundFilterType type)
Creates SoundFilter of the specific type.
uint32_t getId() const
Returns the emitter-id.
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.
AudioSpaceCoordinate getPosition() const
Return the position of the SoundEmitter in the virtual audio space.
unsigned short uint16_t
Definition: core.h:39
void deleteSoundEffect(SoundEffect *effect)
Deletes given SoundEffect.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198
void removeEmitterFromDirectSoundFilter(SoundFilter *filter, SoundEmitter *emitter)
Removes given SoundEmitter from the specific direct SoundFilter.
SoundEffect * createSoundEffectPreset(SoundEffectPreset type)
Creates EaxReverb SoundEffect and loads the specific preset type.
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.
void deactivateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundEffect for the SoundEmitter.
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.
SoundClipPtr getSoundClip()
Get the current sound clip used by this emitter.
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 activateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundFilter for the SoundEmitter.
void rewind()
Rewinds the associated audio file.
void enableSoundEffect(SoundEffect *effect)
Enables given SoundEffect.
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.
void stop()
Stops playing the audio file and rewinds to the beginning.
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 addEmitterToSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Adds given SoundEmitter to the specific SoundEffect.
void setSoundClip(SoundClipPtr soundClip)
Sets the sound clip to be used by this emitter.
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.
bool isActive() const
Return if the Emitter is active / have an openAl-source.
bool isFinished()
Returns true if clip is finished.