From 96b3d98ac330a29e34f4161f9c0e9d1daa05994e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 11 Mar 2023 15:03:18 -0800 Subject: 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. --- al/effects/chorus.cpp | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'al/effects/chorus.cpp') 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 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 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(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(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; } -- cgit v1.2.3