Understanding Musical Key
A song's key defines the set of pitches (scale) and the tonal center (root note) around which the music is organized. A song in C major uses the notes C, D, E, F, G, A, B and tends to sound bright and resolved. The same notes in A minor (the relative minor) produce a darker, more melancholy feel. Key is one of the most important structural properties of a piece of music, influencing its emotional character, harmonic movement, and compatibility with other tracks. For visualization, key detection enables color and mood mapping: a song detected as being in a minor key might use cooler, more subdued color palettes, while a major key track might receive warmer, brighter visual treatment.
Chroma Features and Pitch Class Profiles
Key detection algorithms start by extracting chroma features (also called pitch class profiles or chromagrams) from the audio. A chromagram reduces the full frequency spectrum to just 12 values, one for each pitch class: C, C#, D, D#, E, F, F#, G, G#, A, A#, B. All octaves are folded together, so middle C and the C two octaves above both contribute to the same bin. The chromagram is computed by mapping FFT bins to their closest pitch class and summing the energies. Averaged over the duration of a song, the chromagram reveals which pitch classes are most prominent. This 12-dimensional vector serves as a fingerprint of the song's harmonic content and is the primary input to key classification algorithms.
Key Profiles and Classification
The most widely used approach to key detection is template matching against key profiles. Researchers like Krumhansl and Kessler established psychoacoustic profiles that describe how strongly each pitch class is perceived in each of the 24 possible keys (12 major, 12 minor). The algorithm computes the correlation between the observed chromagram and each of the 24 key profiles. The key whose profile best matches the observed chroma distribution is selected as the detected key. More advanced methods use hidden Markov models or neural networks to track key changes over time, identifying modulations and tonicizations. The Krumhansl-Schmuckler algorithm remains a strong baseline, but machine learning approaches trained on annotated datasets now achieve higher accuracy on diverse genres.
Mapping Keys to Colors
The association between musical keys and colors has a long history, from Scriabin's clavier a lumieres to modern synesthesia research. While there is no universal mapping, several traditions exist. Newton associated the seven notes of the scale with seven colors of the visible spectrum. Scriabin created an elaborate key-to-color system where C was red, G was orange, D was yellow, and so on through the circle of fifths. Modern visualizers often use the color wheel mapped to the circle of fifths, creating smooth chromatic transitions between related keys. Zeltor Labs uses key detection to influence the base color palette of a visualization, creating a harmonic relationship between what you hear and what you see. The specific mapping can be customized, but the defaults are designed to feel emotionally coherent.
Beyond Key: Harmonic Analysis
Key detection is just the beginning of harmonic analysis. More sophisticated systems track chord progressions, identifying the specific chords played at each moment in the song. A chord progression like I-V-vi-IV (extremely common in pop music) can drive visual transitions: the tonic chord feels stable and centered, the dominant creates tension, and the relative minor adds emotional depth. Harmonic rhythm (how frequently chords change) provides another layer of information for visual pacing. Sections with rapid harmonic movement might receive more visual activity, while sustained chords allow visuals to breathe. These deeper harmonic features enable visualizations that respond not just to rhythm and energy but to the tonal narrative of the music itself.