New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wrong visual play position when inside loop #11840
Changes from 2 commits
38a9391
b67e104
acfa18f
58025bf
0c0b308
e50eb82
154863c
77164b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,21 +25,27 @@ VisualPlayPosition::~VisualPlayPosition() { | |
} | ||
|
||
void VisualPlayPosition::set( | ||
double playPos, | ||
double rate, | ||
double playPosition, | ||
double playRate, | ||
double positionStep, | ||
double slipPosition, | ||
double slipRate, | ||
bool loopEnabled, | ||
double loopStartPosition, | ||
double loopEndPosition, | ||
double tempoTrackSeconds, | ||
double audioBufferMicroS) { | ||
VisualPlayPositionData data; | ||
data.m_referenceTime = m_timeInfoTime; | ||
data.m_callbackEntrytoDac = static_cast<int>(m_dCallbackEntryToDacSecs * 1000000); // s to µs | ||
data.m_enginePlayPos = playPos; | ||
data.m_rate = rate; | ||
data.m_playPos = playPosition; | ||
data.m_playRate = playRate; | ||
data.m_slipRate = slipRate; | ||
data.m_positionStep = positionStep; | ||
data.m_slipPosition = slipPosition; | ||
data.m_slipPos = slipPosition; | ||
data.m_loopEnabled = loopEnabled; | ||
data.m_loopStartPos = loopStartPosition; | ||
data.m_loopEndPos = loopEndPosition; | ||
data.m_tempoTrackSeconds = tempoTrackSeconds; | ||
data.m_audioBufferMicroS = audioBufferMicroS; | ||
|
||
|
@@ -77,7 +83,27 @@ double VisualPlayPosition::getAtNextVSync(VSyncThread* pVSyncThread) { | |
if (m_valid) { | ||
const VisualPlayPositionData data = m_data.getValue(); | ||
const double offset = calcOffsetAtNextVSync(pVSyncThread, data); | ||
return data.m_enginePlayPos + offset * data.m_rate; | ||
|
||
double interpolatedPlayPos = data.m_playPos + offset * data.m_playRate; | ||
|
||
if (data.m_loopEnabled) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this must only applied when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've commited a fix. |
||
double loopSize = data.m_loopEndPos - data.m_loopStartPos; | ||
if (loopSize > 0) { | ||
if (interpolatedPlayPos < data.m_loopStartPos) { | ||
interpolatedPlayPos = data.m_loopEndPos - | ||
std::remainder( | ||
data.m_loopStartPos - interpolatedPlayPos, | ||
loopSize); | ||
} | ||
if (interpolatedPlayPos > data.m_loopEndPos) { | ||
interpolatedPlayPos = data.m_loopStartPos + | ||
std::remainder( | ||
interpolatedPlayPos - data.m_loopEndPos, | ||
loopSize); | ||
} | ||
} | ||
} | ||
return interpolatedPlayPos; | ||
} | ||
return -1; | ||
} | ||
|
@@ -88,15 +114,15 @@ void VisualPlayPosition::getPlaySlipAtNextVSync(VSyncThread* pVSyncThread, | |
if (m_valid) { | ||
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; | ||
*pPlayPosition = data.m_playPos + offset * data.m_playRate; | ||
*pSlipPosition = data.m_slipPos + offset * data.m_slipRate; | ||
} | ||
} | ||
|
||
double VisualPlayPosition::getEnginePlayPos() { | ||
if (m_valid) { | ||
VisualPlayPositionData data = m_data.getValue(); | ||
return data.m_enginePlayPos; | ||
return data.m_playPos; | ||
} else { | ||
return -1; | ||
} | ||
|
@@ -105,7 +131,7 @@ double VisualPlayPosition::getEnginePlayPos() { | |
void VisualPlayPosition::getTrackTime(double* pPlayPosition, double* pTempoTrackSeconds) { | ||
if (m_valid) { | ||
VisualPlayPositionData data = m_data.getValue(); | ||
*pPlayPosition = data.m_enginePlayPos; | ||
*pPlayPosition = data.m_playPos; | ||
*pTempoTrackSeconds = data.m_tempoTrackSeconds; | ||
} else { | ||
*pPlayPosition = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop Start and End should be only read atomically. This avoids that the position can slip out during moving the loop.
In this case LoopInfo should be returned, or both values in a single call.