aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-03-11 15:03:18 -0800
committerChris Robinson <[email protected]>2023-03-11 15:03:18 -0800
commit96b3d98ac330a29e34f4161f9c0e9d1daa05994e (patch)
treeb549913189b58344bfa9fa04b53ef0f9fc15e9eb
parent0bda22af1065e3cc251346d720f6f61c7dca17bd (diff)
Simplify committing EAX effect properties
There's no need to explicitly clamp to EFX limits when they're the same as or more lenient than EAX, which were already validated when set, or when it's within tolerance of the effect implementation. Also it's generally better to check once all properties for changes and apply them all if one is different, rather than checking and setting each member individually.
-rw-r--r--al/effects/autowah.cpp50
-rw-r--r--al/effects/chorus.cpp41
-rw-r--r--al/effects/distortion.cpp61
-rw-r--r--al/effects/echo.cpp61
-rw-r--r--al/effects/equalizer.cpp107
5 files changed, 78 insertions, 242 deletions
diff --git a/al/effects/autowah.cpp b/al/effects/autowah.cpp
index 532d7276..7434b62c 100644
--- a/al/effects/autowah.cpp
+++ b/al/effects/autowah.cpp
@@ -195,44 +195,18 @@ bool AutowahCommitter::commit(const EaxEffectProps &props)
const auto orig = props_;
props_ = props;
- auto is_dirty = bool{orig.mType != props_.mType};
- if(props_.mAutowah.flAttackTime != props.mAutowah.flAttackTime)
- {
- is_dirty = true;
- al_effect_props_.Autowah.AttackTime = clamp(
- props_.mAutowah.flAttackTime,
- AL_AUTOWAH_MIN_ATTACK_TIME,
- AL_AUTOWAH_MAX_ATTACK_TIME);
- }
-
- if(props_.mAutowah.flReleaseTime != props.mAutowah.flReleaseTime)
- {
- is_dirty = true;
- al_effect_props_.Autowah.ReleaseTime = clamp(
- props_.mAutowah.flReleaseTime,
- AL_AUTOWAH_MIN_RELEASE_TIME,
- AL_AUTOWAH_MAX_RELEASE_TIME);
- }
-
- if(props_.mAutowah.lResonance != props.mAutowah.lResonance)
- {
- is_dirty = true;
- al_effect_props_.Autowah.Resonance = clamp(
- level_mb_to_gain(static_cast<float>(props_.mAutowah.lResonance)),
- AL_AUTOWAH_MIN_RESONANCE,
- AL_AUTOWAH_MAX_RESONANCE);
- }
-
- if(props_.mAutowah.lPeakLevel != props.mAutowah.lPeakLevel)
- {
- is_dirty = true;
- al_effect_props_.Autowah.PeakGain = clamp(
- level_mb_to_gain(static_cast<float>(props_.mAutowah.lPeakLevel)),
- AL_AUTOWAH_MIN_PEAK_GAIN,
- AL_AUTOWAH_MAX_PEAK_GAIN);
- }
-
- return is_dirty;
+ if(orig.mType == props_.mType && props_.mAutowah.flAttackTime == props.mAutowah.flAttackTime
+ && props_.mAutowah.flReleaseTime == props.mAutowah.flReleaseTime
+ && props_.mAutowah.lResonance == props.mAutowah.lResonance
+ && props_.mAutowah.lPeakLevel == props.mAutowah.lPeakLevel)
+ return false;
+
+ al_effect_props_.Autowah.AttackTime = props_.mAutowah.flAttackTime;
+ al_effect_props_.Autowah.ReleaseTime = props_.mAutowah.flReleaseTime;
+ al_effect_props_.Autowah.Resonance = level_mb_to_gain(static_cast<float>(props_.mAutowah.lResonance));
+ al_effect_props_.Autowah.PeakGain = level_mb_to_gain(static_cast<float>(props_.mAutowah.lPeakLevel));
+
+ return true;
}
template<>
diff --git a/al/effects/chorus.cpp b/al/effects/chorus.cpp
index a9088157..a6845ee8 100644
--- a/al/effects/chorus.cpp
+++ b/al/effects/chorus.cpp
@@ -350,14 +350,11 @@ struct EaxChorusTraits {
static constexpr auto efx_default_feedback() { return AL_CHORUS_DEFAULT_FEEDBACK; }
static constexpr auto efx_default_delay() { return AL_CHORUS_DEFAULT_DELAY; }
- static al::optional<ChorusWaveform> eax_waveform(unsigned long type)
+ static ChorusWaveform eax_waveform(unsigned long type)
{
- switch(type)
- {
- case EAX_CHORUS_SINUSOID: return ChorusWaveform::Sinusoid;
- case EAX_CHORUS_TRIANGLE: return ChorusWaveform::Triangle;
- }
- return al::nullopt;
+ if(type == EAX_CHORUS_SINUSOID) return ChorusWaveform::Sinusoid;
+ if(type == EAX_CHORUS_TRIANGLE) return ChorusWaveform::Triangle;
+ return ChorusWaveform::Sinusoid;
}
}; // EaxChorusTraits
@@ -420,14 +417,11 @@ struct EaxFlangerTraits {
static constexpr auto efx_default_feedback() { return AL_FLANGER_DEFAULT_FEEDBACK; }
static constexpr auto efx_default_delay() { return AL_FLANGER_DEFAULT_DELAY; }
- static al::optional<ChorusWaveform> eax_waveform(unsigned long type)
+ static ChorusWaveform eax_waveform(unsigned long type)
{
- switch(type)
- {
- case EAX_FLANGER_SINUSOID: return ChorusWaveform::Sinusoid;
- case EAX_FLANGER_TRIANGLE: return ChorusWaveform::Triangle;
- }
- return al::nullopt;
+ if(type == EAX_FLANGER_SINUSOID) return ChorusWaveform::Sinusoid;
+ if(type == EAX_FLANGER_TRIANGLE) return ChorusWaveform::Triangle;
+ return ChorusWaveform::Sinusoid;
}
}; // EaxFlangerTraits
@@ -626,19 +620,12 @@ public:
&& dst.flFeedback == src.flFeedback && dst.flDelay == src.flDelay)
return false;
- const auto efx_waveform = Traits::eax_waveform(dst.ulWaveform);
- assert(efx_waveform.has_value());
- al_effect_props_.Chorus.Waveform = *efx_waveform;
- al_effect_props_.Chorus.Phase = clamp(static_cast<ALint>(dst.lPhase),
- Traits::efx_min_phase(), Traits::efx_max_phase());
- al_effect_props_.Chorus.Rate = clamp(dst.flRate,
- Traits::efx_min_rate(), Traits::efx_max_rate());
- al_effect_props_.Chorus.Depth = clamp(dst.flDepth,
- Traits::efx_min_depth(), Traits::efx_max_depth());
- al_effect_props_.Chorus.Feedback = clamp(dst.flFeedback,
- Traits::efx_min_feedback(), Traits::efx_max_feedback());
- al_effect_props_.Chorus.Delay = clamp(dst.flDelay,
- Traits::efx_min_delay(), Traits::efx_max_delay());
+ al_effect_props_.Chorus.Waveform = Traits::eax_waveform(dst.ulWaveform);
+ al_effect_props_.Chorus.Phase = static_cast<ALint>(dst.lPhase);
+ al_effect_props_.Chorus.Rate = dst.flRate;
+ al_effect_props_.Chorus.Depth = dst.flDepth;
+ al_effect_props_.Chorus.Feedback = dst.flFeedback;
+ al_effect_props_.Chorus.Delay = dst.flDelay;
return true;
}
diff --git a/al/effects/distortion.cpp b/al/effects/distortion.cpp
index f91314de..a0f4d924 100644
--- a/al/effects/distortion.cpp
+++ b/al/effects/distortion.cpp
@@ -210,53 +210,20 @@ bool DistortionCommitter::commit(const EaxEffectProps &props)
const auto orig = props_;
props_ = props;
- auto is_dirty = bool{orig.mType != props_.mType};
- if(props_.mDistortion.flEdge != props.mDistortion.flEdge)
- {
- is_dirty = true;
- al_effect_props_.Distortion.Edge = clamp(
- props_.mDistortion.flEdge,
- AL_DISTORTION_MIN_EDGE,
- AL_DISTORTION_MAX_EDGE);
- }
-
- if(props_.mDistortion.lGain != props.mDistortion.lGain)
- {
- is_dirty = true;
- al_effect_props_.Distortion.Gain = clamp(
- level_mb_to_gain(static_cast<float>(props_.mDistortion.lGain)),
- AL_DISTORTION_MIN_GAIN,
- AL_DISTORTION_MAX_GAIN);
- }
-
- if(props_.mDistortion.flLowPassCutOff != props.mDistortion.flLowPassCutOff)
- {
- is_dirty = true;
- al_effect_props_.Distortion.LowpassCutoff = clamp(
- props_.mDistortion.flLowPassCutOff,
- AL_DISTORTION_MIN_LOWPASS_CUTOFF,
- AL_DISTORTION_MAX_LOWPASS_CUTOFF);
- }
-
- if(props_.mDistortion.flEQCenter != props.mDistortion.flEQCenter)
- {
- is_dirty = true;
- al_effect_props_.Distortion.EQCenter = clamp(
- props_.mDistortion.flEQCenter,
- AL_DISTORTION_MIN_EQCENTER,
- AL_DISTORTION_MAX_EQCENTER);
- }
-
- if(props_.mDistortion.flEQBandwidth != props.mDistortion.flEQBandwidth)
- {
- is_dirty = true;
- al_effect_props_.Distortion.EQBandwidth = clamp(
- props_.mDistortion.flEdge,
- AL_DISTORTION_MIN_EQBANDWIDTH,
- AL_DISTORTION_MAX_EQBANDWIDTH);
- }
-
- return is_dirty;
+ if(orig.mType == props_.mType && props_.mDistortion.flEdge == props.mDistortion.flEdge
+ && props_.mDistortion.lGain == props.mDistortion.lGain
+ && props_.mDistortion.flLowPassCutOff == props.mDistortion.flLowPassCutOff
+ && props_.mDistortion.flEQCenter == props.mDistortion.flEQCenter
+ && props_.mDistortion.flEQBandwidth == props.mDistortion.flEQBandwidth)
+ return false;
+
+ al_effect_props_.Distortion.Edge = props_.mDistortion.flEdge;
+ al_effect_props_.Distortion.Gain = level_mb_to_gain(static_cast<float>(props_.mDistortion.lGain));
+ al_effect_props_.Distortion.LowpassCutoff = props_.mDistortion.flLowPassCutOff;
+ al_effect_props_.Distortion.EQCenter = props_.mDistortion.flEQCenter;
+ al_effect_props_.Distortion.EQBandwidth = props_.mDistortion.flEdge;
+
+ return true;
}
template<>
diff --git a/al/effects/echo.cpp b/al/effects/echo.cpp
index 98fa5541..3a83b24f 100644
--- a/al/effects/echo.cpp
+++ b/al/effects/echo.cpp
@@ -207,53 +207,20 @@ bool EchoCommitter::commit(const EaxEffectProps &props)
const auto orig = props_;
props_ = props;
- auto is_dirty = bool{orig.mType != props_.mType};
- if(props_.mEcho.flDelay != props.mEcho.flDelay)
- {
- is_dirty = true;
- al_effect_props_.Echo.Delay = clamp(
- props_.mEcho.flDelay,
- AL_ECHO_MIN_DELAY,
- AL_ECHO_MAX_DELAY);
- }
-
- if(props_.mEcho.flLRDelay != props.mEcho.flLRDelay)
- {
- is_dirty = true;
- al_effect_props_.Echo.LRDelay = clamp(
- props_.mEcho.flLRDelay,
- AL_ECHO_MIN_LRDELAY,
- AL_ECHO_MAX_LRDELAY);
- }
-
- if(props_.mEcho.flDamping != props.mEcho.flDamping)
- {
- is_dirty = true;
- al_effect_props_.Echo.Damping = clamp(
- props_.mEcho.flDamping,
- AL_ECHO_MIN_DAMPING,
- AL_ECHO_MAX_DAMPING);
- }
-
- if(props_.mEcho.flFeedback != props.mEcho.flFeedback)
- {
- is_dirty = true;
- al_effect_props_.Echo.Feedback = clamp(
- props_.mEcho.flFeedback,
- AL_ECHO_MIN_FEEDBACK,
- AL_ECHO_MAX_FEEDBACK);
- }
-
- if(props_.mEcho.flSpread != props.mEcho.flSpread)
- {
- is_dirty = true;
- al_effect_props_.Echo.Spread = clamp(
- props_.mEcho.flSpread,
- AL_ECHO_MIN_SPREAD,
- AL_ECHO_MAX_SPREAD);
- }
-
- return is_dirty;
+ if(orig.mType == props_.mType && props_.mEcho.flDelay == props.mEcho.flDelay
+ && props_.mEcho.flLRDelay == props.mEcho.flLRDelay
+ && props_.mEcho.flDamping == props.mEcho.flDamping
+ && props_.mEcho.flFeedback == props.mEcho.flFeedback
+ && props_.mEcho.flSpread == props.mEcho.flSpread)
+ return false;
+
+ al_effect_props_.Echo.Delay = props_.mEcho.flDelay;
+ al_effect_props_.Echo.LRDelay = props_.mEcho.flLRDelay;
+ al_effect_props_.Echo.Damping = props_.mEcho.flDamping;
+ al_effect_props_.Echo.Feedback = props_.mEcho.flFeedback;
+ al_effect_props_.Echo.Spread = props_.mEcho.flSpread;
+
+ return true;
}
template<>
diff --git a/al/effects/equalizer.cpp b/al/effects/equalizer.cpp
index d9d52e1a..2ef048f9 100644
--- a/al/effects/equalizer.cpp
+++ b/al/effects/equalizer.cpp
@@ -325,89 +325,30 @@ bool EqualizerCommitter::commit(const EaxEffectProps &props)
const auto orig = props_;
props_ = props;
- auto is_dirty = bool{orig.mType != props_.mType};
- if(props_.mEqualizer.lLowGain != props.mEqualizer.lLowGain)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.LowGain = clamp(
- level_mb_to_gain(static_cast<float>(props_.mEqualizer.lLowGain)),
- AL_EQUALIZER_MIN_LOW_GAIN,
- AL_EQUALIZER_MAX_LOW_GAIN);
- }
- if(props_.mEqualizer.flLowCutOff != props.mEqualizer.flLowCutOff)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.LowCutoff = clamp(
- props_.mEqualizer.flLowCutOff,
- AL_EQUALIZER_MIN_LOW_CUTOFF,
- AL_EQUALIZER_MAX_LOW_CUTOFF);
- }
- if(props_.mEqualizer.lMid1Gain != props.mEqualizer.lMid1Gain)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.Mid1Gain = clamp(
- level_mb_to_gain(static_cast<float>(props_.mEqualizer.lMid1Gain)),
- AL_EQUALIZER_MIN_MID1_GAIN,
- AL_EQUALIZER_MAX_MID1_GAIN);
- }
- if(props_.mEqualizer.flMid1Center != props.mEqualizer.flMid1Center)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.Mid1Center = clamp(
- props_.mEqualizer.flMid1Center,
- AL_EQUALIZER_MIN_MID1_CENTER,
- AL_EQUALIZER_MAX_MID1_CENTER);
- }
- if(props_.mEqualizer.flMid1Width != props.mEqualizer.flMid1Width)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.Mid1Width = clamp(
- props_.mEqualizer.flMid1Width,
- AL_EQUALIZER_MIN_MID1_WIDTH,
- AL_EQUALIZER_MAX_MID1_WIDTH);
- }
- if(props_.mEqualizer.lMid2Gain != props.mEqualizer.lMid2Gain)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.Mid2Gain = clamp(
- level_mb_to_gain(static_cast<float>(props_.mEqualizer.lMid2Gain)),
- AL_EQUALIZER_MIN_MID2_GAIN,
- AL_EQUALIZER_MAX_MID2_GAIN);
- }
- if(props_.mEqualizer.flMid2Center != props.mEqualizer.flMid2Center)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.Mid2Center = clamp(
- props_.mEqualizer.flMid2Center,
- AL_EQUALIZER_MIN_MID2_CENTER,
- AL_EQUALIZER_MAX_MID2_CENTER);
- }
- if(props_.mEqualizer.flMid2Width != props.mEqualizer.flMid2Width)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.Mid2Width = clamp(
- props_.mEqualizer.flMid2Width,
- AL_EQUALIZER_MIN_MID2_WIDTH,
- AL_EQUALIZER_MAX_MID2_WIDTH);
- }
- if(props_.mEqualizer.lHighGain != props.mEqualizer.lHighGain)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.HighGain = clamp(
- level_mb_to_gain(static_cast<float>(props_.mEqualizer.lHighGain)),
- AL_EQUALIZER_MIN_HIGH_GAIN,
- AL_EQUALIZER_MAX_HIGH_GAIN);
- }
- if(props_.mEqualizer.flHighCutOff != props.mEqualizer.flHighCutOff)
- {
- is_dirty = true;
- al_effect_props_.Equalizer.HighCutoff = clamp(
- props_.mEqualizer.flHighCutOff,
- AL_EQUALIZER_MIN_HIGH_CUTOFF,
- AL_EQUALIZER_MAX_HIGH_CUTOFF);
- }
-
- return is_dirty;
+ if(orig.mType == props_.mType && props_.mEqualizer.lLowGain == props.mEqualizer.lLowGain
+ && props_.mEqualizer.flLowCutOff == props.mEqualizer.flLowCutOff
+ && props_.mEqualizer.lMid1Gain == props.mEqualizer.lMid1Gain
+ && props_.mEqualizer.flMid1Center == props.mEqualizer.flMid1Center
+ && props_.mEqualizer.flMid1Width == props.mEqualizer.flMid1Width
+ && props_.mEqualizer.lMid2Gain == props.mEqualizer.lMid2Gain
+ && props_.mEqualizer.flMid2Center == props.mEqualizer.flMid2Center
+ && props_.mEqualizer.flMid2Width == props.mEqualizer.flMid2Width
+ && props_.mEqualizer.lHighGain == props.mEqualizer.lHighGain
+ && props_.mEqualizer.flHighCutOff == props.mEqualizer.flHighCutOff)
+ return false;
+
+ al_effect_props_.Equalizer.LowGain = level_mb_to_gain(static_cast<float>(props_.mEqualizer.lLowGain));
+ al_effect_props_.Equalizer.LowCutoff = props_.mEqualizer.flLowCutOff;
+ al_effect_props_.Equalizer.Mid1Gain = level_mb_to_gain(static_cast<float>(props_.mEqualizer.lMid1Gain));
+ al_effect_props_.Equalizer.Mid1Center = props_.mEqualizer.flMid1Center;
+ al_effect_props_.Equalizer.Mid1Width = props_.mEqualizer.flMid1Width;
+ al_effect_props_.Equalizer.Mid2Gain = level_mb_to_gain(static_cast<float>(props_.mEqualizer.lMid2Gain));
+ al_effect_props_.Equalizer.Mid2Center = props_.mEqualizer.flMid2Center;
+ al_effect_props_.Equalizer.Mid2Width = props_.mEqualizer.flMid2Width;
+ al_effect_props_.Equalizer.HighGain = level_mb_to_gain(static_cast<float>(props_.mEqualizer.lHighGain));
+ al_effect_props_.Equalizer.HighCutoff = props_.mEqualizer.flHighCutOff;
+
+ return true;
}
template<>