What it is
A tuner built round a 3D acoustic guitar headstock. Pick a string, turn its peg and listen: the note bends as the peg turns, the string shakes, and a paper meter shows how many cents it is from the target, with Tighten or Loosen until the needle sits in the green. Five tunings (Standard, Drop D, Half Step Down, Open G, DADGAD). A microphone mode tunes a real guitar with the same meter. It is a companion to the Guitar Tuner Android app and links to it.
Engineering decisions
- Everything is modelled in code, no model files: a lofted C-shaped mahogany neck, a radiused rosewood fretboard with binding, nickel frets on the 64.8 cm scale, pearl dots (iridescent on the high tier), a bone nut with string slots, an extruded headstock tilted back 13 degrees with a gloss rosewood veneer, a torch inlay, a bell truss-rod cover and a volute. Each of the six tuners has a hex bushing, washer, a post with a string hole, the string wound round it and its cut end, and on the back a brass gear, a worm thread, shaft tabs, a ferrule and a cream button on a three-on-a-plate strip.
- Wood grain, pores and ribbon figure are painted on canvases at start-up and used as colour and bump maps; wound strings get a bump stripe for the winding. Light is a warm key with soft shadows, a cool rim and a
RoomEnvironment reflection baked once through PMREMGenerator, so nothing is downloaded. - Turning a peg drives both the 3D and the sound. The button turns 5.4 degrees per cent, the post turns 14 times slower, as through a real 14:1 worm gear. The string sound is the Karplus-Strong synth from the Guitar Tuner playable, rendered once at the target pitch; the peg then changes the ringing note through
playbackRate, so the pitch slides while you turn. - A real string vibrates too fast to show at 60 frames a second, so the vertex shader bends each string with its first three modes at a slower rate that rises with pitch, and adds a slow wobble whose depth follows how far out of tune it is, like the beats you hear when tuning.
- The microphone path is a YIN pitch detector (no dependency) on 4096 samples behind a low-pass filter, with raw input (no echo cancellation or noise suppression). The heard pitch picks the nearest string of the tuning and a light smoothing settles the needle. Audio never leaves the browser.
- Tunings, peg response, the hold-to-confirm timer, the meter maths and YIN are plain TypeScript with Vitest tests, including YIN reading the plucked-string synth to within two cents.
Performance
- Renders on demand: frames run only while a string rings, a peg eases, the glow breathes or the view coasts, and stop off-screen or in a hidden tab.
- The low tier halves the textures, drops shadows, clearcoat and iridescence and uses fewer segments.
- Shaders are compiled before the first frame and the page reports ready after two frames and the fonts.