How BeatScope Detects Key and Tempo
In short: we compute tempo from an onset envelope and its autocorrelation, key from a chromagram correlated against Krumhansl–Schmuckler profiles, and the beat grid with dynamic programming. Everything runs offline, on-device. Here's exactly how, and why we chose these methods.
When we built BeatScope, the goal sounded simple: read three numbers off any track — BPM, key and energy — in seconds and without the internet, and do it accurately enough for DJs to trust in a live mix. Behind that "simple" sits classic digital signal processing. Here's our pipeline, honestly, step by step.
How we detect tempo (BPM)
Tempo is periodicity in a track's energy flow. We don't "listen for the kick" directly — we look for regularity in the moments when something happens in the sound.
- Spectral flux → onsets. We measure how much the spectrum changes between frames. Sharp energy jumps are onsets (kick, snare, synth attacks). From them we build an onset envelope.
- Autocorrelation. We autocorrelate that envelope: the lag where the signal most resembles itself is the beat period.
- Comb estimation of multiple periods. We check not only the base period but its multiples (½, 2×), so tempo isn't confused with its harmonics.
- Octave folding + range prior. We fold candidates into a
60–180 BPMrange and gently prefer values typical of dance music — which makes the classic "174 vs 87" error rare. - Median smoothing. The final value is median-smoothed so single spikes don't throw the estimate off.
For the beat grid itself (where beats sit on the waveform) we use a dynamic-programming approach in the spirit of Dan Ellis's beat tracker[3]: it finds a placement of beats that both lands on onsets and keeps a steady interval — so the grid doesn't drift across the track.
How we detect musical key
We estimate key from how energy is distributed across the 12 pitch classes — a chromagram.
- Chromagram. We fold the spectrum (~
55–2000 Hz) into 12 pitch classes and accumulate with a leaky integrator of about8 secondsmemory — giving an averaged "note profile" of the track. - Correlation with Krumhansl–Schmuckler profiles. We compare that profile with 24 reference key profiles (12 major + 12 minor). The best match is the key.
- Mapping to Camelot. We return the result both in notes and in Camelot code — so harmonic mixing becomes arithmetic on the wheel.
This traces back to libKeyFinder by Ibrahim Sha'ath[2] and to Carol Krumhansl's work on key perception[1] — the same method studio key detectors use. We ported it into a pure on-device computation, with no server round-trip.
Why offline and on-device
No uploading tracks to a server: analysis runs locally. That's faster (no network in the loop), more private (your music never leaves the device) and it works in a club with no internet. And it's fundamentally free — there's no cloud compute to pay for, because there isn't any.
How we score energy
"Energy" is the sense of a track's drive. We estimate it from loudness (RMS) and spectral balance and map it to a simple scale, so you can order a set by rising intensity right in the library.
Accuracy and honest limits
On material with a clear rhythm section and stable tonality, the estimates are reliable. Where the method is objectively harder:
- Atonal or very dense harmony — the profile blurs, key is less certain.
- Mid-track modulation — we return the dominant key, not every shift.
- Weak percussion / rubato — few onsets, so BPM is less stable.
- Octave tempo errors — folding and the range prior suppress them, but on edge-case genres it's worth a manual double-check.
We deliberately don't oversell it: BeatScope is a fast, accurate assistant, and on the tricky cases the final call is always the DJ's ear.
Summary
BPM — from onsets and autocorrelation with octave folding; key — from a chromagram and Krumhansl–Schmuckler profiles mapped to Camelot; beat grid — via dynamic programming. All computed on Mac and iPhone, offline, in seconds, for free.
Sources
- Krumhansl C. L. Cognitive Foundations of Musical Pitch. Oxford University Press, 1990.
- Sha'ath I. Estimation of Key in Digital Music Recordings. MSc thesis, Birkbeck College, University of London, 2011 (libKeyFinder).
- Ellis D. P. W. Beat Tracking by Dynamic Programming. Journal of New Music Research, 36(1), 2007.