Repository navigation
fix(tuner): move pitch detection off the audio thread - #306
Merged
Merged
Conversation
The tuner ran its pitch search inside the JACK callback once every 4096 samples (~3.5M ops plus readout allocations), blowing the block budget and causing xruns while the tuner was open. The RT side now only pushes samples into a lock-free queue; TunerHandle drains it and analyses on the GUI thread. Also fixes detection accuracy: - YIN difference function replaces AMDF, which favoured long lags and read e.g. 110 Hz as 55 Hz - octave numbers below C4 were one too high (truncating division) - floor lowered from 50.1 Hz to 30 Hz so bass low E/B are readable; input above 48 kHz is averaged down to keep the window long enough - parabolic interpolation removes the ~5 cent integer-lag error on high notes
OpenSauce
marked this pull request as ready for review
November 28, 2026 17:54
OpenSauce
enabled auto-merge (squash)
November 28, 2026 17:54
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.
Closes #240
Problem
With the tuner open, the standalone xruns constantly. The output is silenced, so you hear nothing wrong, but the JACK xrun counter climbs.
The tuner ran its pitch search inside the audio callback. Once every 4096 samples, one callback did roughly 3.5M operations and allocated memory for the readout (
format!for the note name,Arc::new, and dropping the oldArc). Measured in release:At 96 kHz that callback missed its deadline every time; smaller buffers or a Pi make it worse. The existing no-alloc test stopped just short of 4096 samples, so it never ran the search.
Fix
Tuner::processonly pushes input samples into a lock-free crossbeamArrayQueue. When the queue is full, the oldest sample is dropped. The worst case per callback is now about 0.002 ms.TunerHandle::get_tuner_infoempties the queue and runs detection there. The GUI already polls it every 20 ms while the tuner is open.TunerHandle::reset()runs when the tuner opens, so leftover samples from the last time it was open don't produce a stale first reading.arc-swapfromrustortion-core, which no longer uses it, and corrected the stale engine → GUI line in CLAUDE.md.Detection accuracy fixes
These bugs existed before this change. Fixing them first required working out what the tuner was actually reading.
freq_to_noteused integer division that rounds toward zero. It now usesdiv_euclid.Readings for harmonic-rich test tones, B0 through C6, at 48, 96 and 192 kHz are all within 0.1 cent and name the right octave.
Testing
tuner_does_not_allocateinno_alloc.rsdrives the engine well past the analysis window. Before the fix it failed with 16 allocations.make lintandmake test