Skip to content

Commit bff9a30

Browse files
Merge pull request mixxxdj#12470 from daschuer/visualplayposclamp
Clamp offset in VisualPlayPosition with extra time of two vsync interval
2 parents 9cea449 + f583bcb commit bff9a30

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Diff for: src/waveform/visualplayposition.cpp

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ double VisualPlayPosition::m_dCallbackEntryToDacSecs = 0;
1313

1414
VisualPlayPosition::VisualPlayPosition(const QString& key)
1515
: m_valid(false),
16-
m_key(key) {
16+
m_key(key),
17+
m_noTransport(false) {
1718
}
1819

1920
VisualPlayPosition::~VisualPlayPosition() {
@@ -63,14 +64,31 @@ double VisualPlayPosition::calcOffsetAtNextVSync(
6364
const int refToVSync = pVSyncThread->fromTimerToNextSyncMicros(data.m_referenceTime);
6465
const int syncIntervalTimeMicros = pVSyncThread->getSyncIntervalTimeMicros();
6566
#endif
66-
// The offset is limited to the audio buffer + waveform sync interval
67+
// The offset is limited to the audio buffer + 2 x waveform sync interval
6768
// This should be sufficient to compensate jitter, but does not continue
6869
// in case of underflows.
69-
const int maxOffset = static_cast<int>(data.m_audioBufferMicroS + syncIntervalTimeMicros);
70+
const int maxOffset = static_cast<int>(
71+
data.m_audioBufferMicroS + 2 * syncIntervalTimeMicros);
7072
// Calculate the offset in micros for the position of the sample that will be transferred
7173
// to the DAC when the next display frame is displayed
72-
const int offset = math_clamp(
73-
refToVSync - data.m_callbackEntrytoDac, -maxOffset, maxOffset);
74+
int offset = refToVSync - data.m_callbackEntrytoDac;
75+
if (offset < -maxOffset) {
76+
offset = -maxOffset;
77+
if (!m_noTransport) {
78+
qWarning() << "VisualPlayPosition::calcOffsetAtNextVSync"
79+
<< m_key << "no transport (offset < -maxOffset)";
80+
m_noTransport = true;
81+
}
82+
} else if (offset > maxOffset) {
83+
offset = maxOffset;
84+
if (!m_noTransport) {
85+
qWarning() << "VisualPlayPosition::calcOffsetAtNextVSync"
86+
<< m_key << "no transport (offset > maxOffset)";
87+
m_noTransport = true;
88+
}
89+
} else {
90+
m_noTransport = false;
91+
}
7492
// Apply the offset proportional to m_positionStep
7593
return data.m_positionStep * static_cast<double>(offset) / data.m_audioBufferMicroS;
7694
}

Diff for: src/waveform/visualplayposition.h

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class VisualPlayPosition : public QObject {
9393
ControlValueAtomic<VisualPlayPositionData> m_data;
9494
bool m_valid;
9595
QString m_key;
96+
bool m_noTransport;
9697

9798
static QMap<QString, QWeakPointer<VisualPlayPosition>> m_listVisualPlayPosition;
9899
// Time info from the Sound device, updated just after audio callback is called

0 commit comments

Comments
 (0)