The four stages
- Capture.
getUserMedia()opens the microphone and the Web Audio API delivers raw samples, typically 44,100 or 48,000 per second. - Window. Samples are collected into short overlapping blocks of about 2,048–4,096 samples (≈45–90 ms). Pitch is assumed to be roughly constant inside a block.
- Estimate the period. The block is compared with time-shifted copies of itself. The shift that produces the best match is the period T of the waveform. Frequency is simply f = 1 / T. This is autocorrelation; this page uses a normalised square-difference refinement in the family of the YIN and MPM algorithms, plus parabolic interpolation for sub-sample precision.
- Convert to a note. The frequency is mapped onto the equal-tempered scale, then the residual is expressed in cents.