summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-09-25 20:06:42 +0200
committerJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-09-25 20:06:42 +0200
commitf42c089299198476ecd0b7f433aa7a109a6a7353 (patch)
tree200a7985c6daf4b443845d076c7eb2962b1cc847 /src/engine
parentb2e2e3b0b92f108d8b7fcbea463f92635915c349 (diff)
engine/enginepregain: Use float math for gain calculations
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/enginepregain.cpp26
-rw-r--r--src/engine/enginepregain.h8
2 files changed, 16 insertions, 18 deletions
diff --git a/src/engine/enginepregain.cpp b/src/engine/enginepregain.cpp
index 9c37898ce3..27ed698219 100644
--- a/src/engine/enginepregain.cpp
+++ b/src/engine/enginepregain.cpp
@@ -11,10 +11,13 @@
#include "util/sample.h"
namespace {
- constexpr double kSpeedGainMultiplyer = 4.0; // Bends the speed to gain curve for a natural vinyl sound
- constexpr double kMaxTotalGainBySpeed = 0.9; // -1 dB to not risk any clipping even for lossy track that may
- // have samples above 1.0
- const double kSpeedOneDiv = log10((1 * kSpeedGainMultiplyer) + 1); // value to normalize gain to 1 at speed one
+constexpr float kSpeedGainMultiplier =
+ 4.0f; // Bends the speed to gain curve for a natural vinyl sound
+constexpr float kMaxTotalGainBySpeed =
+ 0.9f; // -1 dB to not risk any clipping even for lossy track that may
+ // have samples above 1.0
+constexpr float kSpeedOneDiv = log10((1 * kSpeedGainMultiplier) +
+ 1); // value to normalize gain to 1 at speed one
} // anonymous namespace
ControlPotmeter* EnginePregain::s_pReplayGainBoost = NULL;
@@ -87,8 +90,8 @@ void EnginePregain::process(CSAMPLE* pInOut, const int iBufferSize) {
// full process for one second.
// So we need to alter gain each time ::process is called.
- const float fullReplayGainBoost = fReplayGain *
- (float)s_pReplayGainBoost->get();
+ const float fullReplayGainBoost =
+ fReplayGain * static_cast<float>(s_pReplayGainBoost->get());
// This means that a ReplayGain value has been calculated after the
// track has been loaded
@@ -98,10 +101,9 @@ void EnginePregain::process(CSAMPLE* pInOut, const int iBufferSize) {
double seconds = m_timer.elapsed().toDoubleSeconds();
if (seconds < kFadeSeconds) {
// Fade smoothly
- double fadeFrac = seconds / kFadeSeconds;
- fReplayGainCorrection =
- static_cast<float>(m_fPrevGain * (1.0 - fadeFrac) +
- fadeFrac * fullReplayGainBoost);
+ const float fadeFrac = seconds / kFadeSeconds;
+ fReplayGainCorrection = m_fPrevGain * (1.0f - fadeFrac) +
+ fadeFrac * fullReplayGainBoost;
} else {
m_bSmoothFade = false;
fReplayGainCorrection = fullReplayGainBoost;
@@ -132,12 +134,12 @@ void EnginePregain::process(CSAMPLE* pInOut, const int iBufferSize) {
// we do not add more gain then we found in the original track.
// This compensates a negative ReplayGain or PreGain setting.
- double speedGain = log10((fabs(m_dSpeed) * kSpeedGainMultiplyer) + 1) / kSpeedOneDiv;
+ CSAMPLE_GAIN speedGain = log10((fabs(m_dSpeed) * kSpeedGainMultiplier) + 1) / kSpeedOneDiv;
// Limit speed Gain to 0 dB if totalGain is already > 0.9 or Limit the
// resulting totalGain to 0.9 for all other cases. This should avoid clipping even
// if the source track has some samples above 1.0 due to lossy codecs.
if (totalGain > kMaxTotalGainBySpeed) {
- speedGain = math_min(1.0, speedGain);
+ speedGain = math_min(1.0f, speedGain);
} else {
speedGain = math_min(kMaxTotalGainBySpeed / totalGain, speedGain);
}
diff --git a/src/engine/enginepregain.h b/src/engine/enginepregain.h
index 7e99332157..6248b40261 100644
--- a/src/engine/enginepregain.h
+++ b/src/engine/enginepregain.h
@@ -1,5 +1,4 @@
-#ifndef ENGINEPREGAIN_H
-#define ENGINEPREGAIN_H
+#pragma once
#include "engine/engineobject.h"
#include "control/controlobject.h"
@@ -33,8 +32,7 @@ class EnginePregain : public EngineObject {
double m_dOldSpeed;
double m_dNonScratchSpeed;
bool m_scratching;
- CSAMPLE_GAIN
- m_fPrevGain;
+ CSAMPLE_GAIN m_fPrevGain;
ControlAudioTaperPot* m_pPotmeterPregain;
ControlObject* m_pTotalGain;
ControlObject* m_pCOReplayGain;
@@ -45,5 +43,3 @@ class EnginePregain : public EngineObject {
bool m_bSmoothFade;
PerformanceTimer m_timer;
};
-
-#endif