What happens when you miss a beat?
Try tapping along to a song, skip one beat, then carry on. The skipped beat leaves a mark in the timing chart. Whether it changes the tempo depends on how you measure it.
Try the instrumentSix taps at the workbench
Choose Try a missed beat in the demo. The built-in recording has six taps, with the first at zero milliseconds. Taking the difference between each pair of neighbors gives five intervals.
| Tap | Time (ms) | Gap (ms) |
|---|---|---|
| 1 | 0 | — |
| 2 | 500 | 500 |
| 3 | 990 | 490 |
| 4 | 1500 | 510 |
| 5 | 2500 | 1000 |
| 6 | 3000 | 500 |
The fifth tap arrives a full second after the fourth. Average all five gaps and you get 600 ms, or 100 beats per minute. Sort those same gaps and the middle value is 500 ms. That gives 120 BPM, which agrees with the four shorter intervals. The chart keeps the full one-second gap visible.
From a button press to a Blyx vector
The browser takes a timestamp from its monotonic clock when you activate the pad. It keeps the latest six timestamps, rounded to milliseconds, and passes them as a numeric vector to a Blyx worker. Pointer taps and keyboard activations use the same input. The microphone is never needed.
fn gap(taps: vector, i: i64) -> f64 {
at(taps, i + 1) - at(taps, i)
}Only differences matter. Adding ten seconds to every timestamp still produces the same intervals. A non-increasing timestamp starts a fresh phrase, as does a gap longer than 2,000 ms. A gap of exactly 2,000 ms still counts. This makes the instrument suitable for tapping beats down to 30 BPM. To follow slower music, tap subdivisions or change the cutoff in the source.
Finding the middle without sorting
For each candidate interval, the Blyx function middle counts how many values fall below it and how many equal it. In the sample, one gap is shorter than 500 ms and two are exactly 500 ms. With positions numbered from zero, 500 therefore occupies positions one and two. Position two is the middle of five.
When the window contains an even number of intervals, Blyx averages its two middle values. A 450 ms gap followed by a 550 ms gap gives a 500 ms period. The final division converts the period to beats per minute.
let low = middle(taps, start, end, (count - 1) / 2);
let high = middle(taps, start, end, count / 2);
let period = (low + high) / 2.0;
println!(period);
println!(60000.0 / period);Here the window is deliberately small. A scan compares at most five candidates against five intervals for each middle position. The web worker runs the same Blyx program as the downloaded example. The web interface supplies timestamps and draws the numbers that program prints.
Hear where the estimate changes
Tap six times at a steady pace. Double your tapping speed and watch the shorter bars appear. With a full window of five, three shorter intervals move the median into the faster group. The delay is the price of ignoring a single unusual gap. If you consistently tap every other beat, the instrument gives half the song’s tempo. It measures the pulse you supply.
Reproduce the reading locally
Install the Blyx CLI, download the example and run it in a terminal. The first three lines are the interval count, the median in milliseconds and the tempo in BPM. The remaining lines are the intervals in arrival order.
blyxc run tap-tempo.blyx
5
500
120
500
490
510
1000
500For a second experiment, change the input in main to [0, 500, 3000, 3750]. The 2,500 ms pause clears the first phrase. The final two taps give one interval of 750 ms, or 80 BPM.