14 static inline T
clamp(const T
& val
, const T
& min
, const T
& max
)
15 { return std::min
<T
>(std::max
<T
>(val
, min
), max
); }
17 void ALEffect::setReverbProperties(const EFXEAXREVERBPROPERTIES
&props
)
19 CheckContext(mContext
);
21 if(mType
!= AL_EFFECT_EAXREVERB
&& mType
!= AL_EFFECT_REVERB
)
24 mContext
->alEffecti(mId
, AL_EFFECT_TYPE
, AL_EFFECT_EAXREVERB
);
25 if(alGetError() == AL_NO_ERROR
)
26 mType
= AL_EFFECT_EAXREVERB
;
29 mContext
->alEffecti(mId
, AL_EFFECT_TYPE
, AL_EFFECT_REVERB
);
30 if(alGetError() != AL_NO_ERROR
)
31 throw std::runtime_error("Failed to set reverb type");
32 mType
= AL_EFFECT_REVERB
;
36 if(mType
== AL_EFFECT_EAXREVERB
)
38 #define SETPARAM(e,t,v) mContext->alEffectf((e), AL_EAXREVERB_##t, clamp((v), AL_EAXREVERB_MIN_##t, AL_EAXREVERB_MAX_##t))
39 SETPARAM(mId
, DENSITY
, props
.flDensity
);
40 SETPARAM(mId
, DIFFUSION
, props
.flDiffusion
);
41 SETPARAM(mId
, GAIN
, props
.flGain
);
42 SETPARAM(mId
, GAINHF
, props
.flGainHF
);
43 SETPARAM(mId
, GAINLF
, props
.flGainLF
);
44 SETPARAM(mId
, DECAY_TIME
, props
.flDecayTime
);
45 SETPARAM(mId
, DECAY_HFRATIO
, props
.flDecayHFRatio
);
46 SETPARAM(mId
, DECAY_LFRATIO
, props
.flDecayLFRatio
);
47 SETPARAM(mId
, REFLECTIONS_GAIN
, props
.flReflectionsGain
);
48 SETPARAM(mId
, REFLECTIONS_DELAY
, props
.flReflectionsDelay
);
49 mContext
->alEffectfv(mId
, AL_EAXREVERB_REFLECTIONS_PAN
, props
.flReflectionsPan
);
50 SETPARAM(mId
, LATE_REVERB_GAIN
, props
.flLateReverbGain
);
51 SETPARAM(mId
, LATE_REVERB_DELAY
, props
.flLateReverbDelay
);
52 mContext
->alEffectfv(mId
, AL_EAXREVERB_LATE_REVERB_PAN
, props
.flLateReverbPan
);
53 SETPARAM(mId
, ECHO_TIME
, props
.flEchoTime
);
54 SETPARAM(mId
, ECHO_DEPTH
, props
.flEchoDepth
);
55 SETPARAM(mId
, MODULATION_TIME
, props
.flModulationTime
);
56 SETPARAM(mId
, MODULATION_DEPTH
, props
.flModulationDepth
);
57 SETPARAM(mId
, AIR_ABSORPTION_GAINHF
, props
.flAirAbsorptionGainHF
);
58 SETPARAM(mId
, HFREFERENCE
, props
.flHFReference
);
59 SETPARAM(mId
, LFREFERENCE
, props
.flLFReference
);
60 SETPARAM(mId
, ROOM_ROLLOFF_FACTOR
, props
.flRoomRolloffFactor
);
61 mContext
->alEffecti(mId
, AL_EAXREVERB_DECAY_HFLIMIT
, (props
.iDecayHFLimit
? AL_TRUE
: AL_FALSE
));
64 else if(mType
== AL_EFFECT_REVERB
)
66 #define SETPARAM(e,t,v) mContext->alEffectf((e), AL_REVERB_##t, clamp((v), AL_REVERB_MIN_##t, AL_REVERB_MAX_##t))
67 SETPARAM(mId
, DENSITY
, props
.flDensity
);
68 SETPARAM(mId
, DIFFUSION
, props
.flDiffusion
);
69 SETPARAM(mId
, GAIN
, props
.flGain
);
70 SETPARAM(mId
, GAINHF
, props
.flGainHF
);
71 SETPARAM(mId
, DECAY_TIME
, props
.flDecayTime
);
72 SETPARAM(mId
, DECAY_HFRATIO
, props
.flDecayHFRatio
);
73 SETPARAM(mId
, REFLECTIONS_GAIN
, props
.flReflectionsGain
);
74 SETPARAM(mId
, REFLECTIONS_DELAY
, props
.flReflectionsDelay
);
75 SETPARAM(mId
, LATE_REVERB_GAIN
, props
.flLateReverbGain
);
76 SETPARAM(mId
, LATE_REVERB_DELAY
, props
.flLateReverbDelay
);
77 SETPARAM(mId
, AIR_ABSORPTION_GAINHF
, props
.flAirAbsorptionGainHF
);
78 SETPARAM(mId
, ROOM_ROLLOFF_FACTOR
, props
.flRoomRolloffFactor
);
79 mContext
->alEffecti(mId
, AL_REVERB_DECAY_HFLIMIT
, (props
.iDecayHFLimit
? AL_TRUE
: AL_FALSE
));
84 void ALEffect::destroy()
86 CheckContext(mContext
);
89 mContext
->alDeleteEffects(1, &mId
);
90 if(alGetError() != AL_NO_ERROR
)
91 throw std::runtime_error("Effect failed to delete");
97 DECL_THUNK1(void, Effect
, setReverbProperties
,, const EFXEAXREVERBPROPERTIES
&)
98 void Effect::destroy()