The quality of a note depends upon the waveform. Two notes of the same pitch and loudness, played from different instruments do not sound the same because the waveforms are different and therefore differ in quality or tone.
The same note from different instruments has different qualities because the sounds from instruments are never pure notes, i.e. of one frequency, the only exception being a tuning fork. Rather they consist of one main note which is predominant and other smaller notes called overtones. The main note or fundamental note is also referred to as the first harmonic and if it has a frequency f, the overtone with frequency 2f is called the second harmonic and the overtone with frequency 3f is called the third harmonic and so on. The sum of all the harmonics is the waveform and determines the quality of the sound.