From effabafa234ffb05dfd69e400673a8a685420f45 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Thu, 17 Sep 2026 18:33:33 +0000 Subject: [PATCH] Fix AEC3 pitch drift by using the AudioContext's actual sample rate The requested AudioContext sampleRate is only a hint - some backends (notably Linux/PulseAudio) silently run at their own native rate anyway. AEC3 was told the requested rate (48000) regardless, so its internal frame timing drifted from the actual sample rate its buffers came in at, audibly heard as the echo's pitch descending with each repeat instead of being cancelled. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index b28287a..ed164da 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -7913,7 +7913,13 @@ function AppInner() { try { const audioContext = ensureAudioContext(); if (audioContext.state === "suspended") await audioContext.resume(); - const aec3 = await createAec3(SAMPLE_RATE, 2, 1); + // The context is *requested* at SAMPLE_RATE, but that constructor hint + // isn't guaranteed - some audio backends (notably Linux/PulseAudio) run + // it at their own native rate regardless. AEC3 must be told the rate + // its ScriptProcessorNode buffers are actually sampled at, or its + // internal frame timing drifts - audibly, as a progressively descending + // pitch on repeated echo. + const aec3 = await createAec3(audioContext.sampleRate, 2, 1); aec3Ref.current = aec3; audioPlayerRef.current?.attachAecRenderTap(aec3); setAec3Enabled(true);