0
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ this is no small problem. even if the input is monophonic (one note at a time, usually from a single instrument or voice) this is no small problem. and if it is polyphonic, a mix of an ensemble of instruments, it's a female canine. i dunno how Melodyne does it. if it is monophonic, you need a pitch detector and from that result you need to make a histogram of the detected pitches. from the notes most often played you must match that set to the set of notes of candidate key. and differentiating between relative major and minor (and other modes) with the same key signature is also hard. $\endgroup$ Sep 6 '19 at 4:50
  • $\begingroup$ You can infer the scale by looking at the intervals (not the individual notes but their "distance"). The intervals are like a signature for the scale and they can reveal if the scale is minor or major. Still, as RBW says, this would only be possible for a one-voice melody, possibly not even from an instrument as you would then have to also deal with timbre. ( @robertbristow-johnson I have a feeling that melodyne does it with something akeen to Prony's method (see 2:20. I've been losing sleep too :) ) $\endgroup$
    – A_A
    Sep 6 '19 at 8:50
  • $\begingroup$ well @A_A , you can only possibly infer the mode of the musical tune from looking at only the intervals. you won't know the difference between A minor or B minor or C minor. t's like running a signal through a differentiator. you lose the DC component. $\endgroup$ Sep 6 '19 at 18:21
0
$\begingroup$

Insert a tuner into the audio chain and take down the notes coming through. Use the circle of fifths to calculate the key as best as possible.

$\endgroup$
0
$\begingroup$

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.

-k

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy