This post shows that some very simplistic algorithms can’t unambiguously determine a key. But I don’t think it establishes that a more sophisticated algorithm could not. Key center is not just based on chords and notes in a scale. It’s based on the note/chord that seems like the place where the music is at rest, or at home. Many songs have non-diatonic chords, but it’s still fairly obvious what key they are in.<p>That said, there are examples where they key is ambiguous even to humans (e.g. Hey Joe [C G D A E], or Sweet Home Alabama [D C G] but disputed whether it’s in G or in D).
Related: When I was off work in December I used graph theory to find chord paths through keys:<p><a href="http://signalsandsorcery.com/" rel="nofollow">http://signalsandsorcery.com/</a><p>You can see from the graph that chords exist in multiple keys and you can move from one key to another via these shared chords known as 'pivot chords'
Talking about this stuff without saying <i>what kind of music you mean</i> seems a little silly. There is a reference to "one popular song", and it seems the author is thinking of pop music. But it seems most things that can be said about keys/chords in one genre/tradition/style, don't apply to others. And even within genres, things naturally evolve so that old rules no longer apply.
> A song could reasonably have a chord progression such as {Am, G, D, Am, G, Dm}, and the inclusion of both {D} and {Dm} would cause conflicts. Given that music theorists cannot agree on this stuff, there doesn't seem to be anything a computer can do that is better.<p>Whilst I'm no expert, I'm pretty sure we have hundreds of years of examples of borrowed chords [1] for music theorists to agree upon, so yes plenty of things a computer could do better (as per other comments).<p>[1] <a href="https://en.wikipedia.org/wiki/Borrowed_chord" rel="nofollow">https://en.wikipedia.org/wiki/Borrowed_chord</a>
One useful heuristic (at least, the one I usually go to first if I'm not sure what key a song is in) is that root of the final chord of the song is often the same as the root of the key. I suppose that probably works better for some music traditions than others. Also I believe some songs in a minor key sometimes end by converting the root chord to major.
In college I built a project that could reasonably well predict the key of a given piece based on the distribution of note usage. For example, most pieces written in a major key would have the highest usage of the root, and the dominant of a key.<p>This obviously has a number flaws, but worked remarkably well for western music written between 1600 and 1900.
I definitely thought this was going in a cryptography direction from the title. I actually kind of like the idea of composing music to generate a secret key :)
I am no musician. I heard quite a few musicians, with or without innate perfect pitch, can tell the keys in a chord, though maybe not to the 100% accuracy. For example, something like what the kid is doing in this video [1]. I am a bit surprised that this can't be done programmatically.<p>[1] <a href="https://www.youtube.com/watch?v=vXivZlPu0ms&t=175s" rel="nofollow">https://www.youtube.com/watch?v=vXivZlPu0ms&t=175s</a>