audiobits 0.1.3 → 0.1.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # audiobits
2
2
 
3
+ ## 0.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 5340645: Simplify the package README to a tested quick start and direct detailed guidance to the website docs. Clarify installed-version authority in the shipped integration Skill.
8
+
3
9
  ## 0.1.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,23 +1,22 @@
1
1
  # AudioBits
2
2
 
3
- [Website and documentation](https://audiobits.joacod.com/)
3
+ Browser-native procedural sound for games and interactive applications. Play
4
+ bundled sounds or build editable JSON recipes without downloaded audio assets
5
+ or runtime dependencies.
4
6
 
5
- AudioBits is available on npm as `audiobits`. It includes confirmation, impact, thruster, tactile click, gentle rejection,
6
- glass notification, whoosh and power-up; schema-1 recipes; play/live controls; seeded variation; bounded
7
- voices; bus gain, mute and routing; native output taps; and explicit lifecycle APIs.
8
- Current Chromium is the only automated browser verification target. Other
9
- browsers and operating systems are unverified and deliberately deferred. Maintainer listening acceptance for the
10
- unchanged sound definitions is recorded separately.
7
+ [Live gallery](https://audiobits.joacod.com/sounds) ·
8
+ [Documentation](https://audiobits.joacod.com/docs)
11
9
 
12
10
  ## Quick start
13
11
 
12
+ Install in a browser application with a bundler:
13
+
14
14
  ```sh
15
15
  npm install audiobits
16
16
  ```
17
17
 
18
- Use a browser bundler. Create the engine and sound once; run the final two lines
19
- inside a user gesture handler, such as a button click. Call `audio.start()`
20
- directly in that handler and await it before playback.
18
+ Create the engine and sound once. Construction is silent; call `play()` directly
19
+ from a user gesture, such as a button click. It awaits activation before playback.
21
20
 
22
21
  ```ts
23
22
  import { createAudio } from "audiobits";
@@ -26,297 +25,41 @@ import { confirmation } from "audiobits/recipes";
26
25
  const audio = createAudio();
27
26
  const sound = audio.sound(confirmation);
28
27
 
29
- await audio.start();
30
- sound.play();
31
- ```
32
-
33
- Surface activation failures and retry from a fresh gesture. Use
34
- `audio.stopAll({ tails: "cut" })` to stop playback and `await audio.dispose()`
35
- when the host is removed. See the production lifecycle example below for
36
- hiding and navigation.
37
-
38
- ## Production lifecycle
39
-
40
- For an SPA, invalidate pending activation when hiding or unmounting; suspend on
41
- hide and dispose on navigation. Returning requires a fresh Play gesture.
42
-
43
- ```ts
44
- import { createAudio } from "audiobits";
45
- import { confirmation } from "audiobits/recipes";
46
- const audio = createAudio();
47
- const sound = audio.sound(confirmation);
48
- let request = 0;
49
28
  export async function play() {
50
- const token = ++request;
51
29
  await audio.start();
52
- if (token === request && !document.hidden) sound.play({ seed: 42 });
30
+ sound.play();
53
31
  }
54
32
  export function stop() {
55
- request++;
56
33
  audio.stopAll({ tails: "cut" });
57
34
  }
58
- function hide() {
59
- if (document.hidden) {
60
- stop();
61
- void audio.suspend().catch(console.error);
62
- }
63
- }
64
- document.addEventListener("visibilitychange", hide);
65
35
  export async function dispose() {
66
- stop();
67
- document.removeEventListener("visibilitychange", hide);
68
36
  await audio.dispose();
69
37
  }
70
38
  ```
71
39
 
72
- `createAudio()` and `audio.sound()` create no context. A failed start reports
73
- `AudioBitsError` with a retryable `start-failed` code. A blocked resume times out
74
- after two wall-clock seconds; the context stays owned for gesture retry. Play
75
- before activation fails with `not-ready`; no input is queued.
76
-
77
- The archive exports `audiobits/schema.json` and `audiobits/capabilities.json`.
78
- The latter identifies package version, shipped primitives, initial Chromium gate and verification browser matrix;
79
- the schema is structural, while `validateRecipe` enforces additional semantic
80
- limits. Agent guidance is included in [the AudioBits Skill](skill/SKILL.md).
81
-
82
- ## Supported data
83
-
84
- `defineSound(recipe)` accepts typed authored data, preserves recipe structure, literal parameter names and modes, validates and returns a deeply frozen `Recipe` snapshot.
85
- Runtime validation remains authoritative for exact schema validity.
86
- For external JSON, `validateRecipe(unknown)` returns `{ ok: true, recipe }` or
87
- `{ ok: false, issues }`; every issue has `code`, `path`, and `message`.
88
- Paths use JSON bracket notation, such as `$["layers"][0]["id"]`.
89
- `AudioBitsError` carries `code` and `issues`; errors during validation use
90
- `invalid-recipe`. The input must be plain JSON data without accessors or cycles.
91
- Unknown fields and versions are rejected. Validation is browser-independent.
40
+ Surface rejected activation, for example `void play().catch(console.error)`, and
41
+ retry from a fresh gesture. Bind `stop()` to Stop and await `dispose()` when the
42
+ host is removed. For pending activation, page hiding, and navigation, follow the
43
+ [lifecycle guide](https://audiobits.joacod.com/docs/lifecycle).
92
44
 
93
- Schema version 1 supports:
45
+ ## Sounds and controls
94
46
 
95
- - One-shot gates in `(0, 60]` seconds or sustained playback until Stop, with
96
- 1–16 uniquely identified layers. Sustained recipes forbid `duration`.
97
- - Sine, triangle, sawtooth, and square oscillators; numeric Hz or linear/
98
- exponential frequency automation beginning at zero and ending by gate close
99
- (at most 60 seconds of onset automation for sustained voices). White noise
100
- uses bounded generated buffers; there is no audio-file fetch.
101
- - Layer gain from -60 to 0 dB and fixed ADSR envelopes. Attack/decay are 0–10 s,
102
- sustain is 0–1, release is 0.005–10 s. Effective attack is at least 0.002 s;
103
- effective attack plus decay must fit within the gate. A zero decay ramps
104
- directly to sustain rather than introducing an instantaneous peak.
105
- - Lowpass/highpass/bandpass filters with frequency 20–20000 Hz and numeric
106
- Q 0.1–20. At most eight filters and 128 frequency points across the recipe.
107
- - Source/filter frequencies accept numeric values, mappings, variation, or
108
- automation. Layer gain accepts numeric values, mappings, or variation;
109
- gain automation and variable envelope times are not supported.
110
- - Up to 16 named parameters with `min < max`, an in-range `default`, and `mode`
111
- of `play` or `live`. Live parameters require `smoothing` in 0.005–1 seconds.
112
- Names begin with an ASCII letter and contain letters, digits or underscores,
113
- up to 64 characters. Declaration numbers are bounded to -60000–60000.
47
+ Eight bundled sounds are available from `audiobits/recipes`: confirmation, impact,
48
+ thruster, tactile click, gentle rejection, glass notification, whoosh, and power-up.
49
+ Use [custom JSON recipes](https://audiobits.joacod.com/docs/recipes) with
50
+ `defineSound()` for typed authoring or `validateRecipe()` for external data.
114
51
 
115
- Depth is limited to 16, visited values to 10000, and diagnostics to 100.
116
- Source/filter frequencies must be below the owning context's Nyquist frequency
117
- at playback, including all mapping/variation extrema. Other effects,
118
- expression strings, sequencing, and continuous random modulation are rejected.
119
- The generated schema is available as `recipeSchema` or `audiobits/schema.json`.
120
-
121
- ## Runtime ownership
122
-
123
- `createAudio({ maxVoices, maxVoicesPerSound, masterGainDb })` defaults to
124
- 32 active voices per engine, eight per sound, and -12 dB master gain. Limits
125
- must be integers from 1–128; master gain must be -60–0 dB. `setMuted(boolean)`
126
- uses a separate mute setting and a 5 ms gain ramp.
127
-
128
- `sound.play({ at, gainDb, pan, parameters, seed, bus })` creates fresh sources synchronously. `at` is
129
- absolute audio-context time, obtained by the host's own scheduling logic;
130
- available after startup as `audio.native.context.currentTime`. Omit it for
131
- immediate playback. Past timestamps are rejected. Playback gain is -60–0 dB
132
- (default 0), pan is -1–1 (default 0). Future voices reserve capacity.
133
-
134
- `voice.stop()` cancels before onset or releases from the current envelope value.
135
- Repeated stops cannot extend lifetime. `voice.ended` resolves after owned nodes
136
- are disconnected; `voice.state` is `active`, `stopping`, `retiring`, or `ended`.
137
- Stopping voices keep their capacity reservation until cleanup. Oldest-voice
138
- stealing uses a 5 ms output fade. There is at most one retiring voice beyond
139
- engine/per-sound limits; another steal finalizes the previous retiree first.
140
- `audio.counts` distinguishes reserved active/stopping voices from retirees.
141
-
142
- Gate duration excludes release. Filters receive a bounded 50 ms tail allowance;
143
- output fades to zero over the final 5 ms. Layer filters precede their envelopes.
144
- `stopAll()` releases managed voices according to their recipe envelopes.
145
- `stopAll({ tails: "cut" })` uses a 5 ms source/output fade. `sound.dispose()` immediately finalizes
146
- that sound's voices and noise buffers. `audio.suspend()` invalidates pending starts and finalizes all voices before suspending.
147
- Native suspension/interruption also finalizes voices when its state event arrives.
148
- `audio.dispose()` invalidates pending startup, finalizes voices immediately,
149
- disconnects master output, and closes the context once, even while suspended.
150
- Disposal is terminal and idempotent; no audio-clock progress is needed.
151
-
152
- `audio.state` reports `idle`, `starting`, `running`, `suspended`, `interrupted`,
153
- `closed`, or `disposed`. `subscribe(listener)` returns an unsubscribe function.
154
- Concurrent starts share one promise. A host controls visibility/navigation policy;
155
- the engine does not replay sounds or automatically resume them.
156
-
157
- Recipes contain no native nodes, callbacks, framework imports, or runtime
158
- dependencies. Only `audiobits/recipes` imports curated sound data.
159
- Default headroom checks do not guarantee safe peaks for arbitrary recipes,
160
- filter resonance, gains, or concurrency.
161
-
162
- ## Dynamic controls and replay
163
-
164
- ```ts
165
- import { createAudio } from "audiobits";
166
- import { impact, thruster } from "audiobits/recipes";
167
-
168
- const audio = createAudio();
169
- const hit = audio.sound(impact);
170
- const engine = audio.sound(thruster);
171
-
172
- // In a user gesture, await activation before creating voices.
173
- await audio.start();
174
- hit.play({ parameters: { intensity: 0.8 }, seed: 42 });
175
- const voice = engine.play({ parameters: { throttle: 0.2 }, seed: 42 });
176
- voice.set({ throttle: 1 }); // Update this voice without retriggering.
177
- console.log(voice.seed, voice.parameters);
178
- voice.stop();
179
- await voice.ended;
180
- await audio.dispose();
181
- ```
52
+ [Parameters and seeds](https://audiobits.joacod.com/docs/parameters) vary playback
53
+ and update live controls. [Buses](https://audiobits.joacod.com/docs/buses) provide
54
+ gain, mute, and routing; [native taps](https://audiobits.joacod.com/docs/native)
55
+ connect caller-owned analysers and nodes.
182
56
 
183
- Omitted parameters use recipe defaults. Invalid names, non-finite values,
184
- out-of-range controls, and invalid seeds fail before graph allocation or voice
185
- stealing. Updates validate every supplied key before changing any parameter;
186
- play-only controls cannot be updated. `voice.parameters` is a frozen snapshot of
187
- requested values, not a readback of the current smoothed native parameters.
188
- `voice.set()` after Stop, retirement, completion, or disposal throws
189
- `ended-voice`; other control errors use `invalid-control`.
57
+ The [API reference](https://audiobits.joacod.com/docs/api) explains public options
58
+ and limits. Exported types, `audiobits/schema.json`, and
59
+ `audiobits/capabilities.json` describe the installed package; semantic validation
60
+ still requires `validateRecipe()`. Integration guidance also ships in the
61
+ [AudioBits Skill](skill/SKILL.md).
190
62
 
191
- Mappings use `{ control, range: [low, high], scale }`, where scale is `linear`
192
- or `exponential`. Exponential mapping endpoints must be positive. Mapping ranges
193
- may descend; random ranges `{ random: [low, high] }` must be ordered. All extrema
194
- must satisfy the target range. Automation points can reference only play-only
195
- controls. Direct live mappings support source frequency, layer gain, and filter
196
- frequency. Native targets ramp linearly over the parameter's smoothing time,
197
- from their current value on every retarget. For gain, that ramp is in linear
198
- amplitude after dB conversion; mapping scale describes the control-to-target
199
- conversion, not the ramp curve. Envelopes remain fixed and independent of live
200
- level controls, so release remains continuous.
201
-
202
- Seeds are unsigned 32-bit integers, including zero. Without one, playback chooses
203
- a seed and exposes it on `voice.seed`. xorshift32 uses shifts 13/17/5 and divides
204
- its unsigned state by 2^32; seed zero maps internally to `0x6d2b79f5`. Resolution
205
- traverses root effects, then layers in array order. Each layer resolves gain,
206
- layer filters, source frequency, and a noise seed, in that order; automation
207
- points follow time order. Each variation consumes one draw, and each noise layer
208
- consumes one draw for its own xorshift32 stream. Object property insertion order
209
- does not change this traversal. This algorithm reproduces choices and
210
- noise for the same normalized recipe, controls, seed and sample rate; it does not
211
- promise identical oscillator/filter samples across browsers or sample rates.
212
-
213
- ## Noise ownership and bounds
214
-
215
- Each noise layer uses a bounded generated mono buffer at the context sample rate,
216
- looped with a crossfade for finite and sustained playback. Noise generation is
217
- reproducible for the same recipe, controls, seed and sample rate. There is no
218
- shared noise cache or rendered-output cache.
219
-
220
- Noise supports integer sample rates from 8000 through 192000 Hz. Unsupported
221
- rates fail with `noise-rate` before voice allocation. Recipe layer limits and
222
- engine/sound voice limits bound concurrent noise resources.
223
-
224
- Control updates allocate no new audio nodes or buffers. Finishing a voice clears
225
- its buffer-source references and disconnects owned nodes, including cancellation
226
- before onset, stealing, sound disposal, and engine teardown. Browser-internal
227
- reclamation timing remains outside the library's control.
228
-
229
- ## Buses and routing
230
-
231
- After `await audio.start()`, `audio.master` is the root bus. `audio.bus(name,
232
- parent = audio.master)` creates a named bus or reuses the live bus with that
233
- name; use `setParent()` to move an existing bus. Names contain 1–64 characters
234
- and cannot be blank. At most 32 buses, including master, may be live. Routes
235
- form a single-parent tree; invalid, disposed, foreign-engine, and cyclic
236
- parents fail before changing the previous connection. Reassigning the same
237
- parent does not create another route. `sound.play({ bus })` defaults to master
238
- and rejects foreign/disposed buses before voice allocation or stealing.
239
-
240
- `bus.setGainDb(value, rampSeconds = 0.005)` accepts -60–0 dB and 0–10 seconds.
241
- It holds the current native value before ramping. `bus.setMuted(boolean)` uses
242
- an independent 5 ms stage, preserving volume automation. `audio.setMuted()`
243
- controls master mute, including a setting made before startup.
244
-
245
- ```ts
246
- import { createAudio } from "audiobits";
247
- import { confirmation } from "audiobits/recipes";
248
- const audio = createAudio();
249
- const sound = audio.sound(confirmation);
250
- // In a gesture handler, after activating this engine:
251
- await audio.start();
252
- const effects = audio.bus("effects");
253
- effects.setGainDb(-6, 0.1);
254
- const voice = sound.play({ bus: effects });
255
- voice.stop(); // Release this voice.
256
- audio.stopAll({ tails: "cut" }); // Fade managed voices over 5 ms.
257
- effects.dispose(); // Finalize routed voices and descendant buses.
258
- await audio.dispose();
259
- ```
260
-
261
- Each bus owns two gain nodes. Suspension and disposal finalize voices
262
- without waiting for audio-clock progress.
263
-
264
- Non-master bus disposal is idempotent and stops routed voices recursively.
265
- A later lookup of that name creates a fresh bus. `master.dispose()` fails;
266
- dispose the engine to release master. Engine disposal removes all owned
267
- output and closes its context, even while suspended or starting.
268
-
269
- ## Native analyser and caller ownership
270
-
271
- `audio.native` is available after startup and exposes the owned `context`,
272
- master `output`, and `connect(node)` tap helper. The helper rejects foreign
273
- contexts, duplicate taps, the output itself, and the context destination.
274
- It returns an idempotent detach function. Master already connects to the
275
- speaker destination. Leave an analyser's output unconnected to avoid a second
276
- audible path. The vanilla example reads peak levels with a host animation
277
- frame, cancels that frame, detaches the tap, and disconnects its analyser
278
- before engine teardown.
279
-
280
- ```ts
281
- import { createAudio } from "audiobits";
282
- const audio = createAudio();
283
- // Execute in a gesture handler.
284
- await audio.start();
285
- const native = audio.native;
286
- const analyser = native.context.createAnalyser();
287
- const detach = native.connect(analyser);
288
- const samples = new Float32Array(analyser.fftSize);
289
- analyser.getFloatTimeDomainData(samples);
290
- // Host teardown:
291
- detach();
292
- analyser.disconnect();
293
- await audio.dispose();
294
- ```
295
-
296
- Caller-created nodes, sources, connections, and animation listeners are
297
- caller-owned. Stop unmanaged sources explicitly: `stopAll()` cannot stop them.
298
- Direct native graph operations remain the caller's responsibility and cannot
299
- be serialized as recipes. Closing the engine context invalidates these native
300
- nodes; retained native handles do not transfer ownership back to the engine.
301
-
302
- The site and vanilla demo invalidate pending Play actions, cut managed tails,
303
- and suspend on hide. Returning does not resume; a fresh gesture starts audio.
304
- Late activation after suspension is cancelled and cannot replay an old request.
305
- The engine also clears owned voices/effects on native interruption; automatic
306
- native recovery is suspended until a fresh `start()` request. Physical OS
307
- interruption still requires manual evidence. Automated checks do not establish
308
- physical-device compatibility.
309
-
310
- Buses provide gain, mute, and routing. Shared effects are deferred until
311
- multiple real sound requirements justify an API.
312
-
313
- ## Curated sounds
314
-
315
- The eight exports live in `audiobits/recipes`: `confirmation`, `impact`, `thruster`,
316
- `tactileClick`, `gentleRejection`, `glassNotification`, `whoosh`, and `powerUp`.
317
- Intensity controls impact, click and power-up; brightness controls glass; size
318
- controls whoosh; throttle is live on thruster. Other sounds have no parameters.
319
- New sound definitions use only schema-1 sources, filters and envelopes. Their
320
- signal and resource properties are tested; the current eight curated sounds have
321
- passed the maintainer listening gate in Chrome. Output devices and detailed
322
- listening coverage were not specified.
63
+ Current Chromium is the only automated browser verification target. Other
64
+ browsers and operating systems are unverified. Automated checks do not establish
65
+ subjective listening quality or physical-device compatibility.
@@ -1,5 +1,5 @@
1
1
  {
2
- "packageVersion": "0.1.3",
2
+ "packageVersion": "0.1.4",
3
3
  "schemaVersion": 1,
4
4
  "status": "stable",
5
5
  "recipe": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "audiobits",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Procedural browser audio: versioned recipes, live controls, managed voices and buses.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://audiobits.joacod.com/",
package/skill/SKILL.md CHANGED
@@ -19,8 +19,13 @@ sounds without browser activation, then invoke `start()` synchronously inside
19
19
  a user gesture and await it before `play()`. Surface failures and allow a fresh
20
20
  gesture retry. Never queue playback across Stop, hiding, or disposal.
21
21
 
22
- Use the [package quick start and API reference](../README.md) for activation,
23
- validation, ownership, limits, seeded replay, and native interop. Read the
22
+ Use the installed package's exported types, schema, capabilities, and actual
23
+ version to determine supported options and limits. The current website may
24
+ postdate an older installed package. Consult the [API guide](https://audiobits.joacod.com/docs/api),
25
+ [lifecycle](https://audiobits.joacod.com/docs/lifecycle),
26
+ [seeded replay](https://audiobits.joacod.com/docs/parameters), and
27
+ [native interop](https://audiobits.joacod.com/docs/native) for human-readable guidance,
28
+ checking it against the installed contracts. Read the
24
29
  [controlled sound example](references/controls.md) for live thruster and bus setup.
25
30
 
26
31
  Keep recipe data JSON-only. Run `validateRecipe` for semantic validation;
@@ -1,8 +1,10 @@
1
1
  # Controlled sound and routing
2
2
 
3
3
  Call `play()` directly from a gesture. Surface rejected promises, bind Stop,
4
- and call `dispose()` when the host unmounts. See the package reference for
5
- bus limits and caller-owned native nodes.
4
+ and call `dispose()` when the host unmounts. See the
5
+ [bus guide](https://audiobits.joacod.com/docs/buses) and
6
+ [native ownership guide](https://audiobits.joacod.com/docs/native), checking options
7
+ against the installed package's exported types and capabilities.
6
8
 
7
9
  ```ts
8
10
  import { createAudio } from "audiobits";