diff options
author | m0dB <79429057+m0dB@users.noreply.github.com> | 2023-05-18 02:09:02 +0200 |
---|---|---|
committer | m0dB <79429057+m0dB@users.noreply.github.com> | 2023-05-27 01:28:25 +0200 |
commit | a6065875e082dd823ac1a8e850ef873126db3dcb (patch) | |
tree | 924ca3910125a0f20f7860596a1929efb16fe54d | |
parent | 4ec3fba1e34910897dd68d4b5832ad2f62fdd4ce (diff) |
calculate the visual split position just like the play position
-rw-r--r-- | src/engine/enginebuffer.cpp | 14 | ||||
-rw-r--r-- | src/waveform/visualplayposition.cpp | 41 | ||||
-rw-r--r-- | src/waveform/visualplayposition.h | 4 |
3 files changed, 36 insertions, 23 deletions
diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index 380b625e46..21d6bbc700 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -590,7 +590,7 @@ void EngineBuffer::ejectTrack() { TrackPointer pOldTrack = m_pCurrentTrack; m_pause.lock(); - m_visualPlayPos->set(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + m_visualPlayPos->set(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); doSeekPlayPos(mixxx::audio::kStartFramePos, SEEK_EXACT); m_pCurrentTrack.reset(); @@ -1385,14 +1385,21 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) { m_iSamplesSinceLastIndicatorUpdate += iBufferSize; const double fFractionalPlaypos = fractionalPlayposFromAbsolute(m_playPosition); + const double fFractionalSlipPos = fractionalPlayposFromAbsolute(m_slipPosition); const double tempoTrackSeconds = m_trackEndPositionOld.value() / m_trackSampleRateOld / getRateRatio(); if (speed > 0 && fFractionalPlaypos == 1.0) { - // At Track end + // Play pos at Track end speed = 0; } + double effectiveSlipRate = m_dSlipRate; + if (effectiveSlipRate > 0.0 && fFractionalSlipPos == 1.0) { + // Slip pos at Track end + effectiveSlipRate = 0.0; + } + // Update indicators that are only updated after every // sampleRate/kiUpdateRate samples processed. (e.g. playposSlider) if (m_iSamplesSinceLastIndicatorUpdate > @@ -1409,7 +1416,8 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) { speed * m_baserate_old, static_cast<int>(iBufferSize) / m_trackEndPositionOld.toEngineSamplePos(), - fractionalPlayposFromAbsolute(m_slipPosition), + fFractionalSlipPos, + effectiveSlipRate, tempoTrackSeconds, iBufferSize / kSamplesPerFrame / m_sampleRate.toDouble() * 1000000.0); diff --git a/src/waveform/visualplayposition.cpp b/src/waveform/visualplayposition.cpp index e71d0deaa1..6a816e1d52 100644 --- a/src/waveform/visualplayposition.cpp +++ b/src/waveform/visualplayposition.cpp @@ -29,6 +29,7 @@ void VisualPlayPosition::set( double rate, double positionStep, double slipPosition, + double slipRate, double tempoTrackSeconds, double audioBufferMicroS) { VisualPlayPositionData data; @@ -36,6 +37,7 @@ void VisualPlayPosition::set( data.m_callbackEntrytoDac = static_cast<int>(m_dCallbackEntryToDacSecs * 1000000); // s to µs data.m_enginePlayPos = playPos; data.m_rate = rate; + data.m_slipRate = slipRate; data.m_positionStep = positionStep; data.m_slipPosition = slipPosition; data.m_tempoTrackSeconds = tempoTrackSeconds; @@ -46,36 +48,36 @@ void VisualPlayPosition::set( m_valid = true; } -double VisualPlayPosition::calcPosAtNextVSync( +double VisualPlayPosition::calcOffsetAtNextVSync( VSyncThread* pVSyncThread, const VisualPlayPositionData& data) { - double playPos = data.m_enginePlayPos; // load playPos for the first sample in Buffer if (data.m_audioBufferMicroS != 0.0) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) Q_UNUSED(pVSyncThread); - int refToVSync = 0; - int syncIntervalTimeMicros = 0; + const int refToVSync = 0; + const int syncIntervalTimeMicros = 0; #else - int refToVSync = pVSyncThread->fromTimerToNextSyncMicros(data.m_referenceTime); - int syncIntervalTimeMicros = pVSyncThread->getSyncIntervalTimeMicros(); + const int refToVSync = pVSyncThread->fromTimerToNextSyncMicros(data.m_referenceTime); + const int syncIntervalTimeMicros = pVSyncThread->getSyncIntervalTimeMicros(); #endif - int offset = refToVSync - data.m_callbackEntrytoDac; // The offset is limited to the audio buffer + waveform sync interval // This should be sufficient to compensate jitter, but does not continue // in case of underflows. - int maxOffset = static_cast<int>(data.m_audioBufferMicroS + syncIntervalTimeMicros); - offset = math_clamp(offset, -maxOffset, maxOffset); - // add the offset for the position of the sample that will be transferred to the DAC - // When the next display frame is displayed - playPos += data.m_positionStep * offset * data.m_rate / data.m_audioBufferMicroS; + const int maxOffset = static_cast<int>(data.m_audioBufferMicroS + syncIntervalTimeMicros); + // Calculate the offset in micros for the position of the sample that will be transferred + // to the DAC when the next display frame is displayed + const int offset = math_clamp( + refToVSync - data.m_callbackEntrytoDac, -maxOffset, maxOffset); + // Apply the offset proportional to m_positionStep + return data.m_positionStep * static_cast<double>(offset) / data.m_audioBufferMicroS; } - // qDebug() << "playPos" << playPos << offset; - return playPos; + return 0.0; } double VisualPlayPosition::getAtNextVSync(VSyncThread* pVSyncThread) { if (m_valid) { - VisualPlayPositionData data = m_data.getValue(); - return calcPosAtNextVSync(pVSyncThread, data); + const VisualPlayPositionData data = m_data.getValue(); + const double offset = calcOffsetAtNextVSync(pVSyncThread, data); + return data.m_enginePlayPos + offset * data.m_rate; } return -1; } @@ -84,9 +86,10 @@ void VisualPlayPosition::getPlaySlipAtNextVSync(VSyncThread* pVSyncThread, double* pPlayPosition, double* pSlipPosition) { if (m_valid) { - VisualPlayPositionData data = m_data.getValue(); - *pPlayPosition = calcPosAtNextVSync(pVSyncThread, data); - *pSlipPosition = data.m_slipPosition; + const VisualPlayPositionData data = m_data.getValue(); + const double offset = calcOffsetAtNextVSync(pVSyncThread, data); + *pPlayPosition = data.m_enginePlayPos + offset * data.m_rate; + *pSlipPosition = data.m_slipPosition + offset * data.m_slipRate; } } diff --git a/src/waveform/visualplayposition.h b/src/waveform/visualplayposition.h index d104a12533..9c2ca6ab67 100644 --- a/src/waveform/visualplayposition.h +++ b/src/waveform/visualplayposition.h @@ -36,6 +36,7 @@ class VisualPlayPositionData { double m_rate; double m_positionStep; double m_slipPosition; + double m_slipRate; double m_tempoTrackSeconds; // total track time, taking the current tempo into account double m_audioBufferMicroS; }; @@ -54,6 +55,7 @@ class VisualPlayPosition : public QObject { double rate, double positionStep, double slipPosition, + double slipRate, double tempoTrackSeconds, double audioBufferMicroS); @@ -77,7 +79,7 @@ class VisualPlayPosition : public QObject { } private: - double calcPosAtNextVSync(VSyncThread* pVSyncThread, const VisualPlayPositionData& data); + double calcOffsetAtNextVSync(VSyncThread* pVSyncThread, const VisualPlayPositionData& data); ControlValueAtomic<VisualPlayPositionData> m_data; bool m_valid; QString m_key; |