Hi again Rui,
Following up on the tests with the previous files, I've been looking through qtractorAudioBuffer.cpp (also using Gemini) and I think I've found the exact condition causing the 1-quantum cycle offset when using buffer sizes ≥ 256.
The issue shows up specifically when comparing any audio file longer than 4 seconds (!m_bIntegral) against a file shorter than 4 seconds (m_bIntegral == true) or a MIDI track. Shortening the session loop markers doesn't avoid it, whereas splitting or consolidating the clip into files under 4 seconds immediately eliminates the drift.
Looking at the code, that exact one-period shift comes from how m_bIntegral, inSync(), and readMix() interact:
In qtractorAudioBuffer::open() and initSync(), any file whose length exceeds the maximum ring-buffer size (capped at iSampleRate << 2, i.e., 4 seconds) streams from disk with m_bIntegral = false.
On transport start or session loop wrap-around, setLoop() / reset() invalidate ReadSync and set m_iReadOffset = m_iOffset + m_iLength + 1.
On the very first process cycle (iFrameStart to iFrameEnd), inSync() sees that ReadSync is false and m_iReadOffset doesn't match iFrameStart + m_iOffset, so it drops the current cycle (returning false) and calls seek(iFrameEnd).
Because seek() schedules the disk read starting at iFrameEnd instead of iFrameStart, clips longer than 4 seconds consistently start one exact buffer period (iFrameEnd - iFrameStart) behind short clips (< 4s) or MIDI tracks.
In fact, there is a second very easy way to reproduce this same issue in readMix(): if you enable an internal clip loop on a file longer than 4 seconds that spans the exact length of the clip (m_iLoopEnd == m_iLength), on each wrap-around m_iReadOffset hits re (m_iOffset + m_iLength), triggers setSyncFlag(ReadSync, false) as if the clip had ended, and falls back into the inSync() -> seek(iFrameEnd) loop, accumulating delay on every repetition until the audio completely disappears. Extending the right edge of the clip past the loop end (m_iLength > m_iLoopEnd) stops it from happening.
At 64 or 128 frames, that initial delay is only ~1.3–2.6 ms and goes practically unnoticed, but at 256, 512, or 1024 frames (5.3–21.3 ms) the timing and phase offset becomes clearly audible.
Keep in mind that this diagnosis was done with the help of AI and might not be entirely accurate, though it fits the test results.
Sharing this in case it helps you reproduce it and see why those test files were drifting out of sync.
Hi again Rui,
Following up on the tests with the previous files, I've been looking through qtractorAudioBuffer.cpp (also using Gemini) and I think I've found the exact condition causing the 1-quantum cycle offset when using buffer sizes ≥ 256.
The issue shows up specifically when comparing any audio file longer than 4 seconds (!m_bIntegral) against a file shorter than 4 seconds (m_bIntegral == true) or a MIDI track. Shortening the session loop markers doesn't avoid it, whereas splitting or consolidating the clip into files under 4 seconds immediately eliminates the drift.
Looking at the code, that exact one-period shift comes from how m_bIntegral, inSync(), and readMix() interact:
In qtractorAudioBuffer::open() and initSync(), any file whose length exceeds the maximum ring-buffer size (capped at iSampleRate << 2, i.e., 4 seconds) streams from disk with m_bIntegral = false.
On transport start or session loop wrap-around, setLoop() / reset() invalidate ReadSync and set m_iReadOffset = m_iOffset + m_iLength + 1.
On the very first process cycle (iFrameStart to iFrameEnd), inSync() sees that ReadSync is false and m_iReadOffset doesn't match iFrameStart + m_iOffset, so it drops the current cycle (returning false) and calls seek(iFrameEnd).
Because seek() schedules the disk read starting at iFrameEnd instead of iFrameStart, clips longer than 4 seconds consistently start one exact buffer period (iFrameEnd - iFrameStart) behind short clips (< 4s) or MIDI tracks.
In fact, there is a second very easy way to reproduce this same issue in readMix(): if you enable an internal clip loop on a file longer than 4 seconds that spans the exact length of the clip (m_iLoopEnd == m_iLength), on each wrap-around m_iReadOffset hits re (m_iOffset + m_iLength), triggers setSyncFlag(ReadSync, false) as if the clip had ended, and falls back into the inSync() -> seek(iFrameEnd) loop, accumulating delay on every repetition until the audio completely disappears. Extending the right edge of the clip past the loop end (m_iLength > m_iLoopEnd) stops it from happening.
At 64 or 128 frames, that initial delay is only ~1.3–2.6 ms and goes practically unnoticed, but at 256, 512, or 1024 frames (5.3–21.3 ms) the timing and phase offset becomes clearly audible.
Keep in mind that this diagnosis was done with the help of AI and might not be entirely accurate, though it fits the test results.
Sharing this in case it helps you reproduce it and see why those test files were drifting out of sync.
Best regards!