# Game assets: libraries, and turning recordings into parametric generators

## Contents
1. What a game needs from a sound
2. Free and open libraries (check the licence per file)
3. Sample → procedural: the three-part model
4. Extending a sample: spectrum, power, stereo, space
5. Endless texture from a short recording
6. Building an asset set
7. Verifying

## 1. What a game needs from a sound

- **No audible repetition**: the same file twice in a row is the first thing players notice. Either ship
  variations (3–8 per event) and vary pitch/level at runtime, or ship the generator.
- **Response to state**: surface, speed, force, distance, health… a parameter, not a new file.
- **Small and cheap**: mono one-shots, 16-bit/48 kHz (or 44.1), trimmed tight, no DC, consistent loudness
  within a category so the mixer can treat the category as one fader.
- **Clean edges**: starts at the transient (no latency), ends in silence, loops pass `loopcheck`.

## 2. Free and open libraries

Licences differ per site and often per file, and terms change — read the licence of each file you ship, keep a
`CREDITS`/licence manifest next to the assets, and tell the user what you used.

| Source | What | Licence notes |
|---|---|---|
| Freesound — https://freesound.org | huge community database, API with search/filter by licence, duration, tags | per sound: CC0, CC-BY (credit), CC-BY-NC (not for commercial games). Filter `license:"Creative Commons 0"`; the API needs the user's own key |
| Sonniss GameAudioGDC — https://sonniss.com/gameaudiogdc | tens of GB of professional libraries released each year | royalty-free, no attribution, commercial use allowed; read the bundle licence (recent bundles restrict AI/ML training use) |
| Kenney — https://kenney.nl/assets?q=audio | cohesive UI, impact, RPG, sci-fi packs | CC0 |
| OpenGameArt — https://opengameart.org | game-ready SFX and packs | per item: CC0, CC-BY, CC-BY-SA, OGA-BY, GPL — filter by licence |
| BBC Sound Effects — https://sound-effects.bbcrewind.co.uk | 33 000+ archive recordings (nature, transport, machines, crowds) | RemArc licence: personal, educational, research only — not commercial without a paid licence |
| Pixabay — https://pixabay.com/sound-effects | general SFX | Pixabay Content Licence: free for commercial use, no attribution; no standalone redistribution |
| Mixkit — https://mixkit.co/free-sound-effects | curated general SFX | Mixkit licence: free for commercial use |
| ZapSplat — https://www.zapsplat.com | large general library | free tier requires attribution; paid removes it |
| 99Sounds — https://99sounds.org | designed packs (cinematic, foley, textures) | royalty-free, see each pack |
| itch.io asset packs — https://itch.io/game-assets/tag-sound-effects | indie packs, many CC0 | per pack |
| Internet Archive / Wikimedia Commons | field recordings, public-domain audio | per item |

How to use them with this skill: take recordings for what synthesis does badly (complex organic sources:
animals, cloth, real voices-as-texture, specific machines), and use the tools below to make them parametric,
varied, bigger, wider or endless. Take synthesis for what recordings do badly (exact parameter response,
unlimited variation, tiny size). Do not download on the user's behalf without saying what and under which licence.

## 3. Sample → procedural: the three-part model

Any one-shot is separable into parts that answer to different controls:

| Part | What it is | Controls it gives |
|---|---|---|
| **modes** | decaying partials (the object ringing) | pitch → size; damping → material/grip; tilt → brightness; per-mode jitter → natural variation |
| **noise** | band energies over time (friction, air, debris, room) | level, brightness, time-stretch |
| **transient** | the first milliseconds (the contact) | gain → hardness/punch |

```js
const model = sd.sampleModel(sd.readAudio('mug.wav'));        // { modes: [{f, t60, amp}], noise, transient }
const same  = sd.resynth(model);                               // close to the original
const big   = sd.resynth(model, { pitch: 0.5, damping: 0.7 }); // twice the size, rings longer
const dull  = sd.resynth(model, { damping: 5, brightness: -3 });// held in a hand / different material
const set   = sd.variations(model, 6, { jitter: 0.2 });        // round-robins
```
`resynth` options: `pitch`, `damping`, `brightness` (dB/oct), `tonal`, `noise`, `transient` (gains), `stretch`,
`jitter`, `seed`. The model is plain data — store it as JSON and ship *it* with a small runtime instead of files,
or feed `model.modes` straight into `strike` / `ModalBank` / `PhysicsSonifier` (`bodies: { mug: { modes } }`)
so the recorded object becomes a physics-driven one: struck harder, rolled, scraped.

