@schmooky/zvuk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +153 -38
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,22 @@
1
- # zvuk
1
+ <div align="center">
2
2
 
3
- > Audio Engine for the Web. Wwise-grade routing, sprite loading, sidechain ducking — in a tiny ESM package.
3
+ # @schmooky/zvuk
4
+
5
+ **Audio Engine for the Web** — Wwise-grade routing, audio sprites, sidechain ducking, snapshots, in a tiny ESM package.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@schmooky/zvuk?style=flat-square&color=4f6cf7)](https://www.npmjs.com/package/@schmooky/zvuk)
8
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@schmooky/zvuk?style=flat-square&label=min%2Bgzip&color=4f6cf7)](https://bundlephobia.com/package/@schmooky/zvuk)
9
+ [![types](https://img.shields.io/npm/types/@schmooky/zvuk?style=flat-square&color=4f6cf7)](https://www.npmjs.com/package/@schmooky/zvuk)
10
+ [![license](https://img.shields.io/npm/l/@schmooky/zvuk?style=flat-square&color=4f6cf7)](./LICENSE)
11
+ [![CI](https://img.shields.io/github/actions/workflow/status/schmooky/zvuk/ci.yml?branch=main&style=flat-square&label=CI)](https://github.com/schmooky/zvuk/actions/workflows/ci.yml)
12
+
13
+ [**Documentation**](https://zvuk.schmooky.dev/docs/) · [**Concepts**](https://zvuk.schmooky.dev/concepts/) · [**API**](https://zvuk.schmooky.dev/api/) · [**Roadmap**](https://zvuk.schmooky.dev/roadmap/) · [**llms.txt**](https://zvuk.schmooky.dev/llms.txt)
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ ## Install
4
20
 
5
21
  ```bash
6
22
  pnpm add @schmooky/zvuk
@@ -14,11 +30,11 @@ const engine = createEngine({
14
30
  music: { level: 0.8 },
15
31
  sfx: { level: 1.0 },
16
32
  },
17
- master: { headroom: -3 },
33
+ master: { headroom: -3, limiter: { threshold: -1 } },
18
34
  });
19
35
 
20
- await engine.unlock(); // call from a user gesture
21
- await engine.loadSound('coin', '/sfx/coin.wav', { bus: 'sfx' });
36
+ await engine.unlock(); // call from a user gesture
37
+ await engine.loadSound('coin', '/sfx/coin.webm', { bus: 'sfx' });
22
38
 
23
39
  const v = engine.sound('coin').play({ volume: { jitter: 0.05 } });
24
40
  await v.fade({ to: 0, ms: 800 });
@@ -26,60 +42,159 @@ await v.fade({ to: 0, ms: 800 });
26
42
  engine.bus('music').fadeTo(0.1, 800);
27
43
  ```
28
44
 
29
- ## What's in this repo
45
+ ## Why zvuk?
46
+
47
+ `HTMLAudioElement` doesn't scale past one menu sound. The Web Audio API does, but you end up writing your own bus graph, your own scheduler, your own iOS unlock dance, your own codec ladder, your own sidechain envelope, your own snapshot crossfader — every time.
48
+
49
+ zvuk is the layer above. It gives you the routing primitives a real game audio team uses (Wwise / FMOD / RAD) without a 60 MB editor, behind an API surface small enough to fit in your head. ESM-only, type-safe, no dependencies beyond `eventemitter3`, ~16 KB min+gzip.
50
+
51
+ ## Features
52
+
53
+ | Mixer | FX | Loading | DX |
54
+ | --- | --- | --- | --- |
55
+ | Named buses with FX inserts | Compressor (DynamicsCompressor + makeup) | Codec ladder (`['x.webm', 'x.m4a']`) | Lazy AudioContext (no constructor side-effects) |
56
+ | Master headroom + brick-wall limiter | Filter (BiquadFilter, all 6 modes) | Audio sprites (one buffer, N regions) | iOS Safari unlock + visibility resume |
57
+ | Voice concurrency + stealing | Reverb (convolution + synthetic IR) | Stream long media via MediaElementSource | Sample-accurate scheduler |
58
+ | Sidechain ducking (Ducker) | Time-stretch (offline SOLA + realtime Worklet) | Loudness normalization on load | Async cues iterator on every Voice |
59
+ | Snapshots — capture & crossfade the mix | Spatializer (2D pan + 3D HRTF) | AbortSignal cancellation | "Did you mean…" on bus/sound name typos |
60
+
61
+ ## Examples
62
+
63
+ ### Audio sprites — one buffer, many regions
64
+
65
+ ```ts
66
+ await engine.loadSprite('cascade', '/sfx/cascade.webm', {
67
+ small: { start: 0, duration: 0.2 },
68
+ medium: { start: 0.25, duration: 0.4 },
69
+ big: { start: 0.7, duration: 0.6 },
70
+ }, { bus: 'sfx' });
71
+
72
+ engine.sprite('cascade').play('medium', { volume: { jitter: 0.05 } });
73
+ ```
74
+
75
+ ### Stream long media (don't decode 4 minutes into RAM)
30
76
 
77
+ ```ts
78
+ const intro = engine.loadStream('intro', '/music/intro.m4a', { bus: 'music' });
79
+ await intro.play({ loop: true, volume: 0.6 });
31
80
  ```
32
- zvuk/
33
- ├── src/ the zvuk package source
34
- ├── test/ vitest suite
35
- ├── docs/ Astro docs site (deploys to zvuk.dev)
36
- └── tsup.config.ts single-file ESM build
81
+
82
+ ### Crossfade music tracks (equal-power)
83
+
84
+ ```ts
85
+ await engine.loadSound('intro', '/music/intro.webm', { bus: 'music' });
86
+ await engine.loadSound('main', '/music/main.webm', { bus: 'music' });
87
+
88
+ engine.sound('intro').play({ loop: true });
89
+ engine.crossfade('intro', 'main', { ms: 1500 });
37
90
  ```
38
91
 
39
- - The **root package** is `@schmooky/zvuk`. It's what npm publishes.
40
- - The **docs** site lives in `docs/` and deploys independently. Concept pages embed live React-island demos that drive the real engine.
92
+ ### Sidechain ducking — music breathes under VO
93
+
94
+ ```ts
95
+ import { Ducker } from '@schmooky/zvuk';
96
+
97
+ const ducker = new Ducker(engine.context, {
98
+ source: engine.bus('voice').output,
99
+ target: engine.bus('music'),
100
+ amount: 0.7, attack: 80, release: 600,
101
+ });
102
+ engine.bus('music').addFx(ducker);
103
+ ```
104
+
105
+ ### Live spatial audio — hold the Voice, steer it per-frame
106
+
107
+ ```ts
108
+ const v = engine.sound('engine-loop').play({
109
+ loop: true,
110
+ spatializer: { position: [0, 0, 0] },
111
+ });
112
+
113
+ requestAnimationFrame(function tick() {
114
+ v.spatializer?.setPosition(player.x, 0, player.z);
115
+ requestAnimationFrame(tick);
116
+ });
117
+ ```
118
+
119
+ ### Snapshots — capture the mix, crossfade back to it
120
+
121
+ ```ts
122
+ const calm = engine.captureSnapshot('calm');
123
+
124
+ engine.bus('music').fadeTo(0.2, 200);
125
+ engine.bus('voice').fadeTo(1.5, 200);
126
+
127
+ await calm.apply({ fadeMs: 600 }); // restore everything in one call
128
+ ```
129
+
130
+ ## Browser support
131
+
132
+ | Browser | Minimum | Notes |
133
+ | -------------------- | ------- | ----- |
134
+ | Chrome, Edge, Opera | 76+ | Opus + AAC, AudioWorklet, HRTF Spatializer |
135
+ | Firefox | 88+ | Opus + AAC |
136
+ | Safari macOS | 14.1+ | Opus from 14.5; pickSource falls back to AAC on older |
137
+ | Safari iOS | 14.5+ | Same — bundle a webm + m4a pair via the codec ladder |
138
+
139
+ zvuk is ESM-only and assumes a working `AudioContext`. No polyfills; no shims for IE.
140
+
141
+ ## Documentation
142
+
143
+ - **[Quickstart](https://zvuk.schmooky.dev/docs/quickstart/)** — running in 30 lines
144
+ - **[Concepts](https://zvuk.schmooky.dev/concepts/)** — Engine, Bus, Sound, Voice, Snapshot, Spatializer, Concurrency
145
+ - **[FX](https://zvuk.schmooky.dev/fx/)** — Compressor, Filter, Reverb, Pitch & time-stretch, Ducker
146
+ - **[Guides](https://zvuk.schmooky.dev/guides/)** — asset formats, loading, mix building, ducking, migrating from Howler
147
+ - **[Recipes](https://zvuk.schmooky.dev/recipes/)** — short, copy-paste-ready solutions
148
+ - **[API reference](https://zvuk.schmooky.dev/api/)** — auto-generated TypeDoc, regenerated each build
149
+ - **[llms.txt](https://zvuk.schmooky.dev/llms.txt)** — agent-readable index of the entire site
41
150
 
42
151
  ## Working in this repo
43
152
 
44
153
  ```bash
45
154
  pnpm install
46
- pnpm test
47
- pnpm typecheck
48
- pnpm build
49
- pnpm docs:dev
155
+ pnpm test # vitest, happy-dom + Web Audio mock
156
+ pnpm typecheck # tsc --noEmit across src/ and test/
157
+ pnpm lint # biome check
158
+ pnpm build # tsup → dist/index.js + dist/cli.js + dist/index.d.ts
159
+ pnpm docs:dev # astro dev at http://localhost:4321
160
+ pnpm docs:build # astro + pagefind index + OG cards + llms.txt
161
+ pnpm bench # vitest bench/
162
+ ```
163
+
164
+ The package's `exports` field resolves to `src/index.ts` for workspace consumers. `publishConfig` overrides it to `dist/...` at publish time so npm consumers get the compiled artifact. Concept pages embed live React-island demos that drive the real engine — no mocks.
165
+
166
+ ```
167
+ zvuk/
168
+ ├── src/ package source
169
+ ├── test/ vitest suite
170
+ ├── bench/ vitest bench/
171
+ ├── examples/ vanilla deployable demos (slot-machine, match-3, fps-footsteps)
172
+ ├── docs/ Astro site → zvuk.schmooky.dev
173
+ └── tsup.config.ts ESM build config
50
174
  ```
51
175
 
52
- What each script does:
176
+ ## Release flow
53
177
 
54
- - `pnpm test` — Vitest, happy-dom + Web Audio mock.
55
- - `pnpm typecheck` — `tsc --noEmit` across `src/` and `test/`.
56
- - `pnpm build` — tsup bundles `dist/index.js` + `dist/index.d.ts`.
57
- - `pnpm docs:dev` — Astro dev server at http://localhost:4321. Reads the
58
- package source directly via the `src/index.ts` exports — no prior `pnpm build` needed.
178
+ Releases are driven by [Changesets](https://github.com/changesets/changesets) on every push to `main`:
59
179
 
60
- The package's `exports` field resolves to `src/index.ts` for workspace
61
- consumers. `publishConfig` overrides it to `dist/...` at publish time so
62
- npm consumers get the compiled artifact.
180
+ 1. Add a changeset describing your change: `pnpm changeset`
181
+ 2. Open a PR; CI gates on lint + typecheck + tests + lib build + docs build.
182
+ 3. On merge to `main`, the release workflow opens (or updates) a `Version Packages` PR that bumps the version and regenerates `CHANGELOG.md`.
183
+ 4. Merging that PR publishes to npm with provenance attestation and creates a GitHub Release.
63
184
 
64
- ## Releasing
185
+ For per-branch preview publishes on non-`main` branches, a snapshot workflow auto-publishes under a sanitized branch dist-tag — install with `pnpm add @schmooky/zvuk@<branch>`.
65
186
 
66
- Releases are managed by [Changesets](https://github.com/changesets/changesets):
187
+ ## CLI
67
188
 
68
189
  ```bash
69
- pnpm changeset # describe your change (patch / minor / major)
70
- git add .changeset/*.md && git commit -m "feat: describe it"
71
- git push # PR + merge to main
190
+ npx @schmooky/zvuk transcode raw/*.wav # ffmpeg ladder → webm/opus + m4a/aac
191
+ npx @schmooky/zvuk gen bank.json # typed sound-name module from a manifest
72
192
  ```
73
193
 
74
194
  ## Credits
75
195
 
76
- The demo audio shipped under [docs/public/audio/](docs/public/audio/) includes
77
- selections from [Kenney's "Digital Audio" pack](https://kenney.nl/assets/digital-audio),
78
- released under [CC0](https://creativecommons.org/publicdomain/zero/1.0/) — used here
79
- without modification. Kenney's full license file is preserved alongside those assets in
80
- [docs/public/audio/KENNEY-LICENSE.txt](docs/public/audio/KENNEY-LICENSE.txt). All other
81
- audio in the repo is original to this project.
196
+ The demo audio shipped under [`docs/public/audio/`](docs/public/audio/) includes selections from [Kenney's Digital Audio pack](https://kenney.nl/assets/digital-audio), released under [CC0](https://creativecommons.org/publicdomain/zero/1.0/) and used here without modification. Kenney's full license file is preserved at [`docs/public/audio/KENNEY-LICENSE.txt`](docs/public/audio/KENNEY-LICENSE.txt). All other audio is original to this project.
82
197
 
83
198
  ## License
84
199
 
85
- MIT for source code. Demo audio attributions live above.
200
+ [MIT](./LICENSE) © schmooky
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schmooky/zvuk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Audio Engine for the Web — Wwise-grade routing, sprites, sidechain ducking. Tiny, ESM-only, type-safe.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "type": "git",
27
27
  "url": "git+https://github.com/schmooky/zvuk.git"
28
28
  },
29
- "homepage": "https://zvuk.dev",
29
+ "homepage": "https://zvuk.schmooky.dev",
30
30
  "bugs": {
31
31
  "url": "https://github.com/schmooky/zvuk/issues"
32
32
  },