Interactive companion

Generating Music from Flocking Dynamics

Cristián Huepe, Marco Colasso and Rodrigo F. Cádiz

This page accompanies the paper of the same title (American Control Conference, 2012) and its extended version (Chapter 7 of Controls and Art, Springer, 2014). It runs the flocking model and the three sound mappings described there, in the browser, so that the examples in the figures can be seen and heard rather than read. Section and equation numbers follow the chapter.

Free runcoupled oscillators η 0.85ψ 0.00
Agents are drawn as in the figures: a dot with a tick along its heading. Click one to see its Vicsek radius R (solid) and its sonic range RS (dashed).
spectrogram · 15 s · 0–5.5 kHz

7.1Order, disorder, flocks, and music

The chapter starts from an observation about music: to be interesting, it needs both order and disorder, coherence and decoherence, structures that consolidate and collapse. Groups of agents following decentralized control rules show the same interplay. They can reach consensus and move as one, or act independently. The question is what happens when one is mapped into the other: which mappings let a listener hear the collective state of a flock, and which produce musically interesting results.

7.2A minimal flocking algorithm

The model is the Vicsek model. N point-like agents move at a fixed common speed v0 in a two-dimensional square box of side L with periodic boundary conditions. Their only interaction is alignment: at every step each agent steers toward the mean heading of all agents within a radius R, with some noise.

(7.1)θi(t+Δt) = Ang{ Σj∈Zi(t) Vel[θj(t)] } + η ξi(t)
(7.2)xi(t+Δt) = xi(t) + Δt v0 Vel[θi(t)]

Ang{·} gives the angle of a vector, Vel[·] the unit vector along an angle, Zi is the set of agents within distance R of agent i, and ξi is a random number uniformly distributed in [−1/2, 1/2]. For low noise the agents converge to a common heading; for high noise they point in random directions. The polarization order parameter measures which:

(7.3)ψ = 1v0 N ‖ Σi=1…N vi(t) ‖

It is 0 in the disordered state and 1 in the polarized flocking state. In both phases agents gather into clusters that keep splitting and merging, with more large clusters at low noise. Clusters do not influence each other until they come closer than R.

Fig. 7.1, recomputed. Polarization ψ as a function of noise η, for systems of equal mean density and different numbers of agents. The transition sharpens as N grows, but even for the N = 30 used in the sound examples the two states are clearly different.

7.4From emergent dynamics to emerging sounds

Each agent drives one sinusoidal generator, Ai(t) sin[ωi(t) t]. Every mapping produces a normalized frequency ωi between 0 and 1 and an amplitude Ai; a final stage maps ωi linearly or exponentially onto a chosen range of audible frequencies. The three approaches differ in where ωi comes from.

Each figure of the chapter shows five panels for one approach: snapshots of the disordered (a) and ordered (b) states, the spectrograms of their sound (c, d), and the spectrogram of a run in which the noise is lowered so that the system goes from disorder to order (e). The buttons below start those runs with N = 30 agents and the noise values quoted in the text. Each takes 15 seconds, the length of the printed spectrograms.

7.4.1The direct approach

The state of each agent is tied directly to its sound: the x coordinate of agent i is its frequency ωi. (In the full system the y coordinate sets the rate of an amplitude modulation; as in the chapter's example, the amplitude is kept constant here.)

directωi(t) = xi(t) / L,   Ai = const.
Fig. 7.3. Direct approach. In disorder: several independently fluctuating frequencies. In order: all frequencies rise or fall at a similar rate, and jump to the opposite extreme when an agent crosses the edge of the periodic box.

The individual dynamics of each agent can be followed, and the two phases are easy to tell apart, but clusters leave no trace in the sound and the result quickly becomes monotonous.

7.4.2The coupled oscillators approach

Here the sound variable is decoupled from the instantaneous state of the flock. Each agent carries a frequency ωi(t) and a randomly chosen preferred frequency ωi0 in [0, 1] that stays fixed during the run. The frequency follows a consensus protocol with the agents inside a sonic interaction range RS > R:

(7.4)dωi(t)dt = β1 [ Ωi(t) − ωi(t) ]
(7.5)Ωi(t) = 1β2 + ñi [ β2 ωi0 + Σj∈Si ωj(t) ]

Si holds the ñi agents with ‖xj − xi‖ < RS. β1 sets how fast each frequency converges to its target; β2 sets the weight of the preferred frequency against the neighbors'. An isolated agent returns to ωi0; agents that flock together long enough end up almost in unison. The amplitude makes interacting agents more audible:

(7.6)Ai(t) = ñi Amax + Aminñi + 1
Fig. 7.4. Coupled oscillators, with RS = 2R, β1 = 0.78, β2 = 0.30. In disorder: horizontal lines at the preferred frequencies, interrupted by quick excursions when agents meet. In order: loud stable notes from persistent clusters, with quieter fluctuating voices from smaller clusters and isolated agents.

Listen for what happens when a cluster splits: the agent that leaves jumps back to its preferred frequency very quickly, while the larger cluster drifts slowly to its new mean. In the transition run, frequencies converge and diverge repeatedly as clusters merge and split.

7.4.3The physical friction approach

The third approach imagines a friction-like process in which agents produce sound as they "rub" against each other, as in a rotating motor whose pitch depends on the relative speed of its parts. The frequency of each agent is proportional to its speed relative to the mean velocity of its neighbors within RS:

(7.7)ωi(t) = 12v0 ‖ [ 1ñi Σj∈Si vj(t) ] − vi(t) ‖

This is 0 when an agent moves exactly with its neighbors and 1 when it moves against them. The amplitude is that of Eq. (7.6).

Fig. 7.5. Physical friction. In disorder: a random sequence of short sounds over the whole range. In order: almost all oscillators sit near ωi = 0, set here to about 700 Hz. In the transition: the short notes are suppressed and sink toward ωi = 0, with "sparkles" when a cluster fragments.

7.5From emergent dynamics to emerging music

Ritmos Circadianos (Cádiz, 2012) is a piece for the Logos Foundation's Man and Machine Robot Orchestra, generated in real time from a Vicsek simulation with twelve agents, one per robot instrument, using the coupled oscillators approach. It lasts 10 min 24 s: 26 sections of 24 s each, ten bars at 100 beats per minute, by analogy with a 24-hour circadian cycle. Each agent's ωi is quantized to MIDI notes within its instrument's range; its distance to the center of the space sets its loudness; and its state rescales the periods of up to three superimposed pulses, so that agents close to the mean heading play regular patterns and agents far from it play irregular ones.

Table 7.1 lists the model parameters of each section. Click a row to put the twelve-agent flock in that state and hear its coupled-oscillator frequencies as sine tones.

This is the flocking state behind each section, not the piece: the robot instruments, the MIDI quantization and the rhythmic pulses are not reproduced. Two readings are assumed because the chapter does not define them: the radius r is taken in units where the box side is , and the "position noise" ηp is applied as a random vector added to the mean heading before taking its angle.
§rηpηaβ1β2Instrumentation

7.6What to listen for

All three mappings let a listener tell order from disorder. The two that use indirect measures of the dynamics, the coupled oscillators and the physical friction, give the more interesting and appealing results: their sound depends only on encounters between agents, not on where the agents are. The chapter suggests natural extensions that were out of reach of the original real-time tools, among them a Kuramoto model coupling the phases of neighboring agents, and treating a cluster as an elastic membrane.

What comes from the chapter and what does not. From the text: the model and Eqs. (7.1) to (7.7), N = 30, the noise values of every example, RS = 2R, β1 = 0.78, β2 = 0.30, the 15 s spectrograms, the 700 Hz floor of the friction example, and Table 7.1. Read off the MaxMSP panel in Fig. 7.2: R = 0.1, 30 frames per second, the 200 to 5000 Hz range with exponential scaling for the coupled oscillators, and Amin = 0.1. Chosen here because the chapter does not state them: the box side (L = 1), the speed (0.2 box sides per second), linear scaling for the direct and friction examples (judged from the printed spectrograms), and noise η expressed as a fraction of a full turn, so that the heading perturbation is 2πη ξ. Equation (7.4) is advanced once per frame. Fig. 7.1 is recomputed at the density of the sound examples and over the full noise range, so its horizontal axis is not the printed one.

C. Huepe, R. F. Cádiz and M. Colasso, "Generating music from flocking dynamics," Proc. American Control Conference, Montréal, 2012, pp. 4339–4344. doi:10.1109/ACC.2012.6315529
C. Huepe, M. Colasso and R. F. Cádiz, "Generating music from flocking dynamics," in A. LaViers and M. Egerstedt (eds.), Controls and Art, Springer, 2014, pp. 155–179. doi:10.1007/978-3-319-03904-6_7