In a temperate musical octave, there are 12 possible sounds. However, in a certain melody, usually, only 7 of them are used. When you see, for example, "Symphony...in Do major", you should expect that it is based on the white piano keys only. When using others scales, like for "Symphony... in Re#", some of the white keys will be replaced by some of the black keys.
Let's see the 12 keys in one piano octave:
- Do (C),
- Re (D),
- Mi (E),
- Fa (F),
- Sol (G),
- La (A),
- Si (B)
In a temperate scale, each of the 12 notes have frequencies that are in a geometric progression. Each one has a frequency that is the frequency of the previous one multiplied with 12'th root of 2. This assures that after 12 notes we will get twice the initial frequency, that is the "octave" interval. For example, after 12 semitones (notes), starting with Do3 we will reach 2*Do3 = Do4.
Because of this 12'th root of 2 ratio, Fa# = Do * sqrt(2) (squared root of two). This irrational number is not close to any small integer fraction and this makes these notes to sound very dissonant when played together. Other intervals approximates very well some small integral fractions (4/5, 2/3, 5/6,...) and sound good together.
Small fractions approximates for temperate scale can be:
Do = 1 * D
Re = 9/8 * Do
Mi = 5/4 * Do
Fa = 4/3 * Do
Sol = 3/2 * Do
La = 5/3 * Do
Si = 15/8 * Do
DO = 2 * Do
When playing in the Do major scale, the melody is based on the fundamental chord Do:Mi:Sol. What is interesting about this chord is that the notes has frequencies that are proportional with 4:5:6. In the temperate game, the frequencies are not exactly proportional, but they are very close. This means that there is a frequency X so that Do=4*X, Mi=5*X, Sol=6*X. Actually this X is the frequency of the Do that is 2 octaves below our chosen octave. This explains why Do:Mi:Sol sounds a lot like a lower Do. This ratio happens for the fundamental chords of all the major scales!
It seems that the brain need to anchor itself in a certain fundamental note (denoted by the fundamental chord) in order to follow a certain music progression. There is also a "serial" music that tries to use all the 12 sounds for a melody, with limited success from what I know.
The "perfect fifth" interval (Do:Sol) has a frequency ratio of 2:3 - in a temperate scale this is only approximate. This makes this interval to sound so harmonious, so that even untrained ear could notice it (like in bing-bang). Actually "fifth" is misleading, the "perfect fifth" actually means 7 semitones, that approximates very well the 2:3 ratio from the "natural" scale. Violin playing solo (without piano) tends to use the "natural" scale, using exact integer ratios instead of temperate approximations.
If we take 3 octaves, starting with Do1 until Do4, we will have these harmonics:
Do2=2*X (octave from Do1)
Sol2=3*X (half of Sol3)
Do3=4*X (octave from Do2)
Sol3=6*X (3/2 of Do3)
So when you hear a song in Do major, the fundamental notes are multiple of a Do with 2 octaves below. This has some physical consequences: playing 2 notes will result in summing and subtracting their frequencies; umming up and subtracting these notes that are integer multiple of X will result also in integer multiple of X. This is because if a and b are integers: a*X+b*X = (a+b)*X ; a*X-b*X = (a-b)*X are still integer multiple of X. Other combinations, like Do+Fa# = X+sqrt(2)*X = (1+sqrt(2)) * X will create many combinations that are not integer multiple of X. Those many combinations sound dissonant and are not used in music (except for special artistic effects).
More important seems to be the wavelength of there notes. When we choose the notes 1*X, 2*X, 3*X, 4*X, 5*X, 6*X, their wavelength are respectively l, l/2, l/3, l/4, l/5, l/6. Such configuration makes them all resonate with an ear resonator that is tuned for wavelength l. When we play frequency X, usually we will produce other harmonic frequencies like 2*X, 3*X, 4*X, 5*X, 6*X, and the ear has a structure that permits to identify all these frequencies like a single sound (of frequency X).
Music has some mathematical and physical constraints that have to be respected in order to create harmony. Within those rules and based on them, composers are able to create a "language" and "stories" that sound harmonious and can transmit emotions through music.
P.S. I don't even play any musical instrument, these are only from my personal research, use it with care!