@litlab/audx 0.0.1 → 0.5.5
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/README.md +96 -53
- package/dist/bin.js +1212 -0
- package/dist/cc-DgCkkqq8.js +13 -0
- package/dist/cc-he3fHS3P.js +12 -0
- package/dist/index.d.ts +723 -3
- package/dist/index.js +1534 -126
- package/dist/react.d.ts +583 -0
- package/dist/react.js +1556 -0
- package/package.json +64 -39
- package/schemas/pack.schema.json +4 -0
- package/schemas/patch.schema.json +857 -0
- package/dist/codegen/theme-codegen.d.ts +0 -12
- package/dist/codegen/theme-codegen.d.ts.map +0 -1
- package/dist/codegen/theme-codegen.js +0 -153
- package/dist/codegen/theme-codegen.js.map +0 -1
- package/dist/commands/add.d.ts +0 -2
- package/dist/commands/add.d.ts.map +0 -1
- package/dist/commands/add.js +0 -120
- package/dist/commands/add.js.map +0 -1
- package/dist/commands/diff.d.ts +0 -2
- package/dist/commands/diff.d.ts.map +0 -1
- package/dist/commands/diff.js +0 -103
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/generate.d.ts +0 -12
- package/dist/commands/generate.d.ts.map +0 -1
- package/dist/commands/generate.js +0 -96
- package/dist/commands/generate.js.map +0 -1
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -79
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/list.d.ts +0 -14
- package/dist/commands/list.d.ts.map +0 -1
- package/dist/commands/list.js +0 -93
- package/dist/commands/list.js.map +0 -1
- package/dist/commands/remove.d.ts +0 -2
- package/dist/commands/remove.d.ts.map +0 -1
- package/dist/commands/remove.js +0 -71
- package/dist/commands/remove.js.map +0 -1
- package/dist/commands/theme.d.ts +0 -31
- package/dist/commands/theme.d.ts.map +0 -1
- package/dist/commands/theme.js +0 -142
- package/dist/commands/theme.js.map +0 -1
- package/dist/commands/update.d.ts +0 -2
- package/dist/commands/update.d.ts.map +0 -1
- package/dist/commands/update.js +0 -123
- package/dist/commands/update.js.map +0 -1
- package/dist/core/alias-resolver.d.ts +0 -24
- package/dist/core/alias-resolver.d.ts.map +0 -1
- package/dist/core/alias-resolver.js +0 -87
- package/dist/core/alias-resolver.js.map +0 -1
- package/dist/core/config.d.ts +0 -21
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/config.js +0 -43
- package/dist/core/config.js.map +0 -1
- package/dist/core/file-writer.d.ts +0 -14
- package/dist/core/file-writer.d.ts.map +0 -1
- package/dist/core/file-writer.js +0 -90
- package/dist/core/file-writer.js.map +0 -1
- package/dist/core/package-manager.d.ts +0 -3
- package/dist/core/package-manager.d.ts.map +0 -1
- package/dist/core/package-manager.js +0 -17
- package/dist/core/package-manager.js.map +0 -1
- package/dist/core/registry.d.ts +0 -18
- package/dist/core/registry.d.ts.map +0 -1
- package/dist/core/registry.js +0 -69
- package/dist/core/registry.js.map +0 -1
- package/dist/core/theme-manager.d.ts +0 -35
- package/dist/core/theme-manager.d.ts.map +0 -1
- package/dist/core/theme-manager.js +0 -94
- package/dist/core/theme-manager.js.map +0 -1
- package/dist/core/utils.d.ts +0 -22
- package/dist/core/utils.d.ts.map +0 -1
- package/dist/core/utils.js +0 -44
- package/dist/core/utils.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -116
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -43
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,86 +1,129 @@
|
|
|
1
|
-
# audx
|
|
1
|
+
# @litlab/audx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Declarative audio synthesis for the web. Describe sounds as plain objects, play them with one function call.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install
|
|
8
|
+
npm install @litlab/audx
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
### Define and play a sound
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineSound, ensureReady } from "@litlab/audx";
|
|
17
|
+
|
|
18
|
+
const pop = defineSound({
|
|
19
|
+
source: { type: "sine", frequency: { start: 1200, end: 300 } },
|
|
20
|
+
envelope: { attack: 0.001, decay: 0.06, sustain: 0, release: 0.03 },
|
|
21
|
+
gain: 0.3,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await ensureReady();
|
|
25
|
+
pop();
|
|
15
26
|
```
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
### Shorthand helpers
|
|
18
29
|
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
```ts
|
|
31
|
+
import { sine, noise } from "@litlab/audx";
|
|
32
|
+
|
|
33
|
+
const beep = sine(440, 0.1);
|
|
34
|
+
const click = noise("white", 0.02);
|
|
35
|
+
|
|
36
|
+
beep();
|
|
37
|
+
click();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Sound patches (React)
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { usePatch } from "@litlab/audx/react";
|
|
44
|
+
|
|
45
|
+
function App() {
|
|
46
|
+
const patch = usePatch("/patches/core.json");
|
|
22
47
|
|
|
23
|
-
|
|
24
|
-
|
|
48
|
+
return (
|
|
49
|
+
<button onClick={() => patch.play("click")} disabled={!patch.ready}>
|
|
50
|
+
Click me
|
|
51
|
+
</button>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Sound patches (vanilla)
|
|
25
57
|
|
|
26
|
-
|
|
27
|
-
|
|
58
|
+
```ts
|
|
59
|
+
import { loadPatch } from "@litlab/audx";
|
|
28
60
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
audx theme map click click-001
|
|
32
|
-
audx theme generate
|
|
61
|
+
const patch = await loadPatch("/patches/core.json");
|
|
62
|
+
patch.play("click");
|
|
33
63
|
```
|
|
34
64
|
|
|
35
|
-
##
|
|
65
|
+
## CLI
|
|
36
66
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
| `audx diff` | Check for updates to installed sounds |
|
|
44
|
-
| `audx update [sound]` | Update installed sounds from registry |
|
|
45
|
-
| `audx generate "<prompt>"` | Generate a sound from a text prompt (`--name`, `--duration`) |
|
|
46
|
-
| `audx theme init` | Create theme configuration |
|
|
47
|
-
| `audx theme set <name>` | Switch active theme |
|
|
48
|
-
| `audx theme map <semantic> <sound>` | Map a semantic name to a sound |
|
|
49
|
-
| `audx theme create <name>` | Create a new theme |
|
|
50
|
-
| `audx theme list` | List all themes |
|
|
51
|
-
| `audx theme generate` | Generate `sound-theme.ts` |
|
|
67
|
+
```bash
|
|
68
|
+
# Browse and install patches from the registry
|
|
69
|
+
npx @litlab/audx add
|
|
70
|
+
|
|
71
|
+
# Install patches from a GitHub repo
|
|
72
|
+
npx @litlab/audx add user/repo
|
|
52
73
|
|
|
53
|
-
|
|
74
|
+
# Create a new sound patch
|
|
75
|
+
npx @litlab/audx init
|
|
54
76
|
|
|
55
|
-
|
|
77
|
+
# List installed patches
|
|
78
|
+
npx @litlab/audx list
|
|
56
79
|
|
|
57
|
-
|
|
80
|
+
# Remove installed patches
|
|
81
|
+
npx @litlab/audx remove
|
|
82
|
+
```
|
|
58
83
|
|
|
59
|
-
##
|
|
84
|
+
## Patch authoring
|
|
60
85
|
|
|
61
|
-
|
|
86
|
+
Create a patch JSON file with `npx @litlab/audx init`, then add sound definitions to the `sounds` object:
|
|
62
87
|
|
|
63
88
|
```json
|
|
64
89
|
{
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
"installedSounds": {}
|
|
90
|
+
"$schema": "node_modules/@litlab/audx/schemas/patch.schema.json",
|
|
91
|
+
"name": "my-patch",
|
|
92
|
+
"sounds": {
|
|
93
|
+
"click": {
|
|
94
|
+
"source": { "type": "noise", "color": "white" },
|
|
95
|
+
"filter": { "type": "bandpass", "frequency": 2000 },
|
|
96
|
+
"envelope": { "decay": 0.05 }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
75
99
|
}
|
|
76
100
|
```
|
|
77
101
|
|
|
78
|
-
|
|
102
|
+
Push it to a GitHub repo. Others can install it with:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx @litlab/audx add your-username/your-repo
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## API
|
|
109
|
+
|
|
110
|
+
| Export | Description |
|
|
111
|
+
|--------|-------------|
|
|
112
|
+
| `defineSound(def)` | Create a reusable play function from a sound definition |
|
|
113
|
+
| `ensureReady()` | Initialize the audio context (call before first play) |
|
|
114
|
+
| `sine(freq, decay)` | Shorthand for sine oscillator |
|
|
115
|
+
| `triangle(freq, decay)` | Shorthand for triangle oscillator |
|
|
116
|
+
| `square(freq, decay)` | Shorthand for square oscillator |
|
|
117
|
+
| `sawtooth(freq, decay)` | Shorthand for sawtooth oscillator |
|
|
118
|
+
| `noise(color, decay)` | Shorthand for noise generator |
|
|
119
|
+
| `loadPatch(url)` | Load a sound patch from a URL |
|
|
120
|
+
| `definePatch(json)` | Create a patch from a JSON object |
|
|
121
|
+
| `usePatch(url)` | React hook for loading and playing patches |
|
|
79
122
|
|
|
80
|
-
##
|
|
123
|
+
## Documentation
|
|
81
124
|
|
|
82
|
-
|
|
125
|
+
Full docs at [audx.site](https://audx.site).
|
|
83
126
|
|
|
84
127
|
## License
|
|
85
128
|
|
|
86
|
-
MIT
|
|
129
|
+
[MIT](https://github.com/ommgh/audio/blob/main/LICENSE)
|