diff options
author | Chris Robinson <[email protected]> | 2023-03-11 15:03:18 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-03-11 15:03:18 -0800 |
commit | 96b3d98ac330a29e34f4161f9c0e9d1daa05994e (patch) | |
tree | b549913189b58344bfa9fa04b53ef0f9fc15e9eb /al/effects/chorus.cpp | |
parent | 0bda22af1065e3cc251346d720f6f61c7dca17bd (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.
Diffstat (limited to 'al/effects/chorus.cpp')
-rw-r--r-- | al/effects/chorus.cpp | 41 |
1 files changed, 14 insertions, 27 deletions
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; } |