To generate the frequency of musical notes programmatically, the formula f(n)=440 * 2^{(n-n_0)/12} can be used, where A4 is set at 440Hz and n represents the note's assigned number. The discussion highlights the equal temperament tuning system, which balances consonance and dissonance across the chromatic scale. It also mentions the concept of natural scales, which provide optimal frequencies for specific keys but require retuning for each key change. The natural A scale aligns harmonics well, while the natural C scale serves a similar purpose for music in C. Ultimately, equal temperament offers a practical solution for most musicians, minimizing the need for frequent retuning.