From b8da646a0b4e7ef63f58b84c766815f15633da55 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 18 Nov 2015 22:20:38 -0800 Subject: [PATCH] Avoid resetting the effect type every time it's updated --- src/effect.cpp | 24 +++++++++++++++++------- src/effect.h | 3 ++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/effect.cpp b/src/effect.cpp index 18e2c09..755ce65 100644 --- a/src/effect.cpp +++ b/src/effect.cpp @@ -18,9 +18,22 @@ void ALEffect::setReverbProperties(const EFXEAXREVERBPROPERTIES &props) { CheckContext(mContext); - alGetError(); - mContext->alEffecti(mId, AL_EFFECT_TYPE, AL_EFFECT_EAXREVERB); - if(alGetError() == AL_NO_ERROR) + if(mType != AL_EFFECT_EAXREVERB && mType != AL_EFFECT_REVERB) + { + alGetError(); + mContext->alEffecti(mId, AL_EFFECT_TYPE, AL_EFFECT_EAXREVERB); + if(alGetError() == AL_NO_ERROR) + mType = AL_EFFECT_EAXREVERB; + else + { + mContext->alEffecti(mId, AL_EFFECT_TYPE, AL_EFFECT_REVERB); + if(alGetError() != AL_NO_ERROR) + throw std::runtime_error("Failed to set reverb type"); + mType = AL_EFFECT_REVERB; + } + } + + if(mType == AL_EFFECT_EAXREVERB) { #define SETPARAM(e,t,v) mContext->alEffectf((e), AL_EAXREVERB_##t, clamp((v), AL_EAXREVERB_MIN_##t, AL_EAXREVERB_MAX_##t)) SETPARAM(mId, DENSITY, props.flDensity); @@ -48,11 +61,8 @@ void ALEffect::setReverbProperties(const EFXEAXREVERBPROPERTIES &props) mContext->alEffecti(mId, AL_EAXREVERB_DECAY_HFLIMIT, (props.iDecayHFLimit ? AL_TRUE : AL_FALSE)); #undef SETPARAM } - else + else if(mType == AL_EFFECT_REVERB) { - mContext->alEffecti(mId, AL_EFFECT_TYPE, AL_EFFECT_REVERB); - if(alGetError() != AL_NO_ERROR) - throw std::runtime_error("Failed to set reverb type"); #define SETPARAM(e,t,v) mContext->alEffectf((e), AL_REVERB_##t, clamp((v), AL_REVERB_MIN_##t, AL_REVERB_MAX_##t)) SETPARAM(mId, DENSITY, props.flDensity); SETPARAM(mId, DIFFUSION, props.flDiffusion); diff --git a/src/effect.h b/src/effect.h index 81566e7..b76af81 100644 --- a/src/effect.h +++ b/src/effect.h @@ -10,9 +10,10 @@ class ALContext; class ALEffect : public Effect { ALContext *const mContext; ALuint mId; + ALenum mType; public: - ALEffect(ALContext *context, ALuint id) : mContext(context), mId(id) + ALEffect(ALContext *context, ALuint id) : mContext(context), mId(id), mType(AL_NONE) { } virtual ~ALEffect() { } -- 2.11.4.GIT