Couldn't find my old program, but it was easy enough to recreate enough for the fundamentals. Disclaimer: I am NOT a music major! I do play a bit, mostly amateur gigs now.
First a bit of reference from Wikipedia:
Now, A4 on a piano (A above middle C) is defined as 440.0 Hz and is a standard tuning pitch. Notes in a Western scale are spaced 2^(n/12) apart going up from the root. To make things interesting, let's look at a C major chord starting at middle C (C4), so the notes are C4, E4, G4 (and C4 if we want the top note). A bit of math provides the pitches (frequencies) of each note using equal temperament:
Yes, since C5 is an octave above C4, I cheated on the last one and just multiplied C4 by two.
Now, we prefer to hear tones spaced by integer ratios or "even" intervals. If you look at ratios and such, eventually you find a base frequency from which all the notes are integer multiples. Being lazy, and already knowing the answer, I am going to do a bit of hand waving. Look at the multiples from C4 for the E4 and G4 notes in our chord:
Not integers, or even numbers that lead to integer ratios. Now the hand waving; rather than find a common factor (frequency), I know 1.25 and 1.5 lead to common multiples with integer ratios (5/4 and 6/4). If I plug those in, the new (prime, "p") frequencies are:
So the desired pitch, that sounds good to us, is an E that's a little low and a G that's a little high. This is "just" intonation. Musicians playing instruments that allow us to adjust pitch will alter those notes in the chord to make them sound prettier. Can't do that with a piano, alas.
Now, for musicians who are not mathematicians (or even a lowly engineer such as myself), what we see on a tuner are "cents". Remember there are twelve notes in a scale, logarithmicly spaced, and we define 100 cents between each note. The equation is:
# cents = 1200 * log2(P1/P2) where log2 is log to base 2 and P1 and P2 are our pitches (notes)
Plugging in our notes/pitches:
Note log(x)/log(n) = the log of x to base n
If you read the Wikipedia quote above, or look up a major chord in a music theory book, sure enough the third in a major chord needs to be about 14 cents low, and the fifth about 2 cents high, to create a pleasing sound. The theory and math work the same for other chords, though actual numbers will vary, natch.
Ain't it great when the theory and the reality actually meet?
HTH - Don