57 m_effectManager(NULL) {
79 if (alcGetError(NULL) != ALC_NO_ERROR) {
88 FL_ERR(
_log,
LMsg() <<
"Could not open audio device - deactivating audio module");
95 FL_ERR(
_log,
LMsg() <<
"Couldn't create audio context - deactivating audio module");
101 if (alcGetError(
m_device) != ALC_NO_ERROR) {
102 FL_ERR(
_log,
LMsg() <<
"Couldn't change current audio context - deactivating audio module");
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);
121 if (alGetError() != AL_NO_ERROR) {
143 alListenerf(AL_GAIN, vol);
154 alListenerf(AL_GAIN, 0);
215 alDistanceModel(AL_NONE);
218 alDistanceModel(AL_INVERSE_DISTANCE);
221 alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
224 alDistanceModel(AL_LINEAR_DISTANCE);
227 alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
230 alDistanceModel(AL_EXPONENT_DISTANCE);
233 alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
246 alListener3f(AL_POSITION, static_cast<ALfloat>(position.
x), static_cast<ALfloat>(position.
y), static_cast<ALfloat>(position.
z));
253 alGetListenerfv(AL_POSITION, vec);
261 ALfloat vec[6] = {
static_cast<ALfloat
>(orientation.
x), static_cast<ALfloat>(orientation.
y),
static_cast<ALfloat
>(orientation.
z),
263 alListenerfv(AL_ORIENTATION, vec);
270 alGetListenerfv(AL_ORIENTATION, vec);
278 alListener3f(AL_VELOCITY, static_cast<ALfloat>(velocity.
x), static_cast<ALfloat>(velocity.
y), static_cast<ALfloat>(velocity.
z));
285 alGetListenerfv(AL_VELOCITY, vec);
294 alDopplerFactor(factor);
301 return alGetFloat(AL_DOPPLER_FACTOR);
333 if (!clip || !plays) {
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);
394 if ((*ptr)->isActive()) {
406 std::pair<std::map<SoundEmitter*, ALuint>::iterator,
bool> ret;
408 if (ret.second ==
false) {
409 FL_WARN(
_log,
LMsg() <<
"SoundEmitter already have an source handler");
417 std::map<SoundEmitter*, ALuint>::iterator it =
m_activeEmitters.find(emitter);
423 FL_WARN(
_log,
LMsg() <<
"SoundEmitter can not release source handler");
511 std::string group = emitter->
getGroup();
517 FL_WARN(
_log,
LMsg() <<
"SoundEmitter can not removed from unknown group");
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++);
532 FL_WARN(
_log,
LMsg() <<
"SoundEmitter could not be found in the given group.");
546 std::vector<SoundEmitter*> emitters = groupIt->second;
547 for (std::vector<SoundEmitter*>::iterator it = emitters.begin(); it != emitters.end(); ++it) {
554 std::vector<std::string> groups;
556 groups.push_back(it->first);
558 for (std::vector<std::string>::iterator it = groups.begin(); it != groups.end(); ++it) {
570 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
571 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
572 (*emitterIt)->play();
582 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
583 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
584 (*emitterIt)->pause();
594 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
595 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
596 (*emitterIt)->stop();
606 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
607 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
608 (*emitterIt)->rewind();
618 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
619 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
620 (*emitterIt)->setGain(gain);
630 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
631 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
632 (*emitterIt)->setMaxGain(gain);
642 std::vector<SoundEmitter*>::iterator emitterIt = groupIt->second.begin();
643 for (; emitterIt != groupIt->second.end(); ++emitterIt) {
644 (*emitterIt)->setMinGain(gain);
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)
void setSource(ALuint source)
Sets openAl-source.
const uint16_t MAX_SOURCES
void enableDirectSoundFilter(SoundFilter *filter)
Enables given direct SoundFilter.
void setListenerVelocity(const AudioSpaceCoordinate &velocity)
Sets the velocity of the listener (alter ego).
uint32_t getId() const
Returns the emitter-id.
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.
void init(ALCdevice *device)
Initializes the effect system.
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
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
void unmute()
Unmutes to volume before mute() was called.
float getDopplerFactor() const
Return factor for doppler effect.
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.
bool isPosition() const
Return if it is a positional SoundEmitter.
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.
void stop()
Stops all SoundEmitters.
void setCheckDifference()
Sets the time difference between play and the first check if it's playable.
SoundEffectManager * m_effectManager
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.
The class defines filters.
DoublePoint3D AudioSpaceCoordinate
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
void disableSoundEffect(SoundEffect *effect)
Disables given SoundEffect.
bool isActive() const
Return if the Emitter is active / have an openAl-source.
void disableDirectSoundFilter(SoundFilter *filter)
Disables given SoundFilter.
void removeGroup(const std::string &group)
Remove group and resets the group for the affected emitters.
EmitterGroups::iterator EmitterGroupsIterator
AudioSpaceCoordinate getListenerPosition() const
Return the position of the listener (alter ego).
ALuint m_sources[MAX_SOURCES]
Holds handles for sources.
SoundDistanceModelType m_distanceModel
Selected distance model.
void removeSoundFilterFromSoundEffect(SoundEffect *effect, SoundFilter *filter)
Removes given SoundFilter from the SoundEffect.
static SoundClipManager * instance()
SoundDistanceModelType getDistanceModel() const
Return the distance mode.
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.
float getVolume() const
Return the Master Volume.
#define FL_ERR(logger, msg)
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.
AudioSpaceCoordinate getListenerVelocity() const
Return the velocity of the listener (alter ego).
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.
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.
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.
void setMaxGain(const std::string &group, float gain)
Sets max gain for all emitters of the group.
ALCdevice * m_device
OpenAL device.
SoundDistanceModelType
Distance model from OpenAL.
std::map< SoundEmitter *, ALuint > m_activeEmitters
Map that holds active Emitters together with the used source handle.
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.
void deleteSoundEffect(SoundEffect *effect)
Deletes given SoundEffect.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
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.
void activateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundFilter for the SoundEmitter.
SoundEffectType
Sound effect type.
float m_maxDistance
distance that removes a active Emitter
ALCcontext * getContext() const
Returns an openAL context.
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.
float getListenerMaxDistance() const
Return the maximal listener distance.
SoundEffect * createSoundEffect(SoundEffectType type)
Creates SoundEffect of the specific type.
void disableSoundEffect(SoundEffect *effect)
Disables given SoundEffect.
AudioSpaceCoordinate getListenerOrientation() const
Return the orientation of the listener (alter ego).
SoundClipPtr getSoundClip()
Get the current sound clip used by this emitter.
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.
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.
void addEmitterToSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Adds given SoundEmitter to the specific SoundEffect.
AudioSpaceCoordinate getPosition() const
Return the position of the SoundEmitter in the virtual audio space.
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.
SoundEmitter * getEmitter(uint32_t emitterId) const
Returns a pointer to an emitter-instance given by emitterId.
bool isActive() const
Returns true if audio module is active.
float m_muteVol
volume before mute() was called
void setListenerOrientation(const AudioSpaceCoordinate &orientation)
Sets the orientation of the listener (alter ego).
bool isFinished()
Returns true if clip is finished.