# Sand and other granular flows

Sand, gravel, salt, rice, seeds, beads, hail, rubble, crumbs — and rain or debris landing on things — are the
same sound: **very many small impacts whose statistics you can hear**. The ear does not follow grains; it reads
their rate, their size distribution, how hard they land, and what they land on.

## The model (`GrainFlow`, kernel name `grains`)

Grains arrive as a Poisson process. Each is a tiny force pulse — strength from size and fall speed, brightness
from contact time (small grains → shorter contact → brighter). The pulses excite two paths:

- **ring** — the surface's modes (`SURFACES[name].modes`, an `objectModes` spec): sheet metal sings, wood knocks,
  paper rattles, a drum skin booms;
- **direct** — the dry tick radiated at the contact point, band-limited per surface (`hp`, `lp`, optional `res`).

| Parameter | Hears as | Typical values |
|---|---|---|
| `rate` grains/s | density: separate ticks → patter → hiss → roar (level grows ~√rate) | trickle 50–500 · pour 2k–20k · dump/sandstorm 50k–400k |
| `size` mm | brightness and weight of each grain | dust 0.05 · sand 0.1–1 · rice 3 · gravel 4–15 · pebbles 20+ |
| `sizeSpread` | uniformity: sieved beads vs. mixed rubble | 0–0.2 uniform · 0.35 natural sand · 0.8 rubble |
| `height` m | impact speed √(2gh): level and energy | hourglass 0.02 · hand pour 0.3 · from a truck 2 |
| `cover` 0–1 | how buried the surface is: resonance damps, tone drifts to grain-on-grain | automate 0 → 1 over a pour |
| `clump` 0–1 | unevenness of the stream | machine feed 0 · hand pour 0.3–0.6 · gusty/sandstorm 0.8 |
| `slide` 0–1 | grains skittering after landing: continuous hiss | tilted or smooth hard surface ↑ |
| `spread` 0–1 | stereo width of the landing zone | thin stream 0.1 · scatter 0.9 |

`opts.surface` — a `SURFACES` key or your own object; `opts.grainRing: { f, t60 }` gives the particles their own
resonance (glass beads, hail, hollow pellets, coins).

Offline: `pour({ surface, seconds, rate: [[t, v], …], cover: [[t, v], …], … })` — any parameter may be a
constant or breakpoints. `crunch({ surface, size, pressure, seconds })` — a collapsing burst: footsteps on
gravel/sand/snow, a shovel bite, a handful dropped, a body in dirt.

## What makes a pour convincing

1. **It evolves.** A real pour starts as a thin stream on the bare surface (bright ticks, surface resonance
   clearly audible), thickens (hiss takes over), buries the surface (`cover` ↑: the ring dies, the tone darkens
   into sand-on-sand), then thins to a trickle of single grains. Automate `rate` and `cover` together; a static
   rate on a static surface sounds like a noise generator.
2. **The surface is the identity.** Same sand: on sheet metal it is a singing shimmer with a low roar; on glass
   bright and brittle; on wood a soft knocking patter; on paper a rattle; on cloth almost nothing but a dull
   breath; on a sand pile a soft, low "pff". Choose or design the surface first.
3. **Graininess is a choice.** Sparse big grains = countable ticks (kurtosis 30+); dense fine sand = smooth hiss
   (kurtosis near 5–10 at pour rates, lower as it thickens). The brief decides: "a few grains still falling"
   and "wall of sand" are opposite ends of one parameter.
4. **Bounce and skitter.** On hard smooth surfaces grains rebound and land again (the surface's `bounce`), and
   slide (`slide`): both blur the stream and add the dry "ssss" tail when the pour stops.
5. **Height changes character, not only level.** Higher fall = harder contacts and more rebound. A stream cut
   off high up keeps arriving for √(2h/g) seconds — delay the stop of the rate curve accordingly.

## Designing surfaces

A surface is `{ modes, ring, direct, hp, lp, res, bounce, tilt }`. To build a new one:
- pick `modes` as for any object (`physics.md` §2): thin sheets = `plate` with many modes and high `damping`
  (sheets are lossy); hollow things = `tube`/`shell` plus a `res` band-pass for the cavity; dead surfaces = `null`;
- set the dry band: hard and dense → `hp` 2–3 kHz, `lp` 12–18 kHz; soft → `lp` 3–5 kHz; granular bed → 1–5 kHz;
- balance `ring` vs `direct` and overall level by rendering 4 s at a fixed rate and reading LUFS (the built-in
  table was calibrated so 3000 grains/s of 0.4 mm sand from 0.4 m lands between −17 LUFS on ringing metal and
  −36 LUFS on cloth). `tilt` (dB/oct on mode amplitudes, default +3) keeps continuous excitation from being all
  low roar.
Blend surfaces by running two kernels (sand reaching the edge of a tray and spilling onto the floor).

## Variations on the theme

- **Hourglass / thin steady stream**: `rate` 200–1500, `clump` 0, `height` 0.02–0.1, `surface: 'sand'` or
  `'glass'`→ automate `cover` quickly to 1.
- **Sandstorm on a tent / car / window**: `rate` 50k–300k, `size` 0.1–0.2, `clump` 0.8, `height` 2–5 (stands in
  for wind speed), surface `drumSkin` / `sheetMetal` / `glass`; layer a `Wind` kernel sharing the gust curve.
- **Gravel dumped**: `size` 6–15, `sizeSpread` 0.6, `rate` rising to 300–2000, `woodBox`/`sheetMetal` (truck bed),
  add `boom` or a low thud layer at the start.
- **Sand dune slide / avalanche hiss**: `surface: 'sand'`, `cover` 1, `slide` 0.8–1, slow `rate` swell; optionally
  a low sine "boom" (booming dunes hum near 70–110 Hz).
- **Rain on things**: the `Rain` kernel is a `GrainFlow` with drop-sized grains plus a diffuse wash; its
  `surface` option accepts the same table (roof, leaves, water, tent).
- **Footsteps on granular ground**: `crunch` per step, `pressure` from walk/run, `size` for the material; vary
  seed and pressure per step and alternate two slightly different sizes for left/right.
- **Debris after an impact**: `crunch` with large `size`, wide `spread`, delayed 30–200 ms after the hit.

## Verifying

- `--lens texture`: `kurtosis` and `localCrestDb` for graininess; `levelStdDb` for evenness.
- `TIME` map across a pour: the surface's bands (low/mid for sheets and wood) must fade as `cover` rises while
  presence/air persist — the picture of burying.
- Compare surfaces with `compare.mjs --variety`: distinct surfaces should sit > 8 dB apart; if two are close,
  their design is not differentiated enough (the level difference alone does not count — it is normalized out).
- Rate sanity: doubling `rate` should raise level by about 3 dB and lower kurtosis.
