Shard format format 0.1.0.6 · npm 0.80.0

Audio in a shard: targets and how to hit them

Reference, rendered from docs/audio.md as it stands at this build. Its links to code go to GitHub; the code is the spec.

On this page
  1. Why audio has targets
  2. Before you upload
  3. Where the check runs
  4. The targets
  5. Loudness
  6. Length
  7. Seamless loops
  8. Cache, never stream (J299)
  9. Mono unless it pans
  10. Share, don't copy
  11. Engine music slots (J304)
  12. The budget (J303)

Written by: Claude

State: living, 2026-11-13 (meta docs/plans/AUDIO-PLAN.md row AU8). Numbers are shard-format's AUDIO_RULES (src/format/audio-rules.ts) as of v0.4.5. If this page and that file disagree, the file is right; fix this page.

Read this before you add music or sound effects to a shard source. It says what to ship, why, and which shard-format check holds you to it. Where no check exists yet, it says so and gives you the command to measure it yourself.

Why audio has targets

J299 (Jake's decision, 2026-11-12, meta docs/plans/MULTI-REPO-SAGA/decisions/): audio is downloaded and cached at DOWNLOAD, never streamed and never read during LOAD. So every recording your shard plays is in the phone's first download, and every megabyte of it is boot time on bad LTE. Before J299, prod v0.1.13 Driftwood sat 34 s in LOAD reading 91 audio files one by one (meta QA-FEEDBACK-2026-11-12 row 36). The targets below keep a shard's audio small enough to download up front.

Before you upload

  1. Run wildshard build <folder> and read its audio lines (see "Where the check runs").
  2. Measure each new or re-exported file with the three commands below: loudness (ebur128), length (ffprobe) and, for a stereo sound effect, the mono check (aeval).
  3. Read src/shards/<folder>/mounts.json for a file you don't play, a copy of an sfx/best sound, or two files of the same sound; drop the unused ones and point duplicates at one file.

Done when: build shows no red line; each new music file reads I: between −19 and −17 LUFS; each new sound effect reads Peak: at −1 or lower; each music loop runs 30 to 90 s and each one-shot under 3 s; each stereo sound effect's L−R max_volume is above −40 dB (or it is mono). Fix an AMBER bitrate or format line in the same re-export that touches the file.

Where the check runs

One check owns the rules, AU5's (row AU5 of meta docs/plans/AUDIO-PLAN.md): audioReport in src/format/audio-rules.ts, fed by shardfileRecordings in src/format/shardfile-audio.ts (it measures each recording from its bytes in src/format/audio-measure.ts, no ffmpeg).

The tests that pin each rule are in src/format/audio-rules.test.ts.

The check reads each file's bytes, not its extension (audioContainer in audio-measure.ts). AAC bytes at a .wav or .flac URL, as the build's encoder leaves them (it keeps the source URL), are measured as AAC. FLAC, AIFF, Ogg, MP3, WebM, CAF or bytes in no container it knows are audio-container (red), and still count toward the budget.

The targets

RuleTargetAU5 checkLevel
FormatAAC-LC in .m4a, 48 kHz, mono or stereoformatFinding: audio-container, audio-unreadable, audio-wav, audio-sample-rate, audio-strict-indexcontainer and unreadable are red; the rest AMBER
Bitrate, music64 kbps stereo, 48 kbps monobitrateFinding: audio-bitrate (cap plus 10%)AMBER
Bitrate, sound effects48 kbps stereo, 40 kbps monobitrateFinding: audio-bitrate (cap plus 10%)AMBER
Length, any file180 s at mostdurationFinding: audio-durationred
Budget, the shard's own audiogreen to 6 MB, AMBER 6 to 10 MB, red over 10 MB (J303)budgetFindings: audio-budget-amber, audio-budget-redAMBER, then red
Loudnessmusic −18 LUFS integrated (−19 to −17); sound effects true peak −1 dBTP or lowernone yetmeasure it yourself
Loop and one-shot lengthmusic loops 30 to 90 s; one-shots under 3 snone yet; audio-duration stops only past 180 smeasure it yourself
Mono unless it panssound effects in one channel unless left and right differnone yet; audio-bitrate gives mono a lower capmeasure it yourself

A recording is music if its path starts /assets/music/ and a sound effect if it starts /assets/sfx/ (recordingRole in audio-measure.ts). The bitrate cap follows from that path, so keep music under music/.

Loudness

Target: music at −18 LUFS integrated, within −19 to −17; sound effects with a true peak of −1 dBTP or lower. The engine sets music and effect gains itself, so a track mastered at −10 LUFS drowns the rest of the game, and a peak near 0 dBTP can clip once AAC decodes it. The engine's piano title (public/assets/music/piano/title-3d1f713a.m4a, engine 8850b104) measures −18.2 LUFS, peak −1.8 dBTP.

Measure with ffmpeg's ebur128 filter:

ffmpeg -hide_banner -nostats -i public/assets/music/<set>/<name>.m4a \
  -filter_complex ebur128=peak=true -f null - 2>&1 | grep -E 'I:|Peak:'

I: is the integrated loudness in LUFS. Peak: is the true peak; ffmpeg prints its unit as dBFS, but with peak=true it is dBTP. To fix a file, re-export it from the source at the target; don't stack gain on an already encoded file.

AU5 check: none. Nothing measures loudness at build or upload yet; this rule is yours to measure.

Length

AU5 check: durationFinding (audio-duration) refuses any file over 180 s as red. The 30 to 90 s and 3 s targets have no check yet. Measure with ffprobe -v error -show_entries stream=duration,channels -of csv=p=0 <file>.

Seamless loops

A music slot loops between loopStart and loopEnd, in seconds, from its row in the set's music.json (as in Coral Drift's public/assets/music/coral-drift/music.json, shard-open-plots bf47e41). Put both on bar lines; bpm and beatsPerBar sit beside them. The engine keeps only that window (engine 8850b104 src/client/engine/audio/loopWindow.ts, compactLoopWindow, plus 128 samples either side), so an intro or outro outside it costs download but never plays.

