fix: raise drift cap to 1s — stops constant resetting on jittery links

150ms cap was too tight for Iran relay (high jitter), causing constant
audio drops. Raised to 1s — packet bursts are absorbed smoothly,
drift reset only fires on real accumulation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-27 19:41:45 +04:00
parent 709ad1ba7d
commit 38ae62b542

View File

@@ -193,9 +193,14 @@ function playAudio(pcmInt16) {
const now = audioCtx.currentTime;
if (nextPlayTime < now || nextPlayTime > now + 0.2) {
// Behind or drifted too far ahead — snap to now + 40ms
nextPlayTime = now + 0.04;
const drift = nextPlayTime - now;
if (drift < 0) {
// Fell behind — catch up
nextPlayTime = now + 0.02;
} else if (drift > 1.0) {
// More than 1 second ahead — hard reset (real drift)
console.log('drift reset:', drift.toFixed(3) + 's');
nextPlayTime = now + 0.02;
}
source.start(nextPlayTime);
nextPlayTime += buffer.duration;