From d78fe1ad99584fd29be3553613c443b204f7bf1f Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Wed, 23 Aug 2023 09:03:51 +0200 Subject: [PATCH] AP_HAL_SITL: fix possible divide by 0 on synth.hpp --- libraries/AP_HAL_SITL/Synth.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_SITL/Synth.hpp b/libraries/AP_HAL_SITL/Synth.hpp index d4a2374681..cc96cf9f44 100644 --- a/libraries/AP_HAL_SITL/Synth.hpp +++ b/libraries/AP_HAL_SITL/Synth.hpp @@ -7,6 +7,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include namespace Synth @@ -107,7 +108,7 @@ double amplitude(double dTime, sEnvelope env) else if (dTime > env.dAttackTime && dTime <= (env.dAttackTime + env.dDecayTime)) // Decay phase dAmplitude = ((dTime - env.dAttackTime) / env.dDecayTime) * (env.dSustainAmplitude - env.dStartAmplitude) + env.dStartAmplitude; - else if (dTime <= env.dAttackTime) // Attack phase + else if ((env.dAttackTime >= DBL_EPSILON) && dTime <= env.dAttackTime) // Attack phase dAmplitude = (dTime / env.dAttackTime) * env.dStartAmplitude; // Amplitude should not be negative, check just in case