AAC starts every file with priming samples, the encoder's warm-up. The engine skips them using the edts edit list in the .m4a (shard-format src/format/aacIndex.ts reads it as primingFrames; engine src/client/engine/audio/aacPull.ts drops them). So:

AU5 check: formatFinding reports audio-strict-index (AMBER) when a file is AAC that the strict playback index refuses, for example with no edts (six of Pine Hollow's beds at shard-pine-hollow 8b17e93). Treat it as a loop that may click.

Cache, never stream (J299)

There is no lazy or streamed audio. Everything your shard names is downloaded at DOWNLOAD and cached on the device before play starts. So:

AU5 check: the budget (budgetFindings) and audio-duration are the limits; together they bound what DOWNLOAD carries.

Mono unless it pans

Ship a sound effect in mono unless its left and right channels really differ, for example a stereo ambience bed or a sweep. A positional sound is placed by the engine, so a stereo source buys nothing. Mono at 40 kbps is under half the bytes of a stereo file at about 97 kbps, the rate shards shipped at before AU7's encoder (audio-rules.ts header). Music may stay stereo.

To see whether a stereo file is really mono, measure the difference of its two channels:

ffmpeg -hide_banner -nostats -i <file> -af "aeval=val(0)-val(1)|val(0)-val(1),volumedetect" -f null - 2>&1 \
  | grep max_volume

A max_volume below about −40 dB means left and right are the same: export it as mono.

AU5 check: none refuses stereo. bitrateFinding holds a mono file to the lower cap (40 kbps for sound effects, 48 kbps for music), so a mono export is what gets you under it.

Share, don't copy

The budget counts each distinct file once, by content hash (uniqueRows in audio-rules.ts): two paths with the same bytes cost one download. Use that.

AU5 check: audioReport dedupes by hash before it sums the budget, so sharing shows up as fewer bytes in the audio … total line.

Engine music slots (J304)

Every shard plays one music style, piano (J304, Jake 2026-11-12). A score can play the engine's own piano stems instead of shipping its own: a slot whose set is base (or unset) plays the engine's stem of that name, and bootSlots: ['title'] plays the engine's title. The engine has exactly these slots: ENGINE_MUSIC_SLOTS in src/format/engine-music.ts (island, pine), plus title; import it from @wildshard/shard-format/engineMusic. Validation refuses any other base slot (AudioMusicSchema; tests in src/format/audio-engine-music.test.ts).

Engine music the engine ships costs you no budget in AU5's check, since the bytes are the engine's; a stem your shard source mounts itself does count. Engine music is still in the player's download: the piano title alone is 0.76 MB (meta AUDIO-PLAN.md row AU18, engine 8850b104).

The budget (J303)

AU5 counts your shard's own recordings: every audio file mounted under /assets/music/ or /assets/sfx/ (any audio extension, .flac and .aiff too, or audio bytes under any name; a music.json there is not audio) plus every non-commons audio.recordings blob, each distinct hash once.

Own audioLevelWhat happens
up to 6 MBgreennothing
over 6 MB, up to 10 MBAMBER (audio-budget-amber)build prints it; upload and admission pass
over 10 MBred (audio-budget-red)build prints it; upload and admission refuse

A shard over the red line while its fix is under way can carry a dated waiver in its shard source, src/shards/<folder>/audio-waiver.json:

{ "version": 1, "waivers": [{ "shard": "<slug>", "until": "2026-12-31", "maxBytes": 15000000, "reason": "<why, and the row that closes it>" }] }

Build copies the row for your slug into the shard file's shard.json as admission.audioWaiver (schema: AudioWaiverSchema in src/format/audio-waiver.ts). While it holds, red becomes audio-budget-waived (AMBER). It stops holding when the date passes, when it names another shard, or when your audio grows past maxBytes: then you get audio-waiver-invalid (AMBER) and the red comes back.

The player's whole audio download is your own audio plus the engine music and sfx/best sounds you play. That total is the engine's to report, not this check's.