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
This commit is contained in:
itsmattkc
2023-02-21 23:04:31 -08:00
parent 764d9ada36
commit 52021a8694
2 changed files with 18 additions and 2 deletions
+17 -2
View File
@@ -24,14 +24,25 @@
#include <QtGlobal>
#include <cmath>
//#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<double>::infinity();
#else
return MINIMUM;
#endif
else if (logarithmic > 0.99)
return 0;
else