There are a few ways to implement pitch tracking. Time-Domain, Frequency-Domain, and Spectral/Temporal approaches.
Time-Domain approaches estimate the period of a signal and inverts the value to get a frequency. For simple waveforms, measuring zero-crossings work for this. For more complex waveforms, compare a segment of the waveform to another segment and account for a “trial” period.
Frequency-Domain approaches work better for polyphonic sounds. Utilizes an FFT and a peiodogram to convert a signal to an estimated frequency.
Spectral/Temporal approaches, track pitch in both the Time and Frequency Domains