1. onset detection
Contents
Definitions
Count “one and two and three and four and” over a house track. Tap your foot on the numbers. Those taps mark the beats. Imagine a kick on each number and a hi-hat on each “and.” The instant the hat starts is its onset. It falls between two beats. Mute the kick on three and leave that count silent. There’s a rest in the music, and your foot still taps three. An onset detector marks where sounds start. Many beat trackers fit a pulse to those marks, or to a score of how strong each possible onset is. [1, 2, 3]
Finding a kick in the waveform
A digital recording stores samples, measurements of a sound wave’s amplitude at successive instants. Plot them against time and you have a waveform. Even a loud kick has positive and negative values that can average to nearly zero. Squaring the samples before adding them keeps both halves of the wave from canceling out and gives a measure of its energy. [1]
Look at a short stretch of samples at a time. This is the analysis window, and the samples in it form one frame. A short window lets the detector distinguish the kick from the quiet just before it. A common measure of level is root-mean-square (RMS) amplitude. Average the squared samples, then take the square root to return to the original amplitude scale. When this level jumps relative to recent frames, the detector records the time. Briefly ignoring further jumps keeps one kick from triggering twice. Measuring only low frequencies can help isolate the kick. [1]
Hearing the hi-hat over the bass
A quiet hi-hat over a sustained bass note may barely change the total level. What gets stronger are the high frequencies, the faster vibrations in the sound wave. A fast Fourier transform (FFT) measures how much of each frequency is present in a window. The result is a spectrum divided into narrow frequency ranges called bins. Repeating the calculation on overlapping windows gives a short-time Fourier transform (STFT). Draw the strengths over time and you get a spectrogram. [1]
Spectral flux measures change by adding up increases in strength across the bins from one frame to the next. The new hi-hat raises that score. So can vibrato, a slight wavering in the pitch of a held note, as the sound moves into a neighboring bin. Böck and Widmer’s SuperFlux algorithm checks whether nearby bins were already strong. That makes it less likely to mistake one wavering note for several new ones. [1, 4]
A complex-domain detector also uses each frequency component’s phase, its position in its own wave cycle. It predicts how the existing tones will continue, then measures how far the next frame differs. A new note can disrupt that prediction even when the total level changes little. [1]
When the app can report it
RMS and spectral flux are features, measurements made from the audio. At 48,000 samples per second, a window of 1,024 samples covers 21.3 milliseconds (ms). If the window is labeled at its midpoint, its last sample arrives 10.7 ms after that label. The hop is the step to the next window. A 256-sample hop takes 5.3 ms. Waiting one more frame to confirm a peak brings the delay to about 16 ms. That’s latency, the gap between the time you mark and the time you can report it. A file can store the earlier timestamp. A flash triggered by this detector has to wait. [1]