Try to fix background glitching over long periods of time
Build and test / test (macos-latest) (push) Canceled after 0s
Build and test / test (ubuntu-24.04) (push) Canceled after 0s
Build and test / test (windows-latest) (push) Canceled after 0s
Build and test / apple-client (push) Canceled after 0s

This commit is contained in:
2026-09-24 13:31:16 +02:00
parent 186fe6dbb6
commit fb740bcfb2
7 changed files with 129 additions and 14 deletions
+8 -5
View File
@@ -177,6 +177,13 @@ public sealed class AudioEngine : IDisposable
catch (Exception exception) { Failure = exception; stop.Cancel(); }
}
// Drop each capture backlog to its buffer target. The consumer calls this after a stall it
// cannot catch up in place: one bounded gap instead of a queue that ratchets toward its edge.
public void ResynchronizeInputs()
{
foreach (LocalStream stream in Volatile.Read(ref routes).Local) stream.Input.Resynchronize();
}
private void Work()
{
long deadline = Stopwatch.GetTimestamp();
@@ -189,12 +196,8 @@ public sealed class AudioEngine : IDisposable
WaitUntil(deadline);
if ((deadline - Stopwatch.GetTimestamp()) * 1000.0 / Stopwatch.Frequency < -100)
{
// A stall this long cannot be caught up in place. Discarding only the schedule
// deficit would leave the producer backlog queued at a fixed offset forever and
// eventually overflow its ring, so drop back to the buffer targets instead: one
// bounded gap per stall rather than growing latency and feed drops.
deadline = Stopwatch.GetTimestamp();
foreach (LocalStream stream in Volatile.Read(ref routes).Local) stream.Input.Resynchronize();
ResynchronizeInputs();
}
}
}