Add new comment to Looping causes audio tracks to desynchronize

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:

  1. 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.

  2. On transport start or session loop wrap-around, setLoop() / reset() invalidate ReadSync and set m_iReadOffset = m_iOffset + m_iLength + 1.

  3. 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).

  4. 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!

The content of this field is kept private and will not be shown publicly.

Markdown

  • Parses markdown and converts it to HTML.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id> <img src alt height width> <strike> <pre> <p> <br>
  • Lines and paragraphs break automatically.

Filtered HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <b> <i> <pre> <img src alt height width> <strike>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
File attachments
Unlimited number of files can be uploaded to this field.
2 MB limit.
Allowed types: jpg jpeg gif png txt doc docx xls xlsx pdf ppt pps odt ods odp zip gz bz2 xz patch diff wav ogg flac ogv mp4 qtz.