diff options
author | Daniel Schürmann <daschuer@mixxx.org> | 2020-10-16 10:23:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-16 10:23:48 +0200 |
commit | e9c4a9e5dcb836c6b18642c7f812e4be8e2be4c3 (patch) | |
tree | 0d233edf52a291fc9fe8d1e4b4bbb6d9faf0cf1c | |
parent | 79d0136a2aa3e5027684e094f7179aa0380e5e36 (diff) | |
parent | 90a842dd3a996a75de44d71aba7f01e98f9fc3bd (diff) |
Merge pull request #3122 from Holzhaus/float-warnings-pt-3
Fix some -Wfloat-conversion warnings (Pt. 3)
36 files changed, 336 insertions, 198 deletions
diff --git a/src/audio/types.h b/src/audio/types.h index 1200343bfb..327c5cc08f 100644 --- a/src/audio/types.h +++ b/src/audio/types.h @@ -145,6 +145,10 @@ class SampleRate { return m_value; } + static constexpr SampleRate fromDouble(double value) { + return SampleRate(static_cast<value_t>(value)); + } + private: value_t m_value; }; diff --git a/src/effects/builtin/autopaneffect.cpp b/src/effects/builtin/autopaneffect.cpp index b1b76df88c..290baf462e 100644 --- a/src/effects/builtin/autopaneffect.cpp +++ b/src/effects/builtin/autopaneffect.cpp @@ -101,7 +101,7 @@ void AutoPanEffect::processChannel( AutoPanGroupState& gs = *pGroupState; double width = m_pWidthParameter->value(); double period = m_pPeriodParameter->value(); - double smoothing = 0.5 - m_pSmoothingParameter->value(); + const auto smoothing = static_cast<float>(0.5 - m_pSmoothingParameter->value()); if (groupFeatures.has_beat_length_sec) { // period is a number of beats @@ -119,7 +119,7 @@ void AutoPanEffect::processChannel( // When the period is changed, the position of the sound shouldn't // so time need to be recalculated if (gs.m_dPreviousPeriod != -1.0) { - gs.time *= period / gs.m_dPreviousPeriod; + gs.time = static_cast<unsigned int>(gs.time * period / gs.m_dPreviousPeriod); } @@ -148,8 +148,7 @@ void AutoPanEffect::processChannel( // NOTE: Assuming engine is working in stereo. for (unsigned int i = 0; i + 1 < bufferParameters.samplesPerBuffer(); i += 2) { - - CSAMPLE periodFraction = CSAMPLE(gs.time) / period; + const auto periodFraction = static_cast<CSAMPLE>(gs.time) / static_cast<CSAMPLE>(period); // current quarter in the trigonometric circle float quarter = floorf(periodFraction * 4.0f); @@ -175,15 +174,15 @@ void AutoPanEffect::processChannel( // so the sound will be stuck at the center. If it values 1, the limits // will be 0 and 1 (full left and full right). sinusoid = sin(M_PI * 2.0f * angleFraction) * width; - gs.frac.setWithRampingApplied((sinusoid + 1.0f) / 2.0f); + gs.frac.setWithRampingApplied(static_cast<float>((sinusoid + 1.0f) / 2.0f)); // apply the delay gs.delay->process(&pInput[i], &pOutput[i], -0.005 * math_clamp(((gs.frac * 2.0) - 1.0f), -1.0, 1.0) * bufferParameters.sampleRate()); double lawCoef = computeLawCoefficient(sinusoid); - pOutput[i] *= gs.frac * lawCoef; - pOutput[i+1] *= (1.0f - gs.frac) * lawCoef; + pOutput[i] *= static_cast<CSAMPLE>(gs.frac * lawCoef); + pOutput[i + 1] *= static_cast<CSAMPLE>((1.0f - gs.frac) * lawCoef); gs.time++; while (gs.time >= period) { @@ -192,7 +191,7 @@ void AutoPanEffect::processChannel( //pOutput[i+1] = 1.0f; // The while loop is required in case period changes the value - gs.time -= period; + gs.time -= static_cast<unsigned int>(period); } } } diff --git a/src/effects/builtin/flangereffect.h b/src/effects/builtin/flangereffect.h index f87b2b30ef..08275c42d4 100644 --- a/src/effects/builtin/flangereffect.h +++ b/src/effects/builtin/flangereffect.h @@ -32,7 +32,7 @@ struct FlangerGroupState : public EffectState { prev_regen(0), prev_mix(0), prev_width(0), - prev_manual(kCenterDelayMs) { + prev_manual(static_cast<CSAMPLE_GAIN>(kCenterDelayMs)) { SampleUtil::clear(delayLeft, kBufferLenth); SampleUtil::clear(delayRight, kBufferLenth); } diff --git a/src/effects/builtin/metronomeeffect.cpp b/src/effects/builtin/metronomeeffect.cpp index 9bcc956b8c..a1487bb34b 100644 --- a/src/effects/builtin/metronomeeffect.cpp +++ b/src/effects/builtin/metronomeeffect.cpp @@ -89,9 +89,11 @@ void MetronomeEffect::processChannel( unsigned int maxFrames; if (m_pSyncParameter->toBool() && groupFeatures.has_beat_length_sec) { - maxFrames = bufferParameters.sampleRate() * groupFeatures.beat_length_sec; + maxFrames = static_cast<decltype(maxFrames)>( + bufferParameters.sampleRate() * groupFeatures.beat_length_sec); if (groupFeatures.has_beat_fraction) { - unsigned int currentFrame = maxFrames * groupFeatures.beat_fraction; + const auto currentFrame = static_cast<unsigned int>( + maxFrames * groupFeatures.beat_fraction); if (maxFrames > clickSize && currentFrame > clickSize && currentFrame < maxFrames - clickSize && @@ -101,7 +103,8 @@ void MetronomeEffect::processChannel( } } } else { - maxFrames = bufferParameters.sampleRate() * 60 / m_pBpmParameter->value(); + maxFrames = static_cast<decltype(maxFrames)>( + bufferParameters.sampleRate() * 60 / m_pBpmParameter->value()); } SampleUtil::copy(pOutput, pInput, bufferParameters.samplesPerBuffer()); @@ -135,4 +138,3 @@ void MetronomeEffect::processChannel( copyFrames); } } - diff --git a/src/encoder/encoderopus.cpp b/src/encoder/encoderopus.cpp index da442be17d..d0b6a9d029 100644 --- a/src/encoder/encoderopus.cpp +++ b/src/encoder/encoderopus.cpp @@ -168,6 +168,9 @@ int EncoderOpus::initEncoder(int samplerate, QString errorMessage) { return -1; } m_samplerate = samplerate; + DEBUG_ASSERT(m_samplerate == 8000 || m_samplerate == 12000 || + m_samplerate == 16000 || m_samplerate == 24000 || + m_samplerate == 48000); int createResult = 0; m_pOpus = opus_encoder_create(m_samplerate, m_channels, OPUS_APPLICATION_AUDIO, &createResult); @@ -197,10 +200,7 @@ int EncoderOpus::initEncoder(int samplerate, QString errorMessage) { opus_encoder_ctl(m_pOpus, OPUS_SET_VBR_CONSTRAINT(0)); // Unconstrained VBR } - double samplingPeriodMs = ( 1.0 / ((double)m_samplerate) ) * 1000.0; - double samplesPerChannel = kOpusFrameMs / samplingPeriodMs; - - m_readRequired = samplesPerChannel * m_channels; + m_readRequired = m_samplerate * kOpusFrameMs; m_pFifoChunkBuffer = std::make_unique<mixxx::SampleBuffer>(m_readRequired); initStream(); @@ -244,7 +244,7 @@ void EncoderOpus::pushHeaderPacket() { frame.append(0x01); // Channel count (1 byte) - frame.append((unsigned char)m_channels); + frame.append(static_cast<unsigned char>(m_channels)); // Pre-skip (2 bytes, little-endian) int preskip = 0; diff --git a/src/engine/sidechain/shoutconnection.cpp b/src/engine/sidechain/shoutconnection.cpp index 711c9fd48f..ca436ad17c 100644 --- a/src/engine/sidechain/shoutconnection.cpp +++ b/src/engine/sidechain/shoutconnection.cpp @@ -383,8 +383,13 @@ void ShoutConnection::updateFromPreferences() { qWarning() << "Error: unknown bit rate:" << iBitrate; } - int iMasterSamplerate = m_pMasterSamplerate->get(); - if (m_format_is_ov && iMasterSamplerate == 96000) { + auto masterSamplerate = mixxx::audio::SampleRate::fromDouble(m_pMasterSamplerate->get()); + VERIFY_OR_DEBUG_ASSERT(masterSamplerate.isValid()) { + qWarning() << "Invalid sample rate!" << masterSamplerate; + return; + } + + if (m_format_is_ov && masterSamplerate == 96000) { errorDialog(tr("Broadcasting at 96 kHz with Ogg Vorbis is not currently " "supported. Please try a different sample rate or switch " "to a different encoding."), @@ -394,7 +399,7 @@ void ShoutConnection::updateFromPreferences() { } #ifdef __OPUS__ - if(m_format_is_opus && iMasterSamplerate != EncoderOpus::getMasterSamplerate()) { + if (m_format_is_opus && masterSamplerate != EncoderOpus::getMasterSamplerate()) { errorDialog( EncoderOpus::getInvalidSamplerateMessage(), tr("Unsupported sample rate") @@ -443,7 +448,8 @@ void ShoutConnection::updateFromPreferences() { pBroadcastSettings, this); QString errorMsg; - if(m_encoder->initEncoder(iMasterSamplerate, errorMsg) < 0) { + // TODO(XXX): Use mixxx::audio::SampleRate instead of int in initEncoder + if (m_encoder->initEncoder(static_cast<int>(masterSamplerate), errorMsg) < 0) { // e.g., if lame is not found // init m_encoder itself will display a message box kLogger.warning() << "**** Encoder init failed"; @@ -906,7 +912,7 @@ bool ShoutConnection::waitForRetry() { if (delay > 0) { m_enabledMutex.lock(); - m_waitEnabled.wait(&m_enabledMutex, delay * 1000); + m_waitEnabled.wait(&m_enabledMutex, static_cast<unsigned long>(delay * 1000)); m_enabledMutex.unlock(); if (!m_pProfile->getEnabled()) { return false; diff --git a/src/library/autodj/autodjprocessor.cpp b/src/library/autodj/autodjprocessor.cpp index ed725e3138..adfa247086 100644 --- a/src/library/autodj/autodjprocessor.cpp +++ b/src/library/autodj/autodjprocessor.cpp @@ -1124,8 +1124,8 @@ double AutoDJProcessor::getEndSecond(DeckAttributes* pDeck) { double AutoDJProcessor::samplePositionToSeconds(double samplePosition, DeckAttributes* pDeck) { samplePosition /= kChannelCount; - double sampleRate = pDeck->sampleRate(); - if (sampleRate <= 0.0) { + mixxx::audio::SampleRate sampleRate = pDeck->sampleRate(); + if (!sampleRate.isValid()) { return 0.0; } return samplePosition / sampleRate / pDeck->rateRatio(); diff --git a/src/library/autodj/autodjprocessor.h b/src/library/autodj/autodjprocessor.h index ed19351516..f702614d64 100644 --- a/src/library/autodj/autodjprocessor.h +++ b/src/library/autodj/autodjprocessor.h @@ -78,8 +78,8 @@ class DeckAttributes : public QObject { return m_outroEndPos.get(); } - int sampleRate() const { - return m_sampleRate.get(); + mixxx::audio::SampleRate sampleRate() const { + return mixxx::audio::SampleRate::fromDouble(m_sampleRate.get()); } double trackSamples() const { diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index c58e893ac9..72a6279bb6 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -1020,7 +1020,7 @@ bool setTrackReplayGainRatio(const QSqlRecord& record, const int column, bool setTrackReplayGainPeak(const QSqlRecord& record, const int column, TrackPointer pTrack) { mixxx::ReplayGain replayGain(pTrack->getReplayGain()); - replayGain.setPeak(record.value(column).toDouble()); + replayGain.setPeak(record.value(column).toFloat()); pTrack->setReplayGain(replayGain); return false; } diff --git a/src/library/librarycontrol.cpp b/src/library/librarycontrol.cpp index fb1e5da22a..e3c573771c 100644 --- a/src/library/librarycontrol.cpp +++ b/src/library/librarycontrol.cpp @@ -275,7 +275,7 @@ void LibraryControl::maybeCreateGroupController(const QString& group) { } void LibraryControl::slotNumDecksChanged(double v) { - int iNumDecks = v; + int iNumDecks = static_cast<int>(v); if (iNumDecks < 0) { return; @@ -287,7 +287,7 @@ void LibraryControl::slotNumDecksChanged(double v) { } void LibraryControl::slotNumSamplersChanged(double v) { - int iNumSamplers = v; + int iNumSamplers = static_cast<int>(v); if (iNumSamplers < 0) { return; @@ -300,7 +300,7 @@ void LibraryControl::slotNumSamplersChanged(double v) { void LibraryControl::slotNumPreviewDecksChanged(double v) { - int iNumPreviewDecks = v; + int iNumPreviewDecks = static_cast<int>(v); if (iNumPreviewDecks < 0) { return; diff --git a/src/mixer/playerinfo.cpp b/src/mixer/playerinfo.cpp index 144caea3ea..f0511d4dfe 100644 --- a/src/mixer/playerinfo.cpp +++ b/src/mixer/playerinfo.cpp @@ -149,7 +149,7 @@ void PlayerInfo::updateCurrentPlayingDeck() { EngineXfader::getXfadeGains(m_pCOxfader->get(), 1.0, 0.0, MIXXX_XFADER_ADDITIVE, false, &xfl, &xfr); - int orient = pDc->m_orientation.get(); + const auto orient = static_cast<int>(pDc->m_orientation.get()); double xfvol; if (orient == EngineChannel::LEFT) { xfvol = xfl; diff --git a/src/preferences/dialog/dlgprefbroadcast.cpp b/src/preferences/dialog/dlgprefbroadcast.cpp index a1987953e9..6581c2da6d 100644 --- a/src/preferences/dialog/dlgprefbroadcast.cpp +++ b/src/preferences/dialog/dlgprefbroadcast.cpp @@ -617,7 +617,7 @@ void DlgPrefBroadcast::onSectionResized() { sender()->blockSignals(true); connectionList->setColumnWidth(kColumnEnabled, 100); - connectionList->setColumnWidth(kColumnName, width * 0.65); + connectionList->setColumnWidth(kColumnName, static_cast<int>(width * 0.65)); // The last column is automatically resized to fill // the remaining width, thanks to stretchLastSection set to true. sender()->blockSignals(false); diff --git a/src/preferences/dialog/dlgprefeq.cpp b/src/preferences/dialog/dlgprefeq.cpp index 3ff81a7cf9..3fca990304 100644 --- a/src/preferences/dialog/dlgprefeq.cpp +++ b/src/preferences/dialog/dlgprefeq.cpp @@ -602,7 +602,7 @@ int DlgPrefEQ::getSliderPosition(double eqFreq, int minValue, int maxValue) { } double dsliderPos = (eqFreq - kFrequencyLowerLimit) / (kFrequencyUpperLimit-kFrequencyLowerLimit); dsliderPos = pow(dsliderPos, 1.0 / 4.0) * (maxValue - minValue) + minValue; - return dsliderPos; + return static_cast<int>(dsliderPos); } void DlgPrefEQ::slotApply() { @@ -752,10 +752,10 @@ void DlgPrefEQ::slotMasterEqEffectChanged(int effectIndex) { slidersGridLayout->addWidget(centerFreqLabel, 0, i + 1, Qt::AlignCenter); QSlider* slider = new QSlider(this); - slider->setMinimum(param->getMinimum() * 100); - slider->setMaximum(param->getMaximum() * 100); + slider->setMinimum(static_cast<int>(param->getMinimum() * 100)); + slider->setMaximum(static_cast<int>(param->getMaximum() * 100)); slider->setSingleStep(1); - slider->setValue(param->getDefault() * 100); + slider->setValue(static_cast<int>(param->getDefault() * 100)); slider->setMinimumHeight(90); // Set the index as a property because we need it inside slotUpdateFilter() slider->setProperty("index", QVariant(i)); @@ -847,7 +847,7 @@ void DlgPrefEQ::setMasterEQParameter(int i, double value) { EffectParameter* param = effect->getKnobParameterForSlot(i); if (param) { param->setValue(value); - m_masterEQSliders[i]->setValue(value * 100); + m_masterEQSliders[i]->setValue(static_cast<int>(value * 100)); QLabel* valueLabel = m_masterEQValues[i]; QString valueText = QString::number(value); diff --git a/src/preferences/dialog/dlgprefwaveform.cpp b/src/preferences/dialog/dlgprefwaveform.cpp index 71df719765..bae25d4c67 100644 --- a/src/preferences/dialog/dlgprefwaveform.cpp +++ b/src/preferences/dialog/dlgprefwaveform.cpp @@ -30,9 +30,10 @@ DlgPrefWaveform::DlgPrefWaveform(QWidget* pParent, MixxxMainWindow* pMixxx, } // Populate zoom options. - for (int i = WaveformWidgetRenderer::s_waveformMinZoom; - i <= WaveformWidgetRenderer::s_waveformMaxZoom; i++) { - defaultZoomComboBox->addItem(QString::number(100/double(i), 'f', 1) + " %"); + for (int i = static_cast<int>(WaveformWidgetRenderer::s_waveformMinZoom); + i <= static_cast<int>(WaveformWidgetRenderer::s_waveformMaxZoom); + i++) { + defaultZoomComboBox->addItem(QString::number(100 / static_cast<double>(i), 'f', 1) + " %"); } // The GUI is not fully setup so connecting signals before calling @@ -157,7 +158,7 @@ void DlgPrefWaveform::slotUpdate() { normalizeOverviewCheckBox->setChecked(factory->isOverviewNormalized()); // Round zoom to int to get a default zoom index. defaultZoomComboBox->setCurrentIndex(static_cast<int>(factory->getDefaultZoom()) - 1); - playMarkerPositionSlider->setValue(factory->getPlayMarkerPosition() * 100); + playMarkerPositionSlider->setValue(static_cast<int>(factory->getPlayMarkerPosition() * 100)); beatGridAlphaSpinBox->setValue(factory->getBeatGridAlpha()); beatGridAlphaSlider->setValue(factory->getBeatGridAlpha()); diff --git a/src/test/analyzersilence_test.cpp b/src/test/analyzersilence_test.cpp index deb968755f..def40554eb 100644 --- a/src/test/analyzersilence_test.cpp +++ b/src/test/analyzersilence_test.cpp @@ -72,7 +72,7 @@ TEST_F(AnalyzerSilenceTest, EndToEndToneTrack) { // Fill the entire buffer with 1 kHz tone double omega = 2.0 * M_PI * kTonePitchHz / pTrack->getSampleRate(); for (int i = 0; i < nTrackSampleDataLength; i++) { - pTrackSampleData[i] = cos(i / kChannelCount * omega); + pTrackSampleData[i] = static_cast<CSAMPLE>(cos(i / kChannelCount * omega)); } analyzeTrack(); @@ -98,7 +98,7 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilence) { // Fill the middle with 1 kHz tone double omega = 2.0 * M_PI * kTonePitchHz / pTrack->getSampleRate(); for (int i = nTrackSampleDataLength / 4; i < 3 * nTrackSampleDataLength / 4; i++) { - pTrackSampleData[i] = cos(i / kChannelCount * omega); + pTrackSampleData[i] = static_cast<CSAMPLE>(cos(i / kChannelCount * omega)); } // Fill the last quarter with silence @@ -131,7 +131,7 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { // Fill the second fifth with 1 kHz tone for (int i = oneFifthOfTrackLength; i < 2 * oneFifthOfTrackLength; i++) { - pTrackSampleData[i] = cos(i / kChannelCount * omega); + pTrackSampleData[i] = static_cast<CSAMPLE>(cos(i / kChannelCount * omega)); } // Fill the third fifth with silence @@ -141,7 +141,7 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { // Fill the fourth fifth with 1 kHz tone for (int i = 3 * oneFifthOfTrackLength; i < 4 * oneFifthOfTrackLength; i++) { - pTrackSampleData[i] = cos(i / kChannelCount * omega); + pTrackSampleData[i] = static_cast<CSAMPLE>(cos(i / kChannelCount * omega)); } // Fill the fifth fifth with silence @@ -189,7 +189,7 @@ TEST_F(AnalyzerSilenceTest, RespectUserEdits) { // Fill the second half with 1 kHz tone double omega = 2.0 * M_PI * kTonePitchHz / pTrack->getSampleRate(); for (int i = nTrackSampleDataLength / 2; i < nTrackSampleDataLength; i++) { - pTrackSampleData[i] = sin(i / kChannelCount * omega); + pTrackSampleData[i] = static_cast<CSAMPLE>(sin(i / kChannelCount * omega)); } analyzeTrack(); diff --git a/src/test/sampleutiltest.cpp b/src/test/sampleutiltest.cpp index ba231687a9..6bc7d47f00 100644 --- a/src/test/sampleutiltest.cpp +++ b/src/test/sampleutiltest.cpp @@ -354,22 +354,22 @@ TEST_F(SampleUtilTest, reverse) { if (buffers.size() > 0 && sizes[0] > 10) { CSAMPLE* buffer = buffers[1]; for (int i = 0; i < 10; ++i) { - buffer[i] = i * 0.1; + buffer[i] = i * 0.1f; } SampleUtil::reverse(buffer, 10); // check if right channel remains at odd index - EXPECT_FLOAT_EQ(buffer[0], 0.8); - EXPECT_FLOAT_EQ(buffer[1], 0.9); - EXPECT_FLOAT_EQ(buffer[2], 0.6); - EXPECT_FLOAT_EQ(buffer[3], 0.7); - EXPECT_FLOAT_EQ(buffer[4], 0.4); - EXPECT_FLOAT_EQ(buffer[5], 0.5); - EXPECT_FLOAT_EQ(buffer[6], 0.2); - EXPECT_FLOAT_EQ(buffer[7], 0.3); - EXPECT_FLOAT_EQ(buffer[8], 0.0); - EXPECT_FLOAT_EQ(buffer[9], 0.1); + EXPECT_FLOAT_EQ(buffer[0], 0.8f); + EXPECT_FLOAT_EQ(buffer[1], 0.9f); + EXPECT_FLOAT_EQ(buffer[2], 0.6f); + EXPECT_FLOAT_EQ(buffer[3], 0.7f); + EXPECT_FLOAT_EQ(buffer[4], 0.4f); + EXPECT_FLOAT_EQ(buffer[5], 0.5f); + EXPECT_FLOAT_EQ(buffer[6], 0.2f); + EXPECT_FLOAT_EQ(buffer[7], 0.3f); + EXPECT_FLOAT_EQ(buffer[8], 0.0f); + EXPECT_FLOAT_EQ(buffer[9], 0.1f); } } @@ -378,22 +378,22 @@ TEST_F(SampleUtilTest, copyReverse) { CSAMPLE* source = buffers[0]; CSAMPLE* destination = buffers[1]; for (int i = 0; i < 10; ++i) { - source[i] = i * 0.1; + source[i] = i * 0.1f; } SampleUtil::copyReverse(destination, source, 10); // check if right channel remains at odd index - EXPECT_FLOAT_EQ(destination[0], 0.8); - EXPECT_FLOAT_EQ(destination[1], 0.9); - EXPECT_FLOAT_EQ(destination[2], 0.6); - EXPECT_FLOAT_EQ(destination[3], 0.7); - EXPECT_FLOAT_EQ(destination[4], 0.4); - EXPECT_FLOAT_EQ(destination[5], 0.5); - EXPECT_FLOAT_EQ(destination[6], 0.2); - EXPECT_FLOAT_EQ(destination[7], 0.3); - EXPECT_FLOAT_EQ(destination[8], 0.0); - EXPECT_FLOAT_EQ(destination[9], 0.1); + EXPECT_FLOAT_EQ(destination[0], 0.8f); + EXPECT_FLOAT_EQ(destination[1], 0.9f); + EXPECT_FLOAT_EQ(destination[2], 0.6f); + EXPECT_FLOAT_EQ(destination[3], 0.7f); + EXPECT_FLOAT_EQ(destination[4], 0.4f); + EXPECT_FLOAT_EQ(destination[5], 0.5f); + EXPECT_FLOAT_EQ(destination[6], 0.2f); + EXPECT_FLOAT_EQ(destination[7], 0.3f); + EXPECT_FLOAT_EQ(destination[8], 0.0f); + EXPECT_FLOAT_EQ(destination[9], 0.1f); } } diff --git a/src/vinylcontrol/vinylcontrolxwax.cpp b/src/vinylcontrol/vinylcontrolxwax.cpp index 78f078eb2b..c77b460214 100644 --- a/src/vinylcontrol/vinylcontrolxwax.cpp +++ b/src/vinylcontrol/vinylcontrolxwax.cpp @@ -38,6 +38,10 @@ ********************/ +namespace { +constexpr int kChannels = 2; +} + // Sample threshold below which we consider there to be no signal. const double kMinSignal = 75.0 / SAMPLE_MAX; @@ -211,8 +215,7 @@ bool VinylControlXwax::writeQualityReport(VinylSignalQualityReport* pReport) { void VinylControlXwax::analyzeSamples(CSAMPLE* pSamples, size_t nFrames) { ScopedTimer t("VinylControlXwax::analyzeSamples"); - CSAMPLE gain = m_pVinylControlInputGain->get(); - const int kChannels = 2; + auto gain = static_cast<CSAMPLE_GAIN>(m_pVinylControlInputGain->get()); // We only support amplifying with the VC pre-amp. if (gain < 1.0f) { @@ -836,7 +839,7 @@ float VinylControlXwax::getAngle() { return -1.0; } - float rps = timecoder_revs_per_sec(&timecoder); + const auto rps = static_cast<float>(timecoder_revs_per_sec(&timecoder)); // Invert angle to make vinyl spin direction correct. - return 360 - (static_cast<int>(pos / 1000.0 * 360.0 * rps) % 360); + return 360 - (static_cast<int>(pos / 1000.0f * 360.0f * rps) % 360); } diff --git a/src/waveform/renderers/glslwaveformrenderersignal.cpp b/src/waveform/renderers/glslwaveformrenderersignal.cpp index ab5d8b18cf..8777ff0e5a 100644 --- a/src/waveform/renderers/glslwaveformrenderersignal.cpp +++ b/src/waveform/renderers/glslwaveformrenderersignal.cpp @@ -174,9 +174,12 @@ void GLSLWaveformRendererSignal::createFrameBuffers() { const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); // We create a frame buffer that is 4x the size of the renderer itself to // "oversample" the texture relative to the surface we're drawing on. - const int oversamplingFactor = 4; - const int bufferWidth = oversamplingFactor * m_waveformRenderer->getWidth() * devicePixelRatio; - const int bufferHeight = oversamplingFactor * m_waveformRenderer->getHeight() * devicePixelRatio; + constexpr int oversamplingFactor = 4; + const auto bufferWidth = oversamplingFactor * + static_cast<int>(m_waveformRenderer->getWidth() * devicePixelRatio); + const auto bufferHeight = oversamplingFactor * + static_cast<int>( + m_waveformRenderer->getHeight() * devicePixelRatio); m_framebuffer = std::make_unique<QGLFramebufferObject>(bufferWidth, bufferHeight); @@ -283,8 +286,10 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/) float lowGain(1.0), midGain(1.0), highGain(1.0), allGain(1.0); getGains(&allGain, &lowGain, &midGain, &highGain); - double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize/2.0; - double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize/2.0; + const auto firstVisualIndex = static_cast<GLfloat>( + m_waveformRenderer->getFirstDisplayedPosition() * dataSize / 2.0); + const auto lastVisualIndex = static_cast<GLfloat>( + m_waveformRenderer->getLastDisplayedPosition() * dataSize / 2.0); // const int firstIndex = int(firstVisualIndex+0.5); // firstVisualIndex = firstIndex - firstIndex%2; @@ -320,26 +325,47 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/) m_frameShaderProgram->setUniformValue("textureSize", waveform->getTextureSize()); m_frameShaderProgram->setUniformValue("textureStride", waveform->getTextureStride()); - m_frameShaderProgram->setUniformValue("firstVisualIndex", (float)firstVisualIndex); - m_frameShaderProgram->setUniformValue("lastVisualIndex", (float)lastVisualIndex); + m_frameShaderProgram->setUniformValue("firstVisualIndex", firstVisualIndex); + m_frameShaderProgram->setUniformValue("lastVisualIndex", lastVisualIndex); m_frameShaderProgram->setUniformValue("allGain", allGain); m_frameShaderProgram->setUniform |