1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdopenal.h"
19 #include "effect_al.h"
20 #include "sound_driver_al.h"
27 // using namespace NLMISC;
31 // ******************************************************************
33 CEffectAL::CEffectAL(CSoundDriverAL
*soundDriver
, ALuint alEffect
, ALuint alAuxEffectSlot
) : _SoundDriver(soundDriver
), _AlEffect(alEffect
), _AlAuxEffectSlot(alAuxEffectSlot
)
38 CEffectAL::~CEffectAL()
40 CSoundDriverAL
*soundDriver
= _SoundDriver
;
42 if (soundDriver
) soundDriver
->removeEffect(this);
45 void CEffectAL::release()
47 if (_AlAuxEffectSlot
!= AL_EFFECTSLOT_NULL
) { alDeleteAuxiliaryEffectSlots(1, &_AlAuxEffectSlot
); _AlAuxEffectSlot
= AL_EFFECTSLOT_NULL
; }
48 if (_AlEffect
!= AL_EFFECT_NULL
) { alDeleteEffects(1, &_AlEffect
); _AlEffect
= AL_EFFECT_NULL
; }
52 // ******************************************************************
54 CStandardReverbEffectAL::CStandardReverbEffectAL(CSoundDriverAL
*soundDriver
, ALuint alEffect
, ALuint alAuxEffectSlot
) : CEffectAL(soundDriver
, alEffect
, alAuxEffectSlot
)
56 // unused params, set default values
57 alEffectf(_AlEffect
, AL_REVERB_AIR_ABSORPTION_GAINHF
, 0.994f
);
58 alEffectf(_AlEffect
, AL_REVERB_ROOM_ROLLOFF_FACTOR
, 0.0f
);
59 alEffectf(_AlEffect
, AL_REVERB_DECAY_HFLIMIT
, AL_TRUE
);
61 // set default environment
65 CStandardReverbEffectAL::~CStandardReverbEffectAL()
70 void CStandardReverbEffectAL::setEnvironment(const CEnvironment
&environment
, float roomSize
)
72 nldebug("AL: CStandardReverbEffectAL::setEnvironment, size: %f", roomSize
);
74 // *** TODO *** environment.RoomSize
75 alEffectf(_AlEffect
, AL_REVERB_DENSITY
, environment
.Density
/ 100.0f
); alTestWarning("AL_REVERB_DENSITY");
76 alEffectf(_AlEffect
, AL_REVERB_DIFFUSION
, environment
.Diffusion
/ 100.0f
); alTestWarning("AL_REVERB_DIFFUSION");
77 alEffectf(_AlEffect
, AL_REVERB_GAIN
, decibelsToAmplitudeRatio(environment
.RoomFilter
)); alTestWarning("AL_REVERB_GAIN");
78 alEffectf(_AlEffect
, AL_REVERB_GAINHF
, decibelsToAmplitudeRatio(environment
.RoomFilterHF
)); alTestWarning("AL_REVERB_GAINHF");
79 alEffectf(_AlEffect
, AL_REVERB_DECAY_TIME
, environment
.DecayTime
); alTestWarning("AL_REVERB_DECAY_TIME");
80 alEffectf(_AlEffect
, AL_REVERB_DECAY_HFRATIO
, environment
.DecayHFRatio
); alTestWarning("AL_REVERB_DECAY_HFRATIO");
81 alEffectf(_AlEffect
, AL_REVERB_REFLECTIONS_GAIN
, decibelsToAmplitudeRatio(environment
.Reflections
)); alTestWarning("AL_REVERB_REFLECTIONS_GAIN");
82 alEffectf(_AlEffect
, AL_REVERB_REFLECTIONS_DELAY
, environment
.ReflectionsDelay
); alTestWarning("AL_REVERB_REFLECTIONS_DELAY");
83 alEffectf(_AlEffect
, AL_REVERB_LATE_REVERB_GAIN
, decibelsToAmplitudeRatio(environment
.LateReverb
)); alTestWarning("AL_REVERB_LATE_REVERB_GAIN");
84 alEffectf(_AlEffect
, AL_REVERB_LATE_REVERB_DELAY
, environment
.LateReverbDelay
); alTestWarning("AL_REVERB_LATE_REVERB_DELAY");
87 // ******************************************************************
89 #if EFX_CREATIVE_AVAILABLE
91 CCreativeReverbEffectAL::CCreativeReverbEffectAL(CSoundDriverAL
*soundDriver
, ALuint alEffect
, ALuint alAuxEffectSlot
) : CEffectAL(soundDriver
, alEffect
, alAuxEffectSlot
)
93 // set default environment
97 CCreativeReverbEffectAL::~CCreativeReverbEffectAL()
102 void CCreativeReverbEffectAL::setEnvironment(const CEnvironment
&environment
, float roomSize
)
104 nldebug("AL: CCreativeReverbEffectAL::setEnvironment, size: %f", roomSize
);
106 EAXREVERBPROPERTIES eaxreverb
;
107 eaxreverb
.ulEnvironment
= 26;
108 eaxreverb
.flEnvironmentSize
= roomSize
;
109 eaxreverb
.flEnvironmentDiffusion
= environment
.Diffusion
/ 100.0f
;
110 eaxreverb
.lRoom
= (long)(environment
.RoomFilter
* 100.0f
);
111 eaxreverb
.lRoomHF
= (long)(environment
.RoomFilterHF
* 100.0f
);
112 eaxreverb
.lRoomLF
= 0;
113 eaxreverb
.flDecayTime
= environment
.DecayTime
;
114 eaxreverb
.flDecayHFRatio
= environment
.DecayHFRatio
;
115 eaxreverb
.flDecayLFRatio
= 1.0f
;
116 eaxreverb
.lReflections
= (long)(environment
.Reflections
* 100.0f
);
117 eaxreverb
.flReflectionsDelay
= environment
.ReflectionsDelay
;
118 eaxreverb
.vReflectionsPan
.x
= 0.0f
;
119 eaxreverb
.vReflectionsPan
.y
= 0.0f
;
120 eaxreverb
.vReflectionsPan
.z
= 0.0f
;
121 eaxreverb
.lReverb
= (long)(environment
.LateReverb
* 100.0f
);
122 eaxreverb
.flReverbDelay
= environment
.LateReverbDelay
;
123 eaxreverb
.vReverbPan
.x
= 0.0f
;
124 eaxreverb
.vReverbPan
.y
= 0.0f
;
125 eaxreverb
.vReverbPan
.z
= 0.0f
;
126 eaxreverb
.flEchoTime
= 0.250f
;
127 eaxreverb
.flEchoDepth
= 0.000f
;
128 eaxreverb
.flModulationTime
= 0.250f
;
129 eaxreverb
.flModulationDepth
= 0.000f
;
130 eaxreverb
.flAirAbsorptionHF
= -5.0f
;
131 eaxreverb
.flHFReference
= 5000.0f
;
132 eaxreverb
.flLFReference
= 250.0f
;
133 eaxreverb
.flRoomRolloffFactor
= 0.0f
;
134 eaxreverb
.ulFlags
= 0x3f;
135 EFXEAXREVERBPROPERTIES efxcreativereverb
;
136 ConvertReverbParameters(&eaxreverb
, &efxcreativereverb
);
137 efxcreativereverb
.flDensity
= environment
.Density
/ 100.0f
;
138 alEffectf(_AlEffect
, AL_EAXREVERB_DENSITY
, efxcreativereverb
.flDensity
); alTestWarning("AL_EAXREVERB_DENSITY");
139 alEffectf(_AlEffect
, AL_EAXREVERB_DIFFUSION
, efxcreativereverb
.flDiffusion
); alTestWarning("AL_EAXREVERB_DIFFUSION");
140 alEffectf(_AlEffect
, AL_EAXREVERB_GAIN
, efxcreativereverb
.flGain
); alTestWarning("AL_EAXREVERB_GAIN");
141 alEffectf(_AlEffect
, AL_EAXREVERB_GAINHF
, efxcreativereverb
.flGainHF
); alTestWarning("AL_EAXREVERB_GAINHF");
142 alEffectf(_AlEffect
, AL_EAXREVERB_GAINLF
, efxcreativereverb
.flGainLF
); alTestWarning("AL_EAXREVERB_GAINLF");
143 alEffectf(_AlEffect
, AL_EAXREVERB_DECAY_TIME
, efxcreativereverb
.flDecayTime
); alTestWarning("AL_EAXREVERB_DECAY_TIME");
144 alEffectf(_AlEffect
, AL_EAXREVERB_DECAY_HFRATIO
, efxcreativereverb
.flDecayHFRatio
); alTestWarning("AL_EAXREVERB_DECAY_HFRATIO");
145 alEffectf(_AlEffect
, AL_EAXREVERB_DECAY_LFRATIO
, efxcreativereverb
.flDecayLFRatio
); alTestWarning("AL_EAXREVERB_DECAY_LFRATIO");
146 alEffectf(_AlEffect
, AL_EAXREVERB_REFLECTIONS_GAIN
, efxcreativereverb
.flReflectionsGain
); alTestWarning("AL_EAXREVERB_REFLECTIONS_GAIN");
147 alEffectf(_AlEffect
, AL_EAXREVERB_REFLECTIONS_DELAY
, efxcreativereverb
.flReflectionsDelay
); alTestWarning("AL_EAXREVERB_REFLECTIONS_DELAY");
148 alEffectfv(_AlEffect
, AL_EAXREVERB_REFLECTIONS_PAN
, efxcreativereverb
.flReflectionsPan
); alTestWarning("AL_EAXREVERB_REFLECTIONS_PAN");
149 alEffectf(_AlEffect
, AL_EAXREVERB_LATE_REVERB_GAIN
, efxcreativereverb
.flLateReverbGain
); alTestWarning("AL_EAXREVERB_LATE_REVERB_GAIN");
150 alEffectf(_AlEffect
, AL_EAXREVERB_LATE_REVERB_DELAY
, efxcreativereverb
.flLateReverbDelay
); alTestWarning("AL_EAXREVERB_LATE_REVERB_DELAY");
151 alEffectfv(_AlEffect
, AL_EAXREVERB_LATE_REVERB_PAN
, efxcreativereverb
.flLateReverbPan
); alTestWarning("AL_EAXREVERB_LATE_REVERB_PAN");
152 alEffectf(_AlEffect
, AL_EAXREVERB_ECHO_TIME
, efxcreativereverb
.flEchoTime
); alTestWarning("AL_EAXREVERB_ECHO_TIME");
153 alEffectf(_AlEffect
, AL_EAXREVERB_ECHO_DEPTH
, efxcreativereverb
.flEchoDepth
); alTestWarning("AL_EAXREVERB_ECHO_DEPTH");
154 alEffectf(_AlEffect
, AL_EAXREVERB_MODULATION_TIME
, efxcreativereverb
.flModulationTime
); alTestWarning("AL_EAXREVERB_MODULATION_TIME");
155 alEffectf(_AlEffect
, AL_EAXREVERB_MODULATION_DEPTH
, efxcreativereverb
.flModulationDepth
); alTestWarning("AL_EAXREVERB_MODULATION_DEPTH");
156 alEffectf(_AlEffect
, AL_EAXREVERB_AIR_ABSORPTION_GAINHF
, efxcreativereverb
.flAirAbsorptionGainHF
); alTestWarning("AL_EAXREVERB_AIR_ABSORPTION_GAINHF");
157 alEffectf(_AlEffect
, AL_EAXREVERB_HFREFERENCE
, efxcreativereverb
.flHFReference
); alTestWarning("AL_EAXREVERB_HFREFERENCE");
158 alEffectf(_AlEffect
, AL_EAXREVERB_LFREFERENCE
, efxcreativereverb
.flLFReference
); alTestWarning("AL_EAXREVERB_LFREFERENCE");
159 alEffectf(_AlEffect
, AL_EAXREVERB_ROOM_ROLLOFF_FACTOR
, efxcreativereverb
.flRoomRolloffFactor
); alTestWarning("AL_EAXREVERB_ROOM_ROLLOFF_FACTOR");
160 alEffecti(_AlEffect
, AL_EAXREVERB_DECAY_HFLIMIT
, efxcreativereverb
.iDecayHFLimit
); alTestWarning("AL_EAXREVERB_DECAY_HFLIMIT"); // note: spec says AL_EAXREVERB_DECAYHF_LIMIT
163 #endif /* #if EFX_CREATIVE_AVAILABLE */
165 // ******************************************************************
167 } /* namespace NLSOUND */