@zsherman/sound 0.0.0-stage → 0.1.0

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 (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +373 -0
  3. package/README.md +16 -2
  4. package/dist/dom/engine/cues.js +69 -0
  5. package/dist/dom/engine/engine.js +104 -0
  6. package/dist/dom/engine/index.js +4 -0
  7. package/dist/dom/engine/synth.js +172 -0
  8. package/dist/dom/engine/types.js +0 -0
  9. package/dist/dom/index.js +9 -0
  10. package/dist/dom/sound-provider/index.js +1 -0
  11. package/dist/dom/sound-provider/sound-provider.js +75 -0
  12. package/dist/dom/themes/glass.js +47 -0
  13. package/dist/dom/themes/index.js +5 -0
  14. package/dist/dom/themes/mechanical.js +46 -0
  15. package/dist/dom/themes/score.js +210 -0
  16. package/dist/dom/themes/soft.js +28 -0
  17. package/dist/solid/engine/cues.jsx +69 -0
  18. package/dist/solid/engine/engine.jsx +104 -0
  19. package/dist/solid/engine/index.jsx +4 -0
  20. package/dist/solid/engine/synth.jsx +172 -0
  21. package/dist/solid/engine/types.jsx +0 -0
  22. package/dist/solid/index.jsx +9 -0
  23. package/dist/solid/sound-provider/index.jsx +1 -0
  24. package/dist/solid/sound-provider/sound-provider.jsx +66 -0
  25. package/dist/solid/themes/glass.jsx +47 -0
  26. package/dist/solid/themes/index.jsx +5 -0
  27. package/dist/solid/themes/mechanical.jsx +46 -0
  28. package/dist/solid/themes/score.jsx +210 -0
  29. package/dist/solid/themes/soft.jsx +28 -0
  30. package/dist/types/engine/cues.d.ts +21 -0
  31. package/dist/types/engine/engine.d.ts +42 -0
  32. package/dist/types/engine/index.d.ts +6 -0
  33. package/dist/types/engine/synth.d.ts +28 -0
  34. package/dist/types/engine/types.d.ts +65 -0
  35. package/dist/types/index.d.ts +3 -0
  36. package/dist/types/sound-provider/index.d.ts +2 -0
  37. package/dist/types/sound-provider/sound-provider.d.ts +55 -0
  38. package/dist/types/themes/glass.d.ts +7 -0
  39. package/dist/types/themes/index.d.ts +5 -0
  40. package/dist/types/themes/mechanical.d.ts +7 -0
  41. package/dist/types/themes/score.d.ts +14 -0
  42. package/dist/types/themes/soft.d.ts +6 -0
  43. package/docs/api.json +55 -0
  44. package/docs/llms.txt +39 -0
  45. package/docs/search-index.json +25 -0
  46. package/docs/sound-provider.md +152 -0
  47. package/docs/sounds.md +203 -0
  48. package/package.json +51 -4
@@ -0,0 +1,104 @@
1
+ import { soft } from "../themes/soft.jsx";
2
+ import { cooldown } from "./cues.jsx";
3
+ import { createBus, scheduleCue } from "./synth.jsx";
4
+ // src/engine/engine.ts
5
+ /** How long the context runs after the last cue ends before it's suspended (saves battery), in ms. */
6
+ const IDLE_MS = 4e3;
7
+ /** A cue still waiting this long for audio to resume is stale (the moment passed): dropped, in ms. */
8
+ const STALE_MS = 150;
9
+ /**
10
+ * The sound engine: plays cues by building them from oscillators and filtered noise at play time. Safe to
11
+ * create on the server and before any gesture: the audio context starts at the first play the browser
12
+ * allows (after the page's first tap, click or key press), and cues before that are dropped, not queued.
13
+ *
14
+ * @example
15
+ * const sound = createSoundEngine({ volume: 0.6 });
16
+ * button.addEventListener("click", () => sound.play("success"));
17
+ */
18
+ function createSoundEngine(options = {}) {
19
+ const settings = {
20
+ theme: options.theme ?? soft,
21
+ volume: options.volume ?? .7,
22
+ muted: options.muted ?? false,
23
+ humanize: options.humanize ?? true
24
+ };
25
+ const listeners = /* @__PURE__ */ new Set();
26
+ const last = /* @__PURE__ */ new Map();
27
+ let ctx;
28
+ let bus;
29
+ let idle;
30
+ let disposed = false;
31
+ const browser = () => typeof window !== "undefined" && typeof window.AudioContext === "function";
32
+ const allowed = () => navigator.userActivation?.hasBeenActive ?? true;
33
+ function context() {
34
+ if (ctx && ctx.state !== "closed") return ctx;
35
+ ctx = new AudioContext({ latencyHint: "interactive" });
36
+ bus = createBus(ctx);
37
+ return ctx;
38
+ }
39
+ function sleepLater(end) {
40
+ clearTimeout(idle);
41
+ const c = ctx;
42
+ if (!c) return;
43
+ const ms = Math.max(0, (end - c.currentTime) * 1e3) + IDLE_MS;
44
+ idle = setTimeout(() => {
45
+ if (c.state === "running") c.suspend().catch(() => {});
46
+ }, ms);
47
+ }
48
+ function emit(played) {
49
+ for (const listener of listeners) listener(played);
50
+ }
51
+ return {
52
+ play(cue, opts = {}) {
53
+ if (disposed || settings.muted || !browser()) return false;
54
+ const now = performance.now();
55
+ if (now - (last.get(cue) ?? -Infinity) < cooldown(cue)) return false;
56
+ last.set(cue, now);
57
+ const theme = opts.theme ?? settings.theme;
58
+ const report = (sounded) => (emit({
59
+ cue,
60
+ theme: theme.name,
61
+ options: opts,
62
+ sounded
63
+ }), sounded);
64
+ if (document.visibilityState === "hidden" || !ctx && !allowed()) return report(false);
65
+ const c = context();
66
+ const volume = settings.volume * (opts.volume ?? 1);
67
+ const start = () => {
68
+ if (!bus || c !== ctx) return;
69
+ sleepLater(scheduleCue(c, bus, theme, cue, opts, c.currentTime + .005, volume, settings.humanize));
70
+ };
71
+ if (c.state === "running") start();
72
+ else if (!allowed()) return report(false);
73
+ else c.resume().then(() => performance.now() - now < STALE_MS && start(), () => {});
74
+ return report(true);
75
+ },
76
+ async unlock() {
77
+ if (disposed || !browser()) return false;
78
+ try {
79
+ const c = context();
80
+ if (c.state !== "running") await Promise.race([c.resume(), new Promise((done) => setTimeout(done, 300))]);
81
+ return c.state === "running";
82
+ } catch {
83
+ return false;
84
+ }
85
+ },
86
+ set(next) {
87
+ Object.assign(settings, Object.fromEntries(Object.entries(next).filter(([, v]) => v !== void 0)));
88
+ },
89
+ get: () => ({ ...settings }),
90
+ subscribe(listener) {
91
+ listeners.add(listener);
92
+ return () => listeners.delete(listener);
93
+ },
94
+ dispose() {
95
+ disposed = true;
96
+ clearTimeout(idle);
97
+ listeners.clear();
98
+ ctx?.close().catch(() => {});
99
+ ctx = void 0;
100
+ bus = void 0;
101
+ }
102
+ };
103
+ }
104
+ export { createSoundEngine };
@@ -0,0 +1,4 @@
1
+ import { createSoundEngine } from "./engine.jsx";
2
+ import { cueDuration, renderCue } from "./synth.jsx";
3
+ import { cueFamilies, cueNames } from "./cues.jsx";
4
+ export { createSoundEngine, cueDuration, cueFamilies, cueNames, renderCue };
@@ -0,0 +1,172 @@
1
+ import { roomShare } from "./cues.jsx";
2
+ // src/engine/synth.ts
3
+ /** The most layers one cue plays; a theme's extra layers are ignored. */
4
+ const MAX_LAYERS = 12;
5
+ /** What emphasis does to a cue: its level, its length, its room, and its accent layers. */
6
+ const EMPHASIS = {
7
+ subtle: {
8
+ gain: .6,
9
+ decay: .75,
10
+ room: .5,
11
+ accent: 0
12
+ },
13
+ normal: {
14
+ gain: 1,
15
+ decay: 1,
16
+ room: 1,
17
+ accent: 1
18
+ },
19
+ strong: {
20
+ gain: 1.15,
21
+ decay: 1.25,
22
+ room: 1.6,
23
+ accent: 1.5
24
+ }
25
+ };
26
+ /** The level an envelope falls to before its last few milliseconds go linearly to zero (about −66 dB). */
27
+ const FLOOR = 5e-4;
28
+ /** The linear fade after the floor, so a voice never stops on a non-zero sample (a click). */
29
+ const FADE = .006;
30
+ const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
31
+ const hz = (f) => clamp(f, 20, 16e3);
32
+ /** A small seeded generator, so noise and the room are the same on every render (tests compare them). */
33
+ function random(seed) {
34
+ let s = seed >>> 0;
35
+ return () => {
36
+ s = s + 1831565813 >>> 0;
37
+ let t = s;
38
+ t = Math.imul(t ^ t >>> 15, t | 1);
39
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
40
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
41
+ };
42
+ }
43
+ const noiseBuffers = /* @__PURE__ */ new WeakMap();
44
+ /** A second of white noise per context, looped by every noise layer. */
45
+ function noise(ctx) {
46
+ let buffer = noiseBuffers.get(ctx);
47
+ if (!buffer) {
48
+ buffer = ctx.createBuffer(1, ctx.sampleRate, ctx.sampleRate);
49
+ const data = buffer.getChannelData(0);
50
+ const next = random(7);
51
+ for (let i = 0; i < data.length; i++) data[i] = next() * 2 - 1;
52
+ noiseBuffers.set(ctx, buffer);
53
+ }
54
+ return buffer;
55
+ }
56
+ /** The shared room: a short stereo tail of decaying noise, about 0.7 s, darker as it fades. */
57
+ function roomImpulse(ctx) {
58
+ const length = Math.round(ctx.sampleRate * .7);
59
+ const buffer = ctx.createBuffer(2, length, ctx.sampleRate);
60
+ for (let c = 0; c < 2; c++) {
61
+ const data = buffer.getChannelData(c);
62
+ const next = random(11 + c);
63
+ let low = 0;
64
+ for (let i = 0; i < length; i++) {
65
+ const t = i / length;
66
+ low += (next() * 2 - 1 - low) * (.6 - .5 * t);
67
+ data[i] = low * Math.pow(1 - t, 3) * (i < ctx.sampleRate * .008 ? i / (ctx.sampleRate * .008) : 1);
68
+ }
69
+ }
70
+ return buffer;
71
+ }
72
+ /** Builds the master chain on a context: master gain → limiter → speakers, and the room into the master. */
73
+ function createBus(ctx, limiter = true) {
74
+ const input = ctx.createGain();
75
+ if (limiter) {
76
+ const limit = ctx.createDynamicsCompressor();
77
+ limit.threshold.value = -8;
78
+ limit.knee.value = 4;
79
+ limit.ratio.value = 16;
80
+ limit.attack.value = .001;
81
+ limit.release.value = .12;
82
+ input.connect(limit).connect(ctx.destination);
83
+ } else input.connect(ctx.destination);
84
+ const room = ctx.createGain();
85
+ const convolver = ctx.createConvolver();
86
+ convolver.buffer = roomImpulse(ctx);
87
+ room.connect(convolver).connect(input);
88
+ return {
89
+ input,
90
+ room
91
+ };
92
+ }
93
+ /** How long a cue's layers ring, in seconds, before the room's tail. */
94
+ function cueDuration(theme, cue, options = {}) {
95
+ const decay = EMPHASIS[options.emphasis ?? "normal"].decay;
96
+ let end = 0;
97
+ for (const layer of theme.cues[cue].slice(0, 12)) end = Math.max(end, (layer.at ?? 0) + (layer.a ?? .002) + layer.d * decay + FADE);
98
+ return end;
99
+ }
100
+ /** One layer's nodes, scheduled from `start`. Returns when it ends. */
101
+ function voice(ctx, out, layer, start, pitch, decay, level, back) {
102
+ const a = Math.max(layer.a ?? .002, .001);
103
+ const d = Math.max(layer.d * decay, .005);
104
+ const peak = clamp(layer.peak, 0, .5) * level;
105
+ const end = start + a + d;
106
+ let from = hz(layer.f * pitch);
107
+ let to = layer.to === void 0 ? from : hz(layer.to * pitch);
108
+ if (back) [from, to] = [to, from];
109
+ const glide = Math.max(layer.glide ?? a + d, .001);
110
+ const env = ctx.createGain();
111
+ env.gain.setValueAtTime(0, start);
112
+ env.gain.linearRampToValueAtTime(peak, start + a);
113
+ env.gain.exponentialRampToValueAtTime(Math.min(FLOOR, peak / 2 || FLOOR), end);
114
+ env.gain.linearRampToValueAtTime(0, end + FADE);
115
+ let source;
116
+ let frequency;
117
+ if (layer.kind === "tone") {
118
+ const osc = ctx.createOscillator();
119
+ osc.type = layer.wave;
120
+ source = osc;
121
+ frequency = osc.frequency;
122
+ osc.connect(env);
123
+ } else {
124
+ const src = ctx.createBufferSource();
125
+ src.buffer = noise(ctx);
126
+ src.loop = true;
127
+ const filter = ctx.createBiquadFilter();
128
+ filter.type = layer.filter;
129
+ filter.Q.value = clamp(layer.q ?? 1, 1e-4, 40);
130
+ source = src;
131
+ frequency = filter.frequency;
132
+ src.connect(filter).connect(env);
133
+ }
134
+ frequency.setValueAtTime(from, start);
135
+ if (to !== from) frequency.exponentialRampToValueAtTime(to, start + glide);
136
+ env.connect(out);
137
+ source.start(start);
138
+ source.stop(end + FADE + .01);
139
+ return end + FADE;
140
+ }
141
+ /** Plays a cue on `bus` at `when` (the context's clock). Returns when its layers end. */
142
+ function scheduleCue(ctx, bus, theme, cue, options, when, volume, humanize) {
143
+ const emphasis = EMPHASIS[options.emphasis ?? "normal"];
144
+ const back = options.direction === "back";
145
+ const semitones = (options.pitch ?? 0) + (options.value === void 0 ? 0 : (clamp(options.value, 0, 1) - .5) * 12) + (back ? -2 : 0) + (humanize ? (Math.random() - .5) * .3 : 0);
146
+ const pitch = Math.pow(2, semitones / 12);
147
+ const level = volume * volume * theme.gain * emphasis.gain * (humanize ? .95 + Math.random() * .1 : 1);
148
+ const cueBus = ctx.createGain();
149
+ cueBus.connect(bus.input);
150
+ const send = ctx.createGain();
151
+ send.gain.value = clamp(theme.room * emphasis.room * roomShare(cue), 0, 1);
152
+ cueBus.connect(send).connect(bus.room);
153
+ let end = when;
154
+ for (const layer of theme.cues[cue].slice(0, 12)) {
155
+ const accent = layer.accent ? emphasis.accent : 1;
156
+ if (accent === 0) continue;
157
+ end = Math.max(end, voice(ctx, cueBus, layer, when + (layer.at ?? 0), pitch, emphasis.decay, level * accent, back));
158
+ }
159
+ return end;
160
+ }
161
+ /**
162
+ * Renders a cue to an `AudioBuffer` without a speaker (an `OfflineAudioContext`): for tests, waveforms, or a
163
+ * WAV file. No humanizing, so a render is the same every time. Browser only.
164
+ */
165
+ async function renderCue(theme, cue, options = {}) {
166
+ const sampleRate = options.sampleRate ?? 48e3;
167
+ const seconds = cueDuration(theme, cue, options) + (theme.room > 0 ? .75 : .02);
168
+ const ctx = new OfflineAudioContext(2, Math.ceil(seconds * sampleRate), sampleRate);
169
+ scheduleCue(ctx, createBus(ctx, options.limiter ?? true), options.theme ?? theme, cue, options, 0, options.volume ?? 1, false);
170
+ return ctx.startRendering();
171
+ }
172
+ export { MAX_LAYERS, createBus, cueDuration, renderCue, scheduleCue };
File without changes
@@ -0,0 +1,9 @@
1
+ import { defineTheme, score } from "./themes/score.jsx";
2
+ import { soft } from "./themes/soft.jsx";
3
+ import { cueFamilies, cueNames } from "./engine/cues.jsx";
4
+ import { cueDuration, renderCue } from "./engine/synth.jsx";
5
+ import { createSoundEngine } from "./engine/engine.jsx";
6
+ import { mechanical } from "./themes/mechanical.jsx";
7
+ import { glass } from "./themes/glass.jsx";
8
+ import { SoundProvider, useSound } from "./sound-provider/sound-provider.jsx";
9
+ export { SoundProvider, createSoundEngine, cueDuration, cueFamilies, cueNames, defineTheme, glass, mechanical, renderCue, score, soft, useSound };
@@ -0,0 +1 @@
1
+ export { SoundProvider, useSound } from "./sound-provider.jsx";
@@ -0,0 +1,66 @@
1
+ import { createSoundEngine } from "../engine/engine.jsx";
2
+ import { CueContext } from "@zsherman/kit/cues";
3
+ import { createContext, createEffect, onSettled, useContext } from "solid-js";
4
+ // src/sound-provider/sound-provider.tsx
5
+ const SoundContext = createContext(null);
6
+ /**
7
+ * Turns on the kit's sounds: inside it, components play their cues (a Switch `toggle-on`, a Dialog `open`, a
8
+ * toast `success`). Without it the kit is silent and none of the engine is in the bundle. No sound plays
9
+ * before the person's first tap, click or key press on the page.
10
+ *
11
+ * @example
12
+ * <SoundProvider muted={!soundOn()}>
13
+ * <App />
14
+ * </SoundProvider>
15
+ */
16
+ function SoundProvider(props) {
17
+ const outer = useContext(SoundContext);
18
+ let settings = {};
19
+ createEffect(() => ({
20
+ muted: props.muted,
21
+ volume: props.volume,
22
+ theme: props.theme,
23
+ cues: props.cues,
24
+ engine: props.engine
25
+ }), (next) => {
26
+ settings = next;
27
+ });
28
+ let own;
29
+ const engine = () => settings.engine ?? outer?.engine() ?? (own ??= createSoundEngine());
30
+ onSettled(() => () => own?.dispose());
31
+ const play = (cue, options = {}) => {
32
+ if (settings.muted) return;
33
+ const mapped = settings.cues?.[cue];
34
+ if (mapped === false) return;
35
+ const next = {
36
+ ...options,
37
+ volume: (settings.volume ?? 1) * (options.volume ?? 1),
38
+ theme: options.theme ?? settings.theme
39
+ };
40
+ if (outer && !settings.engine) outer.play(mapped ?? cue, next);
41
+ else engine().play(mapped ?? cue, next);
42
+ };
43
+ const cuePlayer = (cue, options) => play(cue, options);
44
+ return <SoundContext value={{
45
+ play,
46
+ engine
47
+ }}>
48
+ <CueContext value={cuePlayer}>{props.children}</CueContext>
49
+ </SoundContext>;
50
+ }
51
+ /**
52
+ * Plays cues from your own code: a sent message, a finished upload, a game. Call `play` from the handler, after
53
+ * the visible change.
54
+ *
55
+ * @example
56
+ * const sound = useSound();
57
+ * <Button onClick={() => { save(); sound.play("success"); }}>Save</Button>
58
+ */
59
+ function useSound() {
60
+ const context = useContext(SoundContext);
61
+ return {
62
+ play: (cue, options) => context?.play(cue, options),
63
+ engine: () => context?.engine()
64
+ };
65
+ }
66
+ export { SoundProvider, useSound };
@@ -0,0 +1,47 @@
1
+ import { CEILING, defineTheme } from "./score.jsx";
2
+ // src/themes/glass.ts
3
+ /**
4
+ * Glass: bright struck bars that ring. Tones go up a fifth and last longer, with the inharmonic partials of a
5
+ * free bar (2.76× and 5.4×) dying away first; noise rings through narrow filters; a larger room. For calm,
6
+ * airy products and moments that should feel light.
7
+ */
8
+ const glass = /* @__PURE__ */ defineTheme("glass", .3, .85, (layer) => {
9
+ if (layer.kind === "noise") return [{
10
+ ...layer,
11
+ f: Math.min(layer.f * 1.6, CEILING),
12
+ to: layer.to && Math.min(layer.to * 1.6, 12e3),
13
+ q: (layer.q ?? 1) * 6,
14
+ peak: layer.peak * .6
15
+ }];
16
+ const f = layer.f * 1.5;
17
+ const to = layer.to && layer.to * 1.5;
18
+ const layers = [{
19
+ ...layer,
20
+ wave: "sine",
21
+ f,
22
+ to,
23
+ a: Math.max(layer.a ?? 0, .002),
24
+ d: layer.d * 1.5
25
+ }];
26
+ for (const [ratio, level, decay] of [[
27
+ 2.76,
28
+ .35,
29
+ .5
30
+ ], [
31
+ 5.4,
32
+ .12,
33
+ .25
34
+ ]]) {
35
+ if (f * ratio > 12e3 || layer.accent && ratio > 3) continue;
36
+ layers.push({
37
+ ...layer,
38
+ wave: "sine",
39
+ f: f * ratio,
40
+ to: to && to * ratio,
41
+ peak: layer.peak * level,
42
+ d: layer.d * 1.5 * decay
43
+ });
44
+ }
45
+ return layers;
46
+ });
47
+ export { glass };
@@ -0,0 +1,5 @@
1
+ import { soft } from "./soft.jsx";
2
+ import { mechanical } from "./mechanical.jsx";
3
+ import { glass } from "./glass.jsx";
4
+ import { defineTheme, score } from "./score.jsx";
5
+ export { defineTheme, glass, mechanical, score, soft };
@@ -0,0 +1,46 @@
1
+ import { CEILING, defineTheme } from "./score.jsx";
2
+ // src/themes/mechanical.ts
3
+ /**
4
+ * Mechanical: dry keycaps and switches. Each tone becomes a contact click (narrow noise) over a short
5
+ * triangle body and a low thock; transients halve, and there's almost no room. For tools, terminals and
6
+ * dense, fast UI.
7
+ */
8
+ const mechanical = /* @__PURE__ */ defineTheme("mechanical", .03, 1.6, (layer) => {
9
+ if (layer.kind === "noise") return [{
10
+ ...layer,
11
+ q: (layer.q ?? 1) * 1.5,
12
+ d: layer.d * .6,
13
+ peak: layer.peak * 1.3
14
+ }];
15
+ const click = {
16
+ kind: "noise",
17
+ filter: "bandpass",
18
+ f: Math.min(layer.f * 2.5, CEILING),
19
+ q: 3,
20
+ at: layer.at,
21
+ d: .008,
22
+ peak: layer.peak * .7,
23
+ accent: layer.accent
24
+ };
25
+ const body = {
26
+ ...layer,
27
+ wave: layer.wave === "sine" ? "triangle" : layer.wave,
28
+ a: .001,
29
+ d: layer.d * .5
30
+ };
31
+ const thock = {
32
+ ...layer,
33
+ wave: "square",
34
+ f: layer.f * .5,
35
+ to: layer.to && layer.to * .5,
36
+ a: .001,
37
+ d: Math.min(layer.d * .3, .03),
38
+ peak: layer.peak * .18
39
+ };
40
+ return layer.accent ? [click, body] : [
41
+ click,
42
+ body,
43
+ thock
44
+ ];
45
+ });
46
+ export { mechanical };
@@ -0,0 +1,210 @@
1
+ // src/themes/score.ts
2
+ const tone = (f, d, peak, more = {}) => ({
3
+ kind: "tone",
4
+ wave: "sine",
5
+ f,
6
+ d,
7
+ peak,
8
+ ...more
9
+ });
10
+ const noise = (filter, f, d, peak, more = {}) => ({
11
+ kind: "noise",
12
+ filter,
13
+ f,
14
+ d,
15
+ peak,
16
+ ...more
17
+ });
18
+ /**
19
+ * Every theme plays the same gestures: the same notes, rhythm and sweeps per cue, so a cue means one thing
20
+ * whichever theme plays it (on rises and off falls; success resolves upward, error falls and darkens). A
21
+ * theme's voice decides the timbre. Outcome cues (warning, error, denied) are triangles, a little buzzier
22
+ * than the rest, so they don't read as confirmations.
23
+ */
24
+ const score = {
25
+ tap: [tone(1100, .045, .3, {
26
+ to: 850,
27
+ glide: .03
28
+ }), noise("bandpass", 3200, .012, .08, { q: 1.2 })],
29
+ type: [tone(1900, .022, .12), noise("highpass", 4500, .008, .07)],
30
+ tick: [tone(1400, .028, .18)],
31
+ drag: [tone(520, .07, .2, { to: 700 }), noise("bandpass", 1800, .03, .04, { q: .8 })],
32
+ drop: [tone(720, .09, .28, {
33
+ to: 430,
34
+ glide: .05
35
+ }), noise("lowpass", 900, .03, .1)],
36
+ "toggle-on": [tone(660, .06, .22), tone(990, .09, .22, { at: .045 })],
37
+ "toggle-off": [tone(990, .05, .2), tone(660, .08, .2, { at: .04 })],
38
+ check: [tone(1320, .07, .22), tone(2640, .04, .06, { accent: true })],
39
+ uncheck: [tone(990, .05, .18)],
40
+ select: [tone(1175, .08, .22), tone(2350, .05, .06, { accent: true })],
41
+ open: [tone(440, .16, .18, {
42
+ to: 880,
43
+ glide: .12,
44
+ a: .01
45
+ }), noise("bandpass", 1200, .14, .05, {
46
+ to: 3e3,
47
+ glide: .12,
48
+ q: .8,
49
+ a: .02
50
+ })],
51
+ close: [tone(880, .12, .17, {
52
+ to: 440,
53
+ glide: .1,
54
+ a: .005
55
+ }), noise("bandpass", 3e3, .1, .05, {
56
+ to: 1200,
57
+ glide: .1,
58
+ q: .8
59
+ })],
60
+ expand: [tone(620, .08, .18, {
61
+ to: 930,
62
+ glide: .06
63
+ })],
64
+ collapse: [tone(930, .08, .18, {
65
+ to: 620,
66
+ glide: .06
67
+ })],
68
+ navigate: [tone(880, .05, .16), tone(1320, .07, .14, { at: .035 })],
69
+ success: [
70
+ tone(784, .12, .22),
71
+ tone(1175, .22, .22, { at: .08 }),
72
+ tone(2350, .12, .05, {
73
+ at: .08,
74
+ accent: true
75
+ })
76
+ ],
77
+ warning: [tone(698, .1, .18, { wave: "triangle" }), tone(698, .12, .16, {
78
+ at: .14,
79
+ wave: "triangle"
80
+ })],
81
+ error: [tone(466, .13, .22, { wave: "triangle" }), tone(349, .22, .22, {
82
+ at: .1,
83
+ wave: "triangle"
84
+ })],
85
+ denied: [tone(220, .08, .3, {
86
+ to: 190,
87
+ wave: "triangle"
88
+ }), noise("lowpass", 500, .05, .08)],
89
+ notify: [
90
+ tone(1047, .22, .2),
91
+ tone(1319, .3, .18, { at: .1 }),
92
+ tone(2637, .16, .04, {
93
+ at: .1,
94
+ accent: true
95
+ })
96
+ ],
97
+ send: [tone(520, .11, .16, {
98
+ to: 1500,
99
+ glide: .1
100
+ }), noise("highpass", 2500, .1, .04, {
101
+ to: 7e3,
102
+ glide: .1
103
+ })],
104
+ receive: [tone(988, .08, .18), tone(1480, .14, .18, { at: .06 })],
105
+ copy: [tone(1568, .04, .16), tone(2093, .06, .14, { at: .035 })],
106
+ delete: [noise("bandpass", 1600, .14, .14, {
107
+ to: 380,
108
+ glide: .12,
109
+ q: 1.2
110
+ }), tone(320, .1, .18, {
111
+ to: 180,
112
+ wave: "triangle"
113
+ })],
114
+ complete: [
115
+ tone(1047, .16, .16),
116
+ tone(1319, .16, .15, { at: .06 }),
117
+ tone(1568, .18, .15, { at: .12 }),
118
+ tone(2093, .28, .14, {
119
+ at: .18,
120
+ accent: true
121
+ })
122
+ ],
123
+ mute: [tone(523, .07, .2), tone(392, .1, .18, { at: .05 })],
124
+ unmute: [tone(392, .06, .18), tone(523, .1, .2, { at: .05 })],
125
+ "muted-speaking": [tone(440, .05, .16, { wave: "triangle" }), tone(440, .06, .14, {
126
+ at: .1,
127
+ wave: "triangle"
128
+ })],
129
+ "participant-join": [tone(587, .12, .15), tone(880, .18, .14, { at: .09 })],
130
+ "participant-leave": [tone(880, .1, .14), tone(587, .16, .14, { at: .09 })],
131
+ "call-join": [
132
+ tone(523, .14, .17),
133
+ tone(659, .14, .16, { at: .08 }),
134
+ tone(784, .22, .16, { at: .16 }),
135
+ tone(1568, .14, .04, {
136
+ at: .16,
137
+ accent: true
138
+ })
139
+ ],
140
+ "call-leave": [
141
+ tone(784, .12, .16),
142
+ tone(659, .12, .16, { at: .08 }),
143
+ tone(523, .22, .17, { at: .16 })
144
+ ],
145
+ knock: [
146
+ noise("lowpass", 900, .03, .14),
147
+ tone(240, .05, .22, { wave: "triangle" }),
148
+ noise("lowpass", 900, .03, .13, { at: .14 }),
149
+ tone(240, .05, .2, {
150
+ at: .14,
151
+ wave: "triangle"
152
+ })
153
+ ],
154
+ "hand-raise": [
155
+ tone(659, .1, .18),
156
+ tone(988, .2, .16, { at: .07 }),
157
+ tone(1976, .12, .04, {
158
+ at: .07,
159
+ accent: true
160
+ })
161
+ ],
162
+ "recording-start": [
163
+ tone(880, .07, .17),
164
+ tone(880, .07, .17, { at: .12 }),
165
+ tone(1175, .24, .17, { at: .24 })
166
+ ],
167
+ "recording-stop": [tone(1175, .08, .16), tone(880, .2, .16, { at: .1 })],
168
+ "share-start": [tone(500, .15, .16, {
169
+ to: 1e3,
170
+ glide: .12,
171
+ a: .008
172
+ }), noise("bandpass", 1500, .12, .04, {
173
+ to: 3500,
174
+ glide: .12,
175
+ q: .8,
176
+ a: .015
177
+ })],
178
+ "share-stop": [tone(1e3, .13, .15, {
179
+ to: 500,
180
+ glide: .1,
181
+ a: .005
182
+ }), noise("bandpass", 3500, .1, .04, {
183
+ to: 1500,
184
+ glide: .1,
185
+ q: .8
186
+ })],
187
+ reconnecting: [tone(659, .12, .18, { wave: "triangle" }), tone(494, .2, .18, {
188
+ at: .1,
189
+ wave: "triangle"
190
+ })],
191
+ reconnected: [
192
+ tone(494, .08, .17),
193
+ tone(659, .08, .16, { at: .07 }),
194
+ tone(988, .2, .15, { at: .14 })
195
+ ]
196
+ };
197
+ /** A theme from the shared score and a voice. */
198
+ function defineTheme(name, room, gain, voice) {
199
+ const cues = {};
200
+ for (const [cue, layers] of Object.entries(score)) cues[cue] = layers.flatMap(voice);
201
+ return {
202
+ name,
203
+ room,
204
+ gain,
205
+ cues
206
+ };
207
+ }
208
+ /** Partials above this are dropped: small speakers don't play them, and they only sting. */
209
+ const CEILING = 12e3;
210
+ export { CEILING, defineTheme, score };