summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2020-10-16 10:24:43 +0200
committerGitHub <noreply@github.com>2020-10-16 10:24:43 +0200
commit5713c398b3cdc1949a4d9435347d880bd9e01ecf (patch)
tree2b62a0f80af188267824e2b660ce31cab14bf1d4 /src/engine
parente9c4a9e5dcb836c6b18642c7f812e4be8e2be4c3 (diff)
parentebcb2608dc9a890d946144270d39a254fb6f4cb1 (diff)
Merge pull request #3124 from Holzhaus/float-warnings-pt-5
Fix some -Wfloat-conversion warnings (Pt. 5)
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bufferscalers/enginebufferscalelinear.cpp10
-rw-r--r--src/engine/effects/engineeffectchain.cpp18
-rw-r--r--src/engine/enginemaster.cpp8
-rw-r--r--src/engine/enginepregain.cpp37
-rw-r--r--src/engine/enginepregain.h8
-rw-r--r--src/engine/enginetalkoverducking.cpp33
-rw-r--r--src/engine/enginevumeter.cpp39
-rw-r--r--src/engine/enginevumeter.h30
-rw-r--r--src/engine/sidechain/enginerecord.cpp3
9 files changed, 85 insertions, 101 deletions
diff --git a/src/engine/bufferscalers/enginebufferscalelinear.cpp b/src/engine/bufferscalers/enginebufferscalelinear.cpp
index 89e19a2a60..78aca3ecb4 100644
--- a/src/engine/bufferscalers/enginebufferscalelinear.cpp
+++ b/src/engine/bufferscalers/enginebufferscalelinear.cpp
@@ -67,8 +67,8 @@ double EngineBufferScaleLinear::scaleBuffer(
m_dOldRate = m_dRate; // If cleared, don't interpolate rate.
m_bClear = false;
}
- float rate_add_old = m_dOldRate; // Smoothly interpolate to new playback rate
- float rate_add_new = m_dRate;
+ double rate_add_old = m_dOldRate; // Smoothly interpolate to new playback rate
+ double rate_add_new = m_dRate;
SINT frames_read = 0;
if (rate_add_new * rate_add_old < 0) {
@@ -177,9 +177,9 @@ SINT EngineBufferScaleLinear::do_copy(CSAMPLE* buf, SINT buf_size) {
// Stretch a specified buffer worth of audio using linear interpolation
SINT EngineBufferScaleLinear::do_scale(CSAMPLE* buf, SINT buf_size) {
- float rate_old = m_dOldRate;
- const float rate_new = m_dRate;
- const float rate_diff = rate_new - rate_old;
+ double rate_old = m_dOldRate;
+ const double rate_new = m_dRate;
+ const double rate_diff = rate_new - rate_old;
// Update the old base rate because we only need to
// interpolate/ramp up the pitch changes once.
diff --git a/src/engine/effects/engineeffectchain.cpp b/src/engine/effects/engineeffectchain.cpp
index 9ea84e669f..2a8b5ac137 100644
--- a/src/engine/effects/engineeffectchain.cpp
+++ b/src/engine/effects/engineeffectchain.cpp
@@ -77,7 +77,7 @@ bool EngineEffectChain::removeEffect(EngineEffect* pEffect, int iIndex) {
bool EngineEffectChain::updateParameters(const EffectsRequest& message) {
// TODO(rryan): Parameter interpolation.
m_mixMode = message.SetEffectChainParameters.mix_mode;
- m_dMix = message.SetEffectChainParameters.mix;
+ m_dMix = static_cast<CSAMPLE>(message.SetEffectChainParameters.mix);
if (m_enableState != EffectEnableState::Disabled && !message.SetEffectParameters.enabled) {
m_enableState = EffectEnableState::Disabling;
@@ -315,15 +315,23 @@ bool EngineEffectChain::process(const ChannelHandle& inputHandle,
// Dry/Wet mode: output = (input * (1-mix knob)) + (wet * mix knob)
SampleUtil::copy2WithRampingGain(
pOut,
- pIn, 1.0 - lastCallbackMixKnob, 1.0 - currentMixKnob,
- pIntermediateInput, lastCallbackMixKnob, currentMixKnob,
+ pIn,
+ 1.0f - lastCallbackMixKnob,
+ 1.0f - currentMixKnob,
+ pIntermediateInput,
+ lastCallbackMixKnob,
+ currentMixKnob,
numSamples);
} else {
// Dry+Wet mode: output = input + (wet * mix knob)
SampleUtil::copy2WithRampingGain(
pOut,
- pIn, 1.0, 1.0,
- pIntermediateInput, lastCallbackMixKnob, currentMixKnob,
+ pIn,
+ 1.0f,
+ 1.0f,
+ pIntermediateInput,
+ lastCallbackMixKnob,
+ currentMixKnob,
numSamples);
}
}
diff --git a/src/engine/enginemaster.cpp b/src/engine/enginemaster.cpp
index b38914eaea..e86457b2eb 100644
--- a/src/engine/enginemaster.cpp
+++ b/src/engine/enginemaster.cpp
@@ -412,9 +412,9 @@ void EngineMaster::process(const int iBufferSize) {
CSAMPLE pflMixGainInHeadphones = 1;
CSAMPLE masterMixGainInHeadphones = 0;
if (masterEnabled) {
- CSAMPLE cf_val = m_pHeadMix->get();
- pflMixGainInHeadphones = 0.5 * (-cf_val + 1.);
- masterMixGainInHeadphones = 0.5 * (cf_val + 1.);
+ const auto cf_val = static_cast<CSAMPLE_GAIN>(m_pHeadMix->get());
+ pflMixGainInHeadphones = 0.5f * (-cf_val + 1.0f);
+ masterMixGainInHeadphones = 0.5f * (cf_val + 1.0f);
// qDebug() << "head val " << cf_val << ", head " << chead_gain
// << ", master " << cmaster_gain;
}
@@ -710,7 +710,7 @@ void EngineMaster::process(const int iBufferSize) {
// Balance values
CSAMPLE balright = 1.;
CSAMPLE balleft = 1.;
- CSAMPLE bal = m_pBalance->get();
+ const auto bal = static_cast<CSAMPLE_GAIN>(m_pBalance->get());
if (bal > 0.) {
balleft -= bal;
} else if (bal < 0.) {
diff --git a/src/engine/enginepregain.cpp b/src/engine/enginepregain.cpp
index ee68846028..7a256b26d8 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
+
+// Bends the speed to gain curve for a natural vinyl sound
+constexpr float kSpeedGainMultiplier = 4.0f;
+// -1 dB to not risk any clipping even for lossy track that may have samples above 1.0
+constexpr float kMaxTotalGainBySpeed = 0.9f;
+// value to normalize gain to 1 at speed one
+const float kSpeedOneDiv = log10((1 * kSpeedGainMultiplier) + 1);
} // anonymous namespace
ControlPotmeter* EnginePregain::s_pReplayGainBoost = NULL;
@@ -64,8 +67,8 @@ void EnginePregain::setSpeedAndScratching(double speed, bool scratching) {
}
void EnginePregain::process(CSAMPLE* pInOut, const int iBufferSize) {
- const float fReplayGain = m_pCOReplayGain->get();
- float fReplayGainCorrection;
+ const auto fReplayGain = static_cast<CSAMPLE_GAIN>(m_pCOReplayGain->get());
+ CSAMPLE_GAIN fReplayGainCorrection;
if (!s_pEnableReplayGain->toBool() || m_pPassthroughEnabled->toBool()) {
// Override replaygain value if passing through
// TODO(XXX): consider a good default.
@@ -87,19 +90,19 @@ 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
- const double kFadeSeconds = 1.0;
+ const float kFadeSeconds = 1.0;
if (m_bSmoothFade) {
- double seconds = m_timer.elapsed().toDoubleSeconds();
+ float seconds = static_cast<float>(m_timer.elapsed().toDoubleSeconds());
if (seconds < kFadeSeconds) {
// Fade smoothly
- double fadeFrac = seconds / kFadeSeconds;
- fReplayGainCorrection = m_fPrevGain * (1.0 - fadeFrac) +
+ const float fadeFrac = seconds / kFadeSeconds;
+ fReplayGainCorrection = m_fPrevGain * (1.0f - fadeFrac) +
fadeFrac * fullReplayGainBoost;
} else {
m_bSmoothFade = false;
@@ -131,16 +134,19 @@ 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(static_cast<CSAMPLE_GAIN>(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);
}
- totalGain *= speedGain;
+ totalGain *= static_cast<CSAMPLE_GAIN>(speedGain);
if ((m_dSpeed * m_dOldSpeed < 0) && m_scratching) {
// direction changed, go though zero if scratching
@@ -160,4 +166,3 @@ void EnginePregain::collectFeatures(GroupFeatureState* pGroupFeatures) const {
pGroupFeatures->gain = m_pPotmeterPregain->get();
pGroupFeatures->has_gain = true;
}
-
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
diff --git a/src/engine/enginetalkoverducking.cpp b/src/engine/enginetalkoverducking.cpp
index e67df8b131..d6f41ebea9 100644
--- a/src/engine/enginetalkoverducking.cpp
+++ b/src/engine/enginetalkoverducking.cpp
@@ -1,7 +1,11 @@
#include "control/controlproxy.h"
#include "engine/enginetalkoverducking.h"
-#define DUCK_THRESHOLD 0.1
+namespace {
+
+constexpr CSAMPLE kDuckThreshold = 0.1f;
+
+}
EngineTalkoverDucking::EngineTalkoverDucking(
UserSettingsPointer pConfig, const QString& group)
@@ -23,10 +27,10 @@ EngineTalkoverDucking::EngineTalkoverDucking(
// candidate for customization is the threshold, which may be too low for
// noisy club situations.
setParameters(
- DUCK_THRESHOLD,
- m_pDuckStrength->get(),
- m_pMasterSampleRate->get() / 2 * .1,
- m_pMasterSampleRate->get() / 2);
+ kDuckThreshold,
+ static_cast<CSAMPLE>(m_pDuckStrength->get()),
+ static_cast<unsigned int>(m_pMasterSampleRate->get() / 2 * .1),
+ static_cast<unsigned int>(m_pMasterSampleRate->get() / 2));
m_pTalkoverDucking = new ControlPushButton(ConfigKey(m_group, "talkoverDucking"));
m_pTalkoverDucking->setButtonMode(ControlPushButton::TOGGLE);
@@ -49,14 +53,17 @@ EngineTalkoverDucking::~EngineTalkoverDucking() {
void EngineTalkoverDucking::slotSampleRateChanged(double samplerate) {
setParameters(
- DUCK_THRESHOLD, m_pDuckStrength->get(),
- samplerate / 2 * .1, samplerate / 2);
+ kDuckThreshold,
+ static_cast<CSAMPLE>(m_pDuckStrength->get()),
+ static_cast<unsigned int>(samplerate / 2 * .1),
+ static_cast<unsigned int>(samplerate / 2));
}
void EngineTalkoverDucking::slotDuckStrengthChanged(double strength) {
- setParameters(
- DUCK_THRESHOLD, strength,
- m_pMasterSampleRate->get() / 2 * .1, m_pMasterSampleRate->get() / 2);
+ setParameters(kDuckThreshold,
+ static_cast<CSAMPLE>(strength),
+ static_cast<unsigned int>(m_pMasterSampleRate->get() / 2 * .1),
+ static_cast<unsigned int>(m_pMasterSampleRate->get() / 2));
m_pConfig->set(ConfigKey(m_group, "duckStrength"), ConfigValue(strength * 100));
}
@@ -68,12 +75,12 @@ CSAMPLE EngineTalkoverDucking::getGain(int numFrames) {
// Apply microphone ducking.
switch (getMode()) {
case EngineTalkoverDucking::OFF:
- return 1.0;
+ return 1.0f;
case EngineTalkoverDucking::AUTO:
case EngineTalkoverDucking::MANUAL:
- return calculateCompressedGain(numFrames);
+ return static_cast<CSAMPLE>(calculateCompressedGain(numFrames));
default:
DEBUG_ASSERT("!Unknown Ducking mode");
- return 1.0;
+ return 1.0f;
}
}
diff --git a/src/engine/enginevumeter.cpp b/src/engine/enginevumeter.cpp
index 87989b5ca3..6443de799f 100644
--- a/src/engine/enginevumeter.cpp
+++ b/src/engine/enginevumeter.cpp
@@ -1,19 +1,3 @@
-/***************************************************************************
- enginevumeter.cpp - description
- -------------------
- copyright : (C) 2002 by Tue and Ken Haste Andersen
- email :
-***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
#include "engine/enginevumeter.h"
#include "control/controlproxy.h"
@@ -21,6 +5,19 @@
#include "util/math.h"
#include "util/sample.h"
+namespace {
+
+// Rate at which the vumeter is updated (using a sample rate of 44100 Hz):
+constexpr int kVuUpdateRate = 30; // in 1/s, fits to display frame rate
+constexpr int kPeakDuration = 500; // in ms
+
+// Smoothing Factors
+// Must be from 0-1 the lower the factor, the more smoothing that is applied
+constexpr CSAMPLE kAttackSmoothing = 1.0f; // .85
+constexpr CSAMPLE kDecaySmoothing = 0.1f; //.16//.4
+
+} // namespace
+
EngineVuMeter::EngineVuMeter(QString group) {
// The VUmeter widget is controlled via a controlpotmeter, which means
// that it should react on the setValue(int) signal.
@@ -68,7 +65,7 @@ void EngineVuMeter::process(CSAMPLE* pIn, const int iBufferSize) {
m_iSamplesCalculated += iBufferSize / 2;
// Are we ready to update the VU meter?:
- if (m_iSamplesCalculated > (sampleRate / VU_UPDATE_RATE)) {
+ if (m_iSamplesCalculated > (sampleRate / kVuUpdateRate)) {
doSmooth(m_fRMSvolumeL,
log10(SHRT_MAX * m_fRMSvolumeSumL
/ (m_iSamplesCalculated * 1000) + 1));
@@ -99,7 +96,7 @@ void EngineVuMeter::process(CSAMPLE* pIn, const int iBufferSize) {
if (clipped & SampleUtil::CLIPPING_LEFT) {
m_ctrlPeakIndicatorL->set(1.);
- m_peakDurationL = PEAK_DURATION * sampleRate / iBufferSize / 2000;
+ m_peakDurationL = kPeakDuration * sampleRate / iBufferSize / 2000;
} else if (m_peakDurationL <= 0) {
m_ctrlPeakIndicatorL->set(0.);
} else {
@@ -108,7 +105,7 @@ void EngineVuMeter::process(CSAMPLE* pIn, const int iBufferSize) {
if (clipped & SampleUtil::CLIPPING_RIGHT) {
m_ctrlPeakIndicatorR->set(1.);
- m_peakDurationR = PEAK_DURATION * sampleRate / iBufferSize / 2000;
+ m_peakDurationR = kPeakDuration * sampleRate / iBufferSize / 2000;
} else if (m_peakDurationR <= 0) {
m_ctrlPeakIndicatorR->set(0.);
} else {
@@ -121,9 +118,9 @@ void EngineVuMeter::process(CSAMPLE* pIn, const int iBufferSize) {
void EngineVuMeter::doSmooth(CSAMPLE &currentVolume, CSAMPLE newVolume)
{
if (currentVolume > newVolume)
- currentVolume -= DECAY_SMOOTHING * (currentVolume - newVolume);
+ currentVolume -= kDecaySmoothing * (currentVolume - newVolume);
else
- currentVolume += ATTACK_SMOOTHING * (newVolume - currentVolume);
+ currentVolume += kAttackSmoothing * (newVolume - currentVolume);
if (currentVolume < 0)
currentVolume=0;
if (currentVolume > 1.0)
diff --git a/src/engine/enginevumeter.h b/src/engine/enginevumeter.h
index bf6bee4219..a39da1bcc1 100644
--- a/src/engine/enginevumeter.h
+++ b/src/engine/enginevumeter.h
@@ -1,33 +1,7 @@
-/***************************************************************************
- enginevumeter.h - description
- -------------------
- copyright : (C) 2002 by Tue and Ken Haste Andersen
- email :
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#ifndef ENGINEVUMETER_H
-#define ENGINEVUMETER_H
+#pragma once
#include "engine/engineobject.h"
-// Rate at which the vumeter is updated (using a sample rate of 44100 Hz):
-#define VU_UPDATE_RATE 30 // in 1/s, fits to display frame rate
-#define PEAK_DURATION 500 // in ms
-
-// SMOOTHING FACTORS
-// Must be from 0-1 the lower the factor, the more smoothing that is applied
-#define ATTACK_SMOOTHING 1. // .85
-#define DECAY_SMOOTHING .1 //.16//.4
-
class ControlPotmeter;
class ControlProxy;
@@ -61,5 +35,3 @@ class EngineVuMeter : public EngineObject {
ControlProxy* m_pSampleRate;
};
-
-#endif
diff --git a/src/engine/sidechain/enginerecord.cpp b/src/engine/sidechain/enginerecord.cpp
index d8d39ab188..8878ad1296 100644
--- a/src/engine/sidechain/enginerecord.cpp
+++ b/src/engine/sidechain/enginerecord.cpp
@@ -108,8 +108,7 @@ bool EngineRecord::metaDataHasChanged()
}
void EngineRecord::process(const CSAMPLE* pBuffer, const int iBufferSize) {
-
- float recordingStatus = m_pRecReady->get();
+ const auto recordingStatus = static_cast<int>(m_pRecReady->get());
static const QString tag("EngineRecord recording");
if (recordingStatus == RECORD_OFF) {