Where it works: struck, dropped, clinked, plucked things; knocks; metal, glass, ceramic, wood. Where it does
not: sources with gliding pitch (sub drops, voices, engines), dense reverberant mixes, long evolving textures —
`sampleModel` then finds few modes and the noise part carries a smeared average. Use `enhance`, `granulate` or
layering for those. Always `compare.mjs original.wav resynth.wav` first: under ~4 dB shape distance the model
is faithful enough to parameterize; far above, pick another method.

## 4. Extending a sample without re-synthesis

`enhance(buf, { sub, air, punch, tiltDbOct, widen, room, roomDb, glue })`:

| Want | Option | How |
|---|---|---|
| more weight / lower spectrum | `sub` 0–1 | octave-down generator following the low band (`subharmonic`) |
| more top / presence | `air` 0–1 | saturate the top band and mix back (`exciter`) |
| more punch or softer attack | `punch` ±1 | transient shaper |
| brighter / darker overall | `tiltDbOct` | spectral tilt around 1 kHz |
| mono → stereo, or wider | `widen` 0–1 | all-pass decorrelation (mono-compatible), M/S above 120 Hz for stereo |
| a place | `room`, `roomDb` | synthetic IR (`SPACES` or own) |
| denser / louder | `glue` 0–1 | parallel compression |

Further moves from `lib/core`: `varispeed` (size: lower + slower together), `tilt`, `eq`, `drive` kinds,
`ringmod`, `chorus`/`phaser`, `transientShape`, `reverseSwell`, `glitch`; layering with synthesized roles
(`boom` under a recorded hit, `crunch` debris after it, a modal `strike` for a material accent) — see the role
table in `cinematic.md`. Embed in a scene with `spatialize` (Doppler, distance, occlusion) or a `SpatialSource`.

## 5. Endless texture from a short recording

`granulate(buf, { seconds, grain, density, spray, pitch, scan, stereo })` overlaps windowed grains taken from
random positions: 3 s of rain, fire, crowd, machine room or cloth become minutes that never repeat, already
stereo and already loopable (grains wrap around the end). `grain` 0.05–0.15 s for noisy textures, 0.2–0.5 s to
keep recognisable events; `pitch: [0.97, 1.03]` hides repetition, wider ranges change character; `scan: 1`
travels through the source once (time-stretch).
For realtime, play grains from an `AudioBuffer` with random offset/`playbackRate` per grain (a few lines of
`AudioBufferSourceNode` scheduling), or bake several loops of unequal length.

## 6. Building an asset set

1. List the events and the axes that vary (surface × intensity; weapon × distance; UI state × importance).
2. Decide per event: recorded + extended, modelled from a recording, or fully synthesized.
3. Fix conventions: sample rate, mono/stereo, loudness per category, naming `category_event_variant_NN.wav`,
   tail policy, seeds recorded in sidecar JSON (`writeWav(..., { meta })`).
4. Render variations by changing structure as well as seed; export 3–8 per event.
5. Runtime variation on top (random pitch ±1–2 semitones, level ±2 dB, never the same file twice in a row).
6. Verify the set (below), then hand over with the parameter list and the licence manifest.

## 7. Verifying

- Fidelity of a model: `compare.mjs original resynth` (shape distance, band balance, loudness).
- Round-robins: `compare.mjs --variety var_*.wav` → 1.5–5 dB apart, loudness spread < 2 LU.
- Category consistency: `analyze.mjs set/*.wav --brief` — similar LUFS-M within a category, no defects,
  `head` silence ≈ 0 ms, attack as designed.
- Parameter response: render the generator at 3 values of each parameter and check the intended metric moves
  monotonically (pitch ↔ centroid/peaks, damping ↔ T60, hardness ↔ attack/brightness).
