Skip to content

warp-mathAn integral, made visible, made audible.

The math behind tempo maps and warp markers, taught in code.

The one idea

Tempo is a rate. "120 BPM" means beats arrive at 120 per minute — 2 per second. If musical position is β (beats) and audio position is t (seconds), tempo is the derivative of one with respect to the other:

dβdt=BPM60(beats per second)

We almost always want the other direction — given a beat, what second is it? — so we flip the fraction and integrate. Integrating a rate recovers the total:

t(β)=0β60BPM(b)db

That integral is the whole subject. A warp map is this function from beats to seconds; a warp marker is a single (β,t) point that pins the two together. Everything else — snapping, playback, stretching, drift — falls out of evaluating or inverting this integral for different shapes of BPM(b).

Four shapes of BPM(b)

Shape of tempoThe integral becomesThe warp map looks like
Constant BPM=Kt=(60/K)β (constant rule)a straight line
Piecewise-constant (what beat_this gives)a running sum of rectanglespiecewise-linear, kinking at each marker
Linear ramp (accelerando)t=(60/s)ln(BPM(β)/b0) (closed form)a curve — a logarithm
Curved (ease in/out, BPM=b0+Δ(β/L)k)no closed form — integrate numericallya curve with no simple equation

The last row is the payoff. For general k the antiderivative of 60/(b0+Δ(b/L)k) has no elementary form — so you stop solving by hand and evaluate the integral numerically with the trapezoidal rule. k=1 recovers the linear ramp exactly; k>1 eases in; k<1 eases out.

The same integral underlies all four; only the difficulty changes. The chapters work through them in order.

The round trip

A live BPM readout is the derivative of the warp map coming back around:

BPM(β)=60dβdt=60dt/dβ

Each map's bpmAt(β) is that derivative, evaluated analytically where a formula exists. The test suite confirms the round trip numerically across all four regimes.