I'm looking for a precise way to compute the key of a song. BPM would be cool too. Analog is ok. I tried to approach it from the DFT angle, but got stuck and can't really put a finger on what's the issue. New perspective would allow me to get out of the mental hole I'm in.
Like others have said, doing this for a simple, clean, monophonic tune played using a sinusoid tone generator is one thing. Doing it for a complex mix is another. Simple sing-along note books ofte get it plain wrong (over and above simplifying things), so it is hard for humans, too.
For simple input, I would consider doing a STFT, assigning pitches to 440*2^(1/12) half-tone steps and «wrapping» all spectral peaks into a single octave for simplicity. By looking at thirds and fifths in that octave over time, you may be able to learn something sometimes. Sounds like a ML problem.
Then there is the «high-level-musical-interpretation» bit. I have heard about musical couples having heated arguments over if a song is F# major or Gb major. A song can move in complex ways between C major and A minor using basically the same set of notes but a different center of gravity, or it can modulate mid-way. A single chord can be interpreted as a C major with an E in the bass, or as a Em+5, depending on context and movement.