a1f5e15Islands in a sea of chaos: Duffing phase space with sonificationJeremy Magland 1# Islands in a sea of chaos
3A minimal lab for the driven Duffing oscillator's phase space, a companion to the hardening and softening tutorial (same equation and units):
5 ẍ + δẋ ± (2πf₀)² x + αx³ = F cos Ωt
7```bash
8npm run dev # serves app/ at http://127.0.0.1:8002
9npm run check # node --check on every module
10node scripts/section-png.mjs out.png -220 2e7 0 5.6e4 490 1500 0.5 # render a section (for choosing presets)
11```
13Static `index.html`, `style.css` and ES modules, no build step; fonts bundled under `app/vendor/`.
15## What's in it
17- **Poincaré section**: (x, ẋ) once per drive period, at drive phase 0. Seed orbits from the axes of the view fill it in live. Undamped, regular orbits draw closed curves (islands, island chains) and chaotic ones scatter over the sea. Damped, the seeds settle onto the attractors first.
18- **Click** to add an orbit from that point (up to 8; click its start ring to remove it): its dots fill in (larger, brighter), and a playhead walks it one drive period per beat, with a fading trail of the continuous motion through each period and a ring at each return to the section. Changing a parameter or preset keeps them, restarted from the same (x, ẋ) under the new parameters. All the clicked orbits play together, on the same beat, each in its own voice (listed in the panel with its color; × removes it).
19- **Sound**: each return to the section plays a note, its pitch set by x (left to right across the view: C3 to C6), on a selectable scale (minor pentatonic by default; major pentatonic, major, minors, whole tone, chromatic, or continuous) in a selectable key (A by default). The key buttons keep the register (C3 to C6) and change which notes x snaps to, so switching key while playing shifts the harmony like a chord change. An island orbit plays a repeating pattern; a chaotic one wanders. Tempo sets drive periods per second (default 16, up to 40; the motion is slowed down to that), independent of the drive frequency.
20- **Voices**: the first orbit plays a harp; the next ones marimba, vibraphone, electric piano, music box, ocarina, pizzicato and kalimba (an orbit takes the first voice not in use). **Sustain** (0.1 to 4 s, default 2) sets how long every note rings, the same for all voices and pitches, so they differ only in timbre and attack, and all start equally loud.
31155f4Rhythm: pluck at both turning points by defaultJeremy Magland 21- **Rhythm**: *natural, upward* plucks wherever ẋ crosses 0 upward (the left turning point of each swing), at that x and at that moment in the slowed-down motion, so each orbit makes its own rhythm: a lilting, nearly regular one on an island, an uneven one in the sea, and several orbits make polyrhythms. *Both ways* (the default) also plucks at the right turning point (ẋ crossing 0 downward), so each swing plays its low and high end. *Steady* plucks once per drive period, at the section point.
e607771Optional coupling of the clicked orbitsJeremy Magland 22- **Coupling** (optional, off by default; 1 to about 3000 s⁻¹ on a log scale): joins the clicked orbits into one system, each pulled toward their mean by a spring and a damper on its difference (critically damped at rate r), leaving the mean motion as it was. Weakly coupled they nudge each other (and lose the energy of their mismatch, often settling into islands); strongly coupled they fall into step and play in unison, even in the chaotic sea. On the first preset, three sea orbits lock above about 900 s⁻¹. While coupled, adding or removing an orbit, or changing the coupling, restarts the clicked orbits from their starts.
a1f5e15Islands in a sea of chaos: Duffing phase space with sonificationJeremy Magland 23- **Parameters**: f₀ (negative: a double well), α, δ, F, Ω/2π, and the view's half-width in x. Presets: double well (islands in a sea; gentle drive with a thin chaotic layer; strong drive), pure cubic, hardening resonance island, and a damped strange attractor.
25## Physics and sound
27- `app/js/duffing.js`: each drive period in N equal steps of a 4th-order Yoshida composition of a damping/kick/drift/kick/damping leapfrog (symplectic when undamped, so islands keep their shape over long runs), with the drive tabulated at the kick times. ω h ≤ 0.08 for the stiffest local frequency up to |x| = 1, past which an orbit has escaped.
e607771Optional coupling of the clicked orbitsJeremy Magland 28- Coupling (`stepMany` in `duffing.js`): each oscillator gets r² (x̄ − xₖ) + 2r (v̄ − vₖ), x̄ and v̄ the means of those not escaped. The damper part is solved exactly (the mean velocity is kept, differences decay by e^(−2rt)) in half steps around the kicks, the spring part joins the kicks. A damper alone would lock velocities but not positions (two orbits can glide along together in different wells), hence the spring.
a1f5e15Islands in a sea of chaos: Duffing phase space with sonificationJeremy Magland 29- `app/js/voices.js`: notes rendered once per voice, pitch and sustain into AudioBuffers, each ringing for the sustain (the fundamental's 60 dB decay time) and matched in loudness by the K-weighted RMS (ITU-R BS.1770's filter: +4 dB above about 1.7 kHz, high-pass at 38 Hz) over its first 0.3 s. Strings (harp, pizzicato) are Karplus-Strong. The string starts in a rounded triangle (plucked at 0.15 of its length, so harmonics 2 to 4 sit about 8, 14 and 21 dB below the fundamental), loops through a [¼, ½, ¼] low-pass (highs die away first) with an all-pass for fractional-delay tuning, and gets a 4 ms soft attack. Bars, tines and the ocarina are a few decaying sinusoids at the instrument's partial ratios (marimba 1 : 3.93 : 9.2; vibraphone 1 : 4 : 10 with tremolo); the electric piano is two-operator FM with a fading index. Then a gentle 3.5 kHz low-pass, a dark synthetic reverb and a limiter. Notes are scheduled on the audio clock a little ahead of time, softer the more orbits play; each orbit keeps at most 64 notes sounding (the oldest fades out in 40 ms), so fast tempos with long sustains stay light.