| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 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_SOUNDEFFECTMANAGER_H |
| 23 |
#define FIFE_SOUNDEFFECTMANAGER_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <queue> |
| 27 |
#include <map> |
| 28 |
|
| 29 |
// Platform specific includes |
| 30 |
|
| 31 |
// 3rd party library includes |
| 32 |
|
| 33 |
// FIFE includes |
| 34 |
// These includes are split up in two parts, separated by one empty line |
| 35 |
// First block: files included from the FIFE root src directory |
| 36 |
// Second block: files included from the same folder |
| 37 |
#include "audio/fife_openal.h" |
| 38 |
#include "audio/soundconfig.h" |
| 39 |
|
| 40 |
namespace FIFE { |
| 41 |
|
| 42 |
class SoundEffect; |
| 43 |
class SoundFilter; |
| 44 |
class SoundEmitter; |
| 45 |
|
| 46 |
class SoundEffectManager { |
| 47 |
public: |
| 48 |
/** Constructor |
| 49 |
*/ |
| 50 |
SoundEffectManager(); |
| 51 |
|
| 52 |
/** Destructor |
| 53 |
*/ |
| 54 |
~SoundEffectManager(); |
| 55 |
|
| 56 |
/** Initializes the effect system |
| 57 |
*/ |
| 58 |
void init(ALCdevice* device); |
| 59 |
|
| 60 |
/** Returns true if sound effect module is active |
| 61 |
*/ |
| 62 |
bool isActive() const; |
| 63 |
|
| 64 |
/** Creates SoundEffect of the specific type. |
| 65 |
* @param type See SoundEffectType |
| 66 |
*/ |
| 67 |
SoundEffect* createSoundEffect(SoundEffectType type); |
| 68 |
|
| 69 |
/** Creates EaxReverb SoundEffect and loads the specific preset type. |
| 70 |
* @param type See SoundEffectPreset |
| 71 |
*/ |
| 72 |
SoundEffect* createSoundEffectPreset(SoundEffectPreset type); |
| 73 |
|
| 74 |
/** Deletes given SoundEffect. |
| 75 |
* Deactivates for SoundEmitters are automatically done. |
| 76 |
*/ |
| 77 |
void deleteSoundEffect(SoundEffect* effect); |
| 78 |
|
| 79 |
/** Enables given SoundEffect. |
| 80 |
*/ |
| 81 |
void enableSoundEffect(SoundEffect* effect); |
| 82 |
|
| 83 |
/** Disables given SoundEffect. |
| 84 |
*/ |
| 85 |
void disableSoundEffect(SoundEffect* effect); |
| 86 |
|
| 87 |
/** Adds given SoundEmitter to the specific SoundEffect. |
| 88 |
* Note: A SoundEmitter can only have a limited number of effects, usually 4. |
| 89 |
*/ |
| 90 |
void addEmitterToSoundEffect(SoundEffect* effect, SoundEmitter* emitter); |
| 91 |
|
| 92 |
/** Removes given SoundEmitter from the specific SoundEffect. |
| 93 |
*/ |
| 94 |
void removeEmitterFromSoundEffect(SoundEffect* effect, SoundEmitter* emitter); |
| 95 |
|
| 96 |
/** Adds given SoundFilter to the SoundEffect. |
| 97 |
* Note: A SoundEffect can only have one SoundFilter. |
| 98 |
*/ |
| 99 |
void addSoundFilterToSoundEffect(SoundEffect* effect, SoundFilter* filter); |
| 100 |
|
| 101 |
/** Removes given SoundFilter from the SoundEffect. |
| 102 |
*/ |
| 103 |
void removeSoundFilterFromSoundEffect(SoundEffect* effect, SoundFilter* filter); |
| 104 |
|
| 105 |
/** Internal function to do the OpenAL calls to activate the SoundEffect for the SoundEmitter. |
| 106 |
*/ |
| 107 |
void activateEffect(SoundEffect* effect, SoundEmitter* emitter); |
| 108 |
|
| 109 |
/** Internal function to do the OpenAL calls to deactivate the SoundEffect for the SoundEmitter. |
| 110 |
*/ |
| 111 |
void deactivateEffect(SoundEffect* effect, SoundEmitter* emitter); |
| 112 |
|
| 113 |
/** Creates SoundFilter of the specific type. |
| 114 |
* @param type See SoundFilterType |
| 115 |
*/ |
| 116 |
SoundFilter* createSoundFilter(SoundFilterType type); |
| 117 |
|
| 118 |
/** Deletes given SoundFilter. |
| 119 |
* Deactivates for SoundEmitters and Effects are automatically done. |
| 120 |
*/ |
| 121 |
void deleteSoundFilter(SoundFilter* filter); |
| 122 |
|
| 123 |
/** Enables given direct SoundFilter. Only SoundFilters for SoundEmitters are meant. |
| 124 |
*/ |
| 125 |
void enableDirectSoundFilter(SoundFilter* filter); |
| 126 |
|
| 127 |
/** Disables given SoundFilter. Only SoundFilters for SoundEmitters are meant. |
| 128 |
*/ |
| 129 |
void disableDirectSoundFilter(SoundFilter* filter); |
| 130 |
|
| 131 |
/** Adds given SoundEmitter to the specific direct SoundFilter |
| 132 |
* Note: A SoundEmitter can only have one direct filter. |
| 133 |
*/ |
| 134 |
void addEmitterToDirectSoundFilter(SoundFilter* filter, SoundEmitter* emitter); |
| 135 |
|
| 136 |
/** Removes given SoundEmitter from the specific direct SoundFilter. |
| 137 |
*/ |
| 138 |
void removeEmitterFromDirectSoundFilter(SoundFilter* filter, SoundEmitter* emitter); |
| 139 |
|
| 140 |
/** Internal function to do the OpenAL calls to activate the SoundFilter for the SoundEmitter. |
| 141 |
*/ |
| 142 |
void activateFilter(SoundFilter* filter, SoundEmitter* emitter); |
| 143 |
|
| 144 |
/** Internal function to do the OpenAL calls to deactivate the SoundFilter for the SoundEmitter. |
| 145 |
*/ |
| 146 |
void deactivateFilter(SoundFilter* filter, SoundEmitter* emitter); |
| 147 |
|
| 148 |
private: |
| 149 |
//! Inital the presets |
| 150 |
void createPresets(); |
| 151 |
//! OpenAL device |
| 152 |
ALCdevice* m_device; |
| 153 |
//! If sound effect module is active |
| 154 |
bool m_active; |
| 155 |
//! Holds handles for effects |
| 156 |
ALuint m_effectSlots[MAX_EFFECT_SLOTS]; |
| 157 |
//! Maximal created effect slots, can be different to MAX_EFFECT_SLOTS |
| 158 |
uint16_t m_createdSlots; |
| 159 |
//! Holds free handles for effect slots |
| 160 |
std::queue<ALuint> m_freeSlots; |
| 161 |
//! Maximal effect slots per Source |
| 162 |
ALint m_maxSlots; |
| 163 |
//! Holds all SoundEffects |
| 164 |
std::vector<SoundEffect*> m_effects; |
| 165 |
//! Holds SoundEffects together with the added SoundEmitters |
| 166 |
typedef std::map<SoundEffect*, std::vector<SoundEmitter*> > SoundEffectEmitterMap; |
| 167 |
SoundEffectEmitterMap m_effectEmitters; |
| 168 |
//! Holds all SoundFilters |
| 169 |
std::vector<SoundFilter*> m_filters; |
| 170 |
//! Holds SoundFilters together with the added SoundEmitters |
| 171 |
typedef std::map<SoundFilter*, std::vector<SoundEmitter*> > SoundFilterEmitterMap; |
| 172 |
SoundFilterEmitterMap m_filterdEmitters; |
| 173 |
//! Holds SoundFilters together with the added SoundEffects |
| 174 |
typedef std::map<SoundFilter*, std::vector<SoundEffect*> > SoundFilterEffectMap; |
| 175 |
SoundFilterEffectMap m_filterdEffects; |
| 176 |
//! Establishes the relationship between SoundEffectPreset and EFXEAXREVERBPROPERTIES |
| 177 |
std::map<SoundEffectPreset, EFXEAXREVERBPROPERTIES> m_presets; |
| 178 |
}; |
| 179 |
} |
| 180 |
#endif |