aldus.nexus

Euclidean rhythms

Spread k beats over n steps as evenly as possible and out come the clave, the tresillo, the bossa nova and Balkan aksak. Bjorklund's algorithm does it with Euclid's remainders; each ring is one voice of synth drums.

Voices ring 1 is the outside; drag a ring or use the arrow keys to rotate it

Take this rhythm to the visualiser, Ribbon run as a course, or Oscilloscope music as the melody's beat.

The numbers

gaps between hits
Bjorklund rounds for every k
scheduling headroomms ahead of the audio clock

How it works

In 2004 Godfried Toussaint noticed that a timing algorithm from a particle accelerator, Bjorklund's, rebuilds dozens of traditional rhythms from just two numbers. Each step below uses the selected voice, …, and follows it as you change it. Related pages: RSA art draws the same i · k mod n circles as lines, Ribbon run makes a game of hitting beats on time (and can build a course from this rhythm), the Visualiser and Oscilloscope music can play it with the same drum synth, Tuner looks at the other half of music, pitch, and the How it works guide has the short version.

1As even as possible

Put n steps round a circle and choose k of them to hit. When k divides n the answer is obvious: every n/k steps. When it doesn't, some gaps must be longer than others, and the most even choice uses only two gap lengths, ⌊n/k⌋ and ⌈n/k⌉, spread out as well as they will go. That one rule, maximal evenness, picks out the tresillo's 3-3-2 from all 56 ways of choosing 3 of 8.

Right now: … uses gaps of ….

gaps ∈ { ⌊n/k⌋, ⌈n/k⌉ }only two gap lengths, never threen/k = … → …

#long gaps = n mod khow many gaps get the extra step…

2Bjorklund: pair the remainders

Start with k groups [x] and n − k groups [.]. Each round, glue one leftover group onto the end of each front group; whichever kind is left over becomes the new remainder. Stop when one or no remainder group is left, then read the groups left to right. The panel beside the rings plays this round by round.

For … the group counts go …, in … rounds, giving ….

(a, b) → (min(a, b), |a − b|)a front groups, b remainder groups; stop at b ≤ 1…

3It is Euclid's algorithm

The counts in each round are exactly Euclid's greatest common divisor worked by repeated subtraction, the oldest algorithm still in use (about 300 BC). The divisions below do the same thing in fewer lines. When g = gcd(n, k) is bigger than 1, the rhythm is g copies of E(k/g, n/g).

So this pattern is ….

a = q · b + r, then (a, b) ← (b, r)until r = 0; the last b is the gcd…

4Same rhythm, drawn as a line

Draw a straight line from (0, 0) to (n, k) and walk along it a step at a time: a hit wherever the line crosses a whole number. That is Bresenham's algorithm for drawing lines on pixels, and it lands on the same necklace as Bjorklund, only started from a different bead. The staircase in the panel traces it after the pairing rounds.

pᵢ = ⌊i·k/n⌋ − ⌊(i − 1)·k/n⌋1 = a hit at step i…

Bjorklund = Bresenham rotated by rthe same beads, turnedr = …

5Rotation: one necklace, many rhythms

Starting the same circle from a different step gives a different rhythm with identical gaps: E(5,16) started at its third hit is the bossa nova clave, and E(7,12) turned by three is the West African bell pattern. A pattern made of g repeats has only n/g distinct rotations.

p′ᵢ = p₍ᵢ ₊ ᵣ₎ mod nrotate left by r stepsr = … → …

distinct rotations = n / gg = gcd(n, k)…

6Layering: polymeter and polyrhythm

With the rings locked to the same step, rings of different lengths slide past each other and only line up again after the least common multiple of their lengths (polymeter, as in a lot of techno and Steve Reich). Locked to the same bar, every ring squeezes its n steps into one bar, so 3 steps against 4 is the classic 3:4 polyrhythm, and the hits only coincide on the downbeat when the step counts share no factor.

cycle = lcm(n₁, n₂, …) stepssame step: when every ring is back at its start…

Δtᵢ = 60 / (bpm · 4) or 4 · 60 / (bpm · nᵢ)seconds per step: sixteenth notes, or one bar shared out…

7Keeping time: look ahead

JavaScript timers wobble by tens of milliseconds, which the ear hears as sloppy drumming. So a timer wakes every 25 ms and books every hit due in the next 100 ms on the audio hardware's own clock, which is sample-accurate. The rings are drawn from that same clock. The headroom chart shows how far ahead each hit was booked: it should never touch zero.

Swing delays every second step: at 66% the pair splits 2:1, a triplet shuffle.

book every hit with t < now + 0.1 stimer every 25 ms, times from AudioContext.currentTimelowest headroom so far: …

tⱼ = t₀ + j · Δt + (j odd) · (s − 50%) · 2Δts = swing; step mode only…

8Drums from nothing

There are no recordings. The kick is a sine wave whose pitch falls fast, the snare and hats are filtered white noise, the clave a short 2.5 kHz ring, and the cowbell two square waves at 540 and 800 Hz, as in the 1980 Roland TR-808. Every hit is a few oscillators with a volume envelope, booked at its exact time. The same drum kit plays the Euclidean beat in the Visualiser, Ribbon run and Oscilloscope music: the links under the voices take your rhythm there.

f(t) = f₁ + (f₀ − f₁) e^(−t/τ)kick pitch: 150 Hz falling to 45 Hz

g(t) = g₀ e^(−t/τ)every hit's volume dies away exponentially

Two numbers and a two-thousand-year-old algorithm turn out to encode drumming traditions from Cuba to Bulgaria to the Central African Republic.