Try to fix background glitching over long periods of time
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user