Repository navigation
Conversation
jucePlayer set its interpolation anchor to performance.now() after the awaited getBackingPosition() resolved, so every anchor was stale by the IPC round trip (plus any renderer main-thread delay before the await resumed). With latency jitter and the engine's block-quantized position the interpolated clock stepped backwards on many polls. Take t0 before the call and anchor the sample at the midpoint of the round trip. Fold small errors in by slewing the clock up to 10% fast or slow instead of stepping, keep it monotonic between repositions, ignore slow replies unless they show a real discontinuity (>= 250 ms snaps), and drop poll replies that were in flight across a seek, pause or rate change. The route hand-off in juce-audio.js re-anchors through the same _setAnchor() helper. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: odntht <odntht@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
What was wrong
static/js/transport.js(jucePlayer._startPolling, lines 128-139 ateef58c8) pollsgetBackingPosition()every 100 ms in desktop/JUCE mode and interpolates between polls:_pollAtis taken after the await, so every anchor is stale by the IPC round trip plus any delay before the renderer main thread resumes the await. The engine's position is also block-quantized (~10.7 ms at 512/48k). Each new sample therefore lands a few ms to tens of ms behind the extrapolation, and the clock that the highway,_audioTime(), plugins andsong:position-changedread can step backwards on a poll. How often depends on IPC latency: rarely on a fast Linux box, more often with slow or jittery IPC (see measurements). An in-flight poll reply that crosses aseek()also overwrites the new position with the old one.The fix
t0before the call. The engine reads its position somewhere inside[t0, t1], so anchor the sample at the midpoint._setAnchor(). It bumps a generation, so a poll reply that was in flight across it is dropped.juce-audio.jsuses it for the HTML5 to JUCE hand-off instead of writing_pos/_pollAtdirectly.This stays consistent with #1117. That PR smooths the highway render clock downstream of
setTime(). This PR fixes the source clock in JUCE mode, so #1117's loop gets a monotonic, unbiased input and only rarely needs its 50 ms snap. The two PRs are independent and don't touch the same files.Evidence
New test
tests/js/juce_transport_clock.test.jsruns the realjucePlayerobject (extracted fromtransport.js) against a simulated engine, IPC and a 60 Hz rAF sampler in virtual time. The engine position moves in 512-frame blocks. The engine reads its position at a random point inside each IPC round trip. The test asserts: no backward steps, a stddev of Δchart/Δwall below 0.08, max error below 30 ms, no bias under a constant 30 ms round trip, correct seek with a poll in flight, and a snap on an engine-side jump.Same harness, 60 s × 5 seeds per scenario,
origin/mainvs this branch:These numbers come from a model of the IPC, not from the live app.
Measured in the real desktop app (Linux)
Same desktop build (desktop
origin/main, real JUCE addon, ALSA HDMI 0 at 48 kHz / 256). The probe:loadBackingTrack;jucePlayer.play();jucePlayer.currentTimeon every rAF for 60 s (3602 frames);getBackingPosition()probe as the engine reference.3 launches per cell, main → branch:
Honest reading: on this Linux box the
getBackingPositionround trip is well under 1 ms, so main barely steps backwards (1 step in 3 minutes). The real-app gain here is a ~40% smoother per-frame clock, with no backward steps and no measurable bias. The larger backward-step counts in the model table need slower or jittery IPC, as on a loaded Windows machine. I couldn't measure those systems.To reproduce:
node --test tests/js/juce_transport_clock.test.js. For the main-vs-branch table, point the harness'ssimulate()at either version oftransport.js.Tests
npm run test:js: 1212 pass, 0 fail.🤖 Generated with Claude Code
Summary by CodeRabbit