From 52021a8694445655e62ab925168d8d7f47b84817 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue, 21 Feb 2023 23:04:31 -0800 Subject: [PATCH] curveview/decibel: return -200 rather than infinity While technically less correct, it's mathematically essentially the same and saves a lot of programming headaches. Fixes #2133 --- app/common/decibel.h | 19 +++++++++++++++++-- app/widget/curvewidget/curveview.cpp | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/common/decibel.h b/app/common/decibel.h index 40a88135b..569b0a969 100644 --- a/app/common/decibel.h +++ b/app/common/decibel.h @@ -24,14 +24,25 @@ #include #include +//#define ALLOW_RETURNING_INFINITY + namespace olive { class Decibel { public: + // In basically all circumstances, this should calculate to 0.0 linear + static constexpr double MINIMUM = -200.0; + static double fromLinear(double linear) { - return double(20.0) * std::log10(linear); + double v = double(20.0) * std::log10(linear); +#ifndef ALLOW_RETURNING_INFINITY + if (std::isinf(v)) { + return MINIMUM; + } +#endif + return v; } static double toLinear(double decibel) @@ -49,7 +60,11 @@ public: static double fromLogarithmic(double logarithmic) { if (logarithmic < 0.001) - return -200.0; +#ifdef ALLOW_RETURNING_INFINITY + return std::numeric_limits::infinity(); +#else + return MINIMUM; +#endif else if (logarithmic > 0.99) return 0; else diff --git a/app/widget/curvewidget/curveview.cpp b/app/widget/curvewidget/curveview.cpp index df51b25b3..81d00bf2e 100644 --- a/app/widget/curvewidget/curveview.cpp +++ b/app/widget/curvewidget/curveview.cpp @@ -27,6 +27,7 @@ #include #include +#include "common/decibel.h" #include "common/qtutils.h" #include "node/nodeundo.h" #include "widget/keyframeview/keyframeviewundo.h"