The quality depends primarily on the waveform of the sound. The waveform of the sound emitted by a tuning fork is a simple sine curve.
But most bodies vibrate in a very complex manner.
Besides the fundamental frequency f, they consist of additional frequencies of 2f,3f,4f, etc.
These additional tones are called overtones or harmonics.
According to Helmholtz, the quality is determined by the number, relative frequency and intensities of the component simple tones of which a complex vibration is composed of.