Repository navigation
Tune to a fraction of a cent: a new pitch detector and a ±3 cent window - #8
Merged
Merged
Conversation
The tuner heard the strings through the browser's voice processing, called ±8 cents in tune, followed a peg about 0.6 s late, and read a string 5–20 cents flat while the one tuned before it still rang. Capture (useAudioCapture): - echo cancellation, noise suppression and automatic gain are off: they faded sustained notes out as noise and kept moving the level; - the AudioContext is created within the tap that starts it, so Safari does not keep it suspended; - the noise gate follows the room's own noise level, down to −60 dBFS, so a quiet instrument is still heard; - every tick sends a frame, and the analysis and the low-pass filter are aimed at the string being tuned. Detector (new, src/tuner/detector.ts, replacing pitchy): - the McLeod Pitch Method on a decimated window with the same overlap at every lag, in double precision through one FFT pair; - then a narrow-band phase measurement of the fundamental and the 2nd harmonic, as a strobe tuner does: another string ringing a third or a fourth away no longer pulls the reading; - the share of energy at the pitch and its octave, which tells a real string from a phantom (B3 and E4 together repeat like an E2); - the spread between the two harmonics, which tells noise from a blend of strings. Engine: - in tune within ±3 cents (and until ±4), after at least 3 readings; - readings up to a fifth either way; a reading an octave up is the 2nd harmonic; tuned strings still ringing and phantoms are ignored; - a 5-reading median, and a needle that follows a turning peg 130–220 ms behind, trusting each reading by how well its harmonics agree; - a string that hovered just off now needs its full time in tune (it was confirmed at once), and choosing a string once all were in tune keeps listening; - time in tune: guitar 1 s, bass 1.2 s, ukulele 0.7 s, violin 0.6 s. Android declares MODIFY_AUDIO_SETTINGS for the WebView's audio capture. The virtual instrument gains room noise, stiff strings and gliding notes; the tests cover accuracy, noise, other strings ringing, phantoms, a phone microphone on a bass and a turning peg (287 tests). The README's signal-processing section is rewritten.
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.
Why
The tuner worked poorly in real use:
getUserMediawas called with the defaults: echo cancellation, noise suppression and automatic gain all on. Tuned for speech, they fade a sustained note out as if it were noise and keep moving the level.MODIFY_AUDIO_SETTINGS.What changed
Capture (
useAudioCapture)setTarget). Changing tuning no longer restarts the microphone.Detector (new:
src/tuner/detector.tsandsrc/tuner/fft.ts, replacing pitchy)Engine (
src/tuner/engine.ts)Measured on the virtual instrument
Testing
npm test: 287 tests, up from 243.npm run lint,vue-tsc -bandvite buildare clean.For the reviewer
CentsMeterdraws ±ACCEPT_CENTS, so the band is now ±3 %.pitchyis removed frompackage.json.