DJ Key and BPM Analyzer
Operator: Abdulla Al Fahad. How tools are built and checked
Harmonic mixing needs two numbers for every track: its tempo and its key, written in a notation your decks understand. This page reads a folder of up to 500 tracks and fills a table with BPM, the key in Camelot and Open Key codes, a 1 to 10 energy score, and, for a selected track, the other tracks in the folder that will mix with it.
Key features
- Up to 500 files of 15 minutes each, analysed up to three at a time in background workers so the page stays responsive
- BPM from a spectral-flux tempo estimator, with Half and Double buttons per track for octave errors
- Key from a tuning-corrected chroma and the 24 Krumhansl-Kessler profiles, shown as a name, a Camelot code and an Open Key code
- An energy score from 1 to 10 that is labelled as a proxy: loudness and onset density, not a perceptual measure
- A sortable table, a CSV download, and MP3 copies with TBPM and TKEY frames written, one by one or as a ZIP
How BPM, key, Camelot codes and energy are worked out
Camelot numbers the 12 minor keys 1A to 12A and the 12 major keys 1B to 12B round the circle of fifths. C major is 8B, and its relative minor, A minor, is 8A. Open Key counts the same wheel starting from C major at 1d, with d for major and m for minor, so A minor is 1m and E minor, which is 9A on the Camelot wheel, is 2m.
TBPM is stored as the BPM rounded to a whole number in text form, and TKEY as the key in the style you choose: Camelot (8A), Open Key (1m) or the musical spelling the ID3 specification describes (Am, F#, Bb). Frames other than TBPM and TKEY in the file's existing ID3v2 tag are carried over unchanged.
How it works
Each file is decoded to mono at 22,050 Hz after its length is read from the file's metadata, so a track over 15 minutes is refused before it is decoded. A worker then runs the tempo and key analysis, and measures the track's RMS level in dBFS and how many onsets per second the onset envelope contains (local peaks above the envelope's mean plus one standard deviation, at least 0.1 s apart). The tempo is kept only if the onset envelope pulses at that tempo at least 0.15 times as strongly as its own average level (about 1 for a kick drum or click track, under 0.1 for a sustained tone); weaker than that, the track is reported without a BPM.
Energy is 1 plus 9 times a blend of loudness and busyness: 60% from the RMS level, mapped from -30 dBFS to -6 dBFS, and 40% from onsets per second, mapped from 0 to 6. A loud track with a dense beat scores 9 or 10, and a quiet ambient piece scores 1 or 2.
When this helps
- A DJ drops a 90-track crate on the page before a gig, sorts by Camelot code, and sets the tracks in each 8A to 10A run in BPM order.
- A track analysed at 64 BPM that is clearly a 128 BPM house record gets its Double button pressed, and then appears next to the other 128 BPM tracks in the sort.
Opening a file
- Choose files, or a whole folder; non-audio files in the folder are skipped and counted.
- Let the queue run; each track's row appears when its analysis finishes, and Cancel stops the rest.
- Click a column heading to sort by name, length, BPM, key (in Camelot order) or energy.
- Select a row to see tracks that mix with it, and press Half or Double on any track whose tempo is an octave off.
- Download the CSV, or pick a TKEY style and download tagged MP3s.
Example
Two tracks from a folder, as the table shows them
Track A: 124 BPM, A minor. Track B: 126 BPM, E minor.Their rows and the mix suggestion
Track A: 124 BPM, A minor, Camelot 8A, Open Key 1m.
Track B: 126 BPM, E minor, Camelot 9A, Open Key 2m.
Selecting A lists B as one step on the wheel with a 1.6% tempo gap. Tagging A with Camelot style writes TBPM 124 and TKEY 8A. For a track at 127.6 BPM the TBPM frame holds 128.Limits
Key estimates are least reliable on drum-only tracks, atonal material and tracks that modulate; a track whose key correlation margin is small can land on its relative major or minor.
Tempo can come out at half or double time, and a track with a drifting live tempo gets one average figure. A '?' beside the BPM marks a low tempo confidence.
A track with no repeating pulse, such as a sustained pad, a drone or a spoken-word recording, gets a key but no BPM: the row says "No steady tempo found" instead of an invented number, and it is left out of mix suggestions and BPM tagging.
- The table sorts on one column at a time, so for a set list sort on key, which runs in Camelot order (1A, 1B, 2A, 2B and so on), and read the BPM column within each key.
- Write the TKEY in Camelot style for DJ software and in musical style for tag editors that expect the ID3 convention.
Common errors and how to fix them
- The track is 18 minutes long; this tool takes up to 15 minutes
- Cut the track, or analyse a shorter edit. The limit exists because the whole track is held in memory while it is analysed.
- The track is silent
- The file decoded to samples under the noise floor, so there is nothing to analyse. Check that it plays.
- There are no analysed MP3 files to tag
- Tags are only written to MP3 files, and only to tracks that finished analysing with a tempo.
What the tagging changes and what it leaves alone
The page reads the ID3v2 tag at the start of the MP3, replaces or adds TBPM and TKEY, writes the tag again with a little padding, and joins it to the original file's audio bytes, which are copied from the first byte after the old tag. The ID3v1 tag at the end, if there is one, is part of that audio range and is kept. The tagged file is a new download; the original is never opened for writing.
Rewriting the tag is where a few frames can be lost: frames with compression or encryption flags cannot be carried between ID3 versions and are dropped. The MP3s you tag stay at the ID3 version they have, with v2.2 tags written as v2.3.
Frequently asked questions
How does this differ from the BPM Detector on this site?
The BPM Detector takes up to 30 files of up to 30 minutes and adds a tap-tempo pad, a steadiness figure and a chroma chart, with Camelot codes and a CSV. This page takes up to 500 files of up to 15 minutes and adds Open Key codes, the energy score, mix suggestions across the folder and TBPM and TKEY tags in MP3 copies. Both run the same tempo and key estimators, so one track gets the same tempo and key on either page.
Is the energy score the same as another program's energy rating?
No. It is a simple measure from loudness and the number of onsets per second, and it does not use any other program's method, so do not compare it with ratings from other software.
Why does a tagged file show 128 when the table says 127.6?
TBPM holds a whole number, so the tempo is rounded when it is written. The table and the CSV keep the tenth.