Replace threshold-based latency calibration with MLS/cross-correlation#86
Open
fan-droide wants to merge 3 commits into
Open
Replace threshold-based latency calibration with MLS/cross-correlation#86fan-droide wants to merge 3 commits into
fan-droide wants to merge 3 commits into
Conversation
Replaces the threshold-based AudioWorklet peak-detector with the MLS/cross-correlation <latency-test> component. Key changes: - Delete LatencyProcessor.js (old threshold detector) - Rewrite LatencyController.ts: getUserMedia -> set audioContext + inputStream on the element -> listen for latency-result / latency-complete - Use main audioCtx (not a fresh context) -- same sink, sample rate, outputLatency as the recording pipeline - Fix formula bug: use event.detail.mean (full round-trip) instead of roundtrip - outputLatency * 1000 - Race-safe: _calibrating = true set before first await; stale-element guards in all event handlers; cleanup scoped to el to prevent a rejected async operation from clobbering a newer calibration run - Reliability gate: only commit calibration if all 3 runs are reliable Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fan-droide
pushed a commit
to idsinge/latency-test-examples
that referenced
this pull request
Jun 26, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add if (this._latencyEl !== el) return guard in el.start() catch block — same pattern as all other async paths, prevents a late rejection from clobbering a newer calibration run - Remove unused _hostView field and its HostView import - Simplify _cleanupLatencyTest with optional chain - Rename catch (err) to catch (_err) in startCalibrate — error already logged upstream before rethrow Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Replaces
LatencyProcessor.js(threshold/peak-based AudioWorklet detector) with<latency-test>— a maintained Web Component that measures browser round-trip audio latency using an MLS signal and cross-correlation.Primary changes
LatencyController.tsrewritten to use the<latency-test>element inaudioworkletmode, using the mainaudioCtx— closer to WAM Studio's recording path than the original fresh-context approachLatencyProcessor.jsdeleted — replaced by the component@adasp/latency-test@1.2.1added topackage.json(MIT licence)Behaviour improvements
roundtrip - outputLatencyManual verification
Tested calibration flow (mic permission, stop/retry, repeated calibrations, reload persistence) in Firefox and Chrome.
self.crossOriginIsolated === trueconfirmed in both browsers on the live demo.Live demo (fork)
https://charming-paletas-c95a3f.netlify.app
Background notes
Full investigation: demos/wam-studio/NOTES.md in idsinge/latency-test-examples