Skip to content

fix(audio): heard clocks for song and guitar, measured not tuned - #22

Merged
mattromano merged 3 commits into
customfrom
fix/heard-clocks
Nov 10, 2026
Merged

mattromano merged 3 commits into
customfrom
fix/heard-clocks

Conversation

@mattromano

Copy link
Copy Markdown
Owner

What

Hit timing now uses the real delay until you hear the song and your guitar. It measures that delay instead of using hand-tuned offsets.

  • Song (stems, ASIO/exclusive): a song-only renderer bus whose clock includes output latency. The heard delay on ASIO4ALL measures 26–58 ms and is steady to ±1.5 ms over 3 min. The old path ran 130–180 ms and jumped 43 ms mid-run.
  • Song (native backing): getBackingPosition() returns the position you hear, not the end of the last rendered block.
  • Guitar: each input block is timestamped and placed using the device's capture latency. A new engine/PlayheadModel.h measures the playback rate, so practice speeds are handled.
  • Onset backdate: 525 samples, the detector's own measured lag. This replaces a 50 ms value that hid other latencies.
  • Test aid: SLOPSMITH_TEST_LOOPBACK=1 feeds the output back as the input for end-to-end timing runs. It's off in normal use.

Results

The end-to-end loopback median is +27/+28/+27/+28 ms at ASIO 128/256/512/1024, and that constant is the chart vs the stem. It's +28 to +33 ms at 0.5–0.8× speed.

Tests

  • engine_units: renderer_bus and playhead_model
  • onset_lag
  • heard-clock-wiring

Play-tested on the local packaged build.

Stacked after #21; once #21 merges this diff is only the two latency commits.

🤖 Generated with Claude Code

mattromano and others added 3 commits November 6, 2026 23:01
…f timed

Tone switch stall: LoadPreset loads each NAM/IR slot by path and then
applies its saved state, which loaded the SAME model a second time while
the slot was live. The audio callback froze ~0.75 s on every switch
(reproduced on ASIO: the renderer bus backed up to ~37k frames and then
dropped), heard as a hard glitch plus a song-delay jump. State restore now
skips a same-file reload (NAM and IR), and NAMProcessor::processBlock
try-locks the model so the audio thread never waits on a swap.

Verdict timing: a hit with no matched pick attack was stamped at the chart
time with no flag, so consumers read a measured 0 ms. Verdicts now carry
`timed` (true only when an onset was claimed), exposed by getNoteVerdicts
and getSourceNoteVerdicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Song (stems, ASIO/exclusive): a second renderer bus carries the song alone,
each push anchored to its AudioContext frame; the output callback stamps its
start, so getSongBusClock() names the context frame reaching the DAC (output
latency included). Measured on ASIO4ALL: the heard delay is 26-58 ms
depending on buffer size and bus fill (steady to +-1.5 ms over 3 min), where
the old loopback path ran 130-180 ms and jumped 43 ms mid-run.

Song (native backing): getBackingPosition() returns the heard position (the
rendered block start reaches the DAC one output latency after its callback),
not the end of the last rendered block.

Guitar: every input block is stamped with its callback's start time; the
verifier places each sample from that stamp minus the device's capture
latency (reported input latency - one buffer, ASIO and JUCE WASAPI alike),
on a playhead model that measures the playback rate (practice speeds were
extrapolated at 1.0x) and filters IPC delay (fastest push wins). Rebuilt as
the JUCE-free engine/PlayheadModel.h.

Onset backdate: 525 samples (the detector's own lag, measured on synthetic
picks with a known attack: tests/onset_lag), replacing a 50 ms value tuned
from live medians that silently absorbed capture and display latency and was
wrong at any other sample rate.

Tests: engine_units renderer_bus (heard clock) + playhead_model (every
buffer/latency/rate config lands < 1 ms), onset_lag, heard-clock-wiring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SLOPSMITH_TEST_LOOPBACK=1 (duplex devices only, read once at start) feeds the
engine's own output back as its input, delayed by the device's reported
output + input latency: an ideal cable from output jack to input. With the
song's guitar stem soloed it measures the whole chain end to end. Measured:
median hit timing +27/+28/+27/+28 ms at ASIO 128/256/512/1024 (the constant is
the chart vs the stem) and +28..+33 ms at 0.5-0.8x. Off in normal runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattromano
mattromano merged commit 0d5e5bb into custom Nov 10, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant