Skip to content

Commit

Permalink
curveview/decibel: return -200 rather than infinity
Browse files Browse the repository at this point in the history
While technically less correct, it's mathematically essentially the same and saves a lot of programming headaches.

Fixes olive-editor#2133
  • Loading branch information
itsmattkc committed Feb 22, 2023
1 parent 764d9ad commit 52021a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/common/decibel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -49,7 +60,11 @@ class Decibel
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
Expand Down
1 change: 1 addition & 0 deletions app/widget/curvewidget/curveview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QScrollBar>
#include <QtMath>

#include "common/decibel.h"
#include "common/qtutils.h"
#include "node/nodeundo.h"
#include "widget/keyframeview/keyframeviewundo.h"
Expand Down

0 comments on commit 52021a8

Please sign in to comment.