@avoid.quest/audio 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 (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -2
  3. package/dist/effects/index.d.ts +266 -0
  4. package/dist/effects/index.js +744 -0
  5. package/dist/effects/index.js.map +1 -0
  6. package/dist/errors-BT9HxDLn.js +74 -0
  7. package/dist/errors-BT9HxDLn.js.map +1 -0
  8. package/dist/errors-ChTQFwuZ.d.ts +53 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.js +3 -0
  11. package/dist/midi/index.d.ts +162 -0
  12. package/dist/midi/index.js +338 -0
  13. package/dist/midi/index.js.map +1 -0
  14. package/dist/playback/index.d.ts +349 -0
  15. package/dist/playback/index.js +1372 -0
  16. package/dist/playback/index.js.map +1 -0
  17. package/dist/queue/index.d.ts +144 -0
  18. package/dist/queue/index.js +1062 -0
  19. package/dist/queue/index.js.map +1 -0
  20. package/dist/recognize/index.d.ts +161 -0
  21. package/dist/recognize/index.js +2816 -0
  22. package/dist/recognize/index.js.map +1 -0
  23. package/dist/routing/index.d.ts +140 -0
  24. package/dist/routing/index.js +678 -0
  25. package/dist/routing/index.js.map +1 -0
  26. package/dist/sync/index.d.ts +282 -0
  27. package/dist/sync/index.js +1103 -0
  28. package/dist/sync/index.js.map +1 -0
  29. package/dist/worklet-loader-BvEW0oVO.d.ts +44 -0
  30. package/dist/worklet-loader-S7R8ZAmP.js +175 -0
  31. package/dist/worklet-loader-S7R8ZAmP.js.map +1 -0
  32. package/dist/worklets/couch-live.d.ts +1 -0
  33. package/dist/worklets/couch-live.js +365 -0
  34. package/dist/worklets/couch-live.js.map +1 -0
  35. package/dist/worklets/meter.d.ts +7 -0
  36. package/dist/worklets/meter.js +80 -0
  37. package/dist/worklets/meter.js.map +1 -0
  38. package/package.json +109 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 avoid-quest
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,71 @@
1
- # Temporary Holding Version
1
+ # `@avoid.quest/audio`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Modular Web Audio, DSP plugin seam, queue state machine, live sync framing, audio recognition, MIDI controller, and standalone zero-import AudioWorklets built on **Effect v4**.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @avoid.quest/audio effect
9
+ # Optional: install hls.js for non-native HLS playback in createMediaEngine
10
+ bun add hls.js
11
+ ```
12
+
13
+ - **Required peer dependency:** `effect` (`^4.1.0`)
14
+ - **Optional peer dependency:** `hls.js` (`^1.7.0`, loaded dynamically only when `createMediaEngine` plays HLS streams in browsers without native HLS support)
15
+
16
+ ## Exports
17
+
18
+ | Subpath | Environment | Contents |
19
+ | --- | --- | --- |
20
+ | `@avoid.quest/audio` | Browser / Universal | `AudioError` tagged errors (`AudioErrorSchema`) and worklet loader helpers (`loadAudioWorklet`, `createWorkletModuleUrl`, `createWorkletBlobUrl`, `VITE_AUDIO_WORKLET_OPTIMIZE_DEPS_EXCLUDE`) |
21
+ | `@avoid.quest/audio/queue` | Universal (DOM-free) | Pure queue state machine (`createAudioQueue`, `QueueService`, `makeQueueServiceLayer`, `fisherYatesShuffle`, link-expiry helpers) |
22
+ | `@avoid.quest/audio/playback` | Browser | `AudioContextService`, `createMediaEngine` (optional `hls.js` + stall recovery), `createSampler`, `acquireInputCapture`, `createMediaSessionController` |
23
+ | `@avoid.quest/audio/routing` | Browser | `createMultiSinkRouter` (multi-output `setSinkId` + per-sink delay) and `createStereoMeter` / `loadMeterWorklet` |
24
+ | `@avoid.quest/audio/effects` | Browser | Native Web Audio nodes (`createGain`, `createPan`, `createBiquadFilter`, `createCrossfade`, `createCompressor`) and `createDspPluginHost` (`DspPlugin` / `AudioNode` seam) |
25
+ | `@avoid.quest/audio/recognize` | Universal (DOM-free) | `generateShazamSignature`, `crc32`, and M3U / PLS / HLS playlist parsers (`parsePlaylist`, `parseHlsManifest`, `parseM3u`, `parsePls`) |
26
+ | `@avoid.quest/audio/sync` | Browser / Universal | `CCA1` binary framing, `LiveTimeline`, adaptive live buffer & lead controllers, `createSendspinReceiver`, `createLivePlayer`, `loadCouchLiveWorklet` |
27
+ | `@avoid.quest/audio/midi` | Browser / Universal | Web MIDI controller (`createMidiController`, `requestMidiAccess`), message parser (`parseMidiMessage`), and binding transforms |
28
+ | `@avoid.quest/audio/worklets/couch-live` (+ `.js`) | AudioWorklet | Standalone zero-import ring-buffer playback worklet processor |
29
+ | `@avoid.quest/audio/worklets/meter` (+ `.js`) | AudioWorklet | Standalone zero-import peak/RMS stereo metering worklet processor |
30
+
31
+ ## Quick Usage
32
+
33
+ ```ts
34
+ import {
35
+ createCompressor,
36
+ createDspPluginHost,
37
+ } from "@avoid.quest/audio/effects";
38
+ import { createAudioQueue } from "@avoid.quest/audio/queue";
39
+ import { loadMeterWorklet } from "@avoid.quest/audio/routing";
40
+ import { Effect } from "effect";
41
+
42
+ const setupQueue = Effect.gen(function* () {
43
+ const queue = yield* createAudioQueue({ maxEntries: 500 });
44
+ yield* queue.enqueue([
45
+ {
46
+ id: "track-1",
47
+ title: "Ambient Study",
48
+ url: "https://cdn.example.com/track.mp3",
49
+ },
50
+ ]);
51
+ return queue;
52
+ });
53
+
54
+ // Attach external DSP engines (such as upstream @opendaw/*) via the AudioNode seam
55
+ const attachGraph = (ctx: AudioContext) =>
56
+ Effect.gen(function* () {
57
+ yield* loadMeterWorklet(ctx);
58
+ const compressor = createCompressor(ctx);
59
+ const host = createDspPluginHost(ctx, {
60
+ masterDestination: ctx.destination,
61
+ });
62
+ compressor.output.connect(host.masterInput);
63
+ return { compressor, host };
64
+ });
65
+ ```
66
+
67
+ When using Vite, add `VITE_AUDIO_WORKLET_OPTIMIZE_DEPS_EXCLUDE` to `optimizeDeps.exclude` so `import.meta.url` worklet assets resolve cleanly.
68
+
69
+ ## License & Boundaries
70
+
71
+ MIT — see [LICENSE](./LICENSE). Contains zero `@opendaw/*` imports or forked DSP code; consuming applications integrate upstream `@opendaw/*` or custom DSP nodes externally through `DspPlugin` / `createDspPluginHost`.
@@ -0,0 +1,266 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { d as AudioWorkletError, u as AudioUnsupportedError } from "../errors-ChTQFwuZ.js";
3
+ export declare const COMPRESSOR_LOOKAHEAD_SECONDS = 0.006;
4
+ export declare const COMPRESSOR_PARAMETERS: {
5
+ readonly attack: {
6
+ readonly label: "Attack";
7
+ readonly max: 1000;
8
+ readonly min: 0.1;
9
+ readonly step: 0.1;
10
+ readonly unit: "ms";
11
+ };
12
+ readonly gain: {
13
+ readonly label: "Output gain";
14
+ readonly max: 12;
15
+ readonly min: -12;
16
+ readonly step: 0.5;
17
+ readonly unit: "dB";
18
+ };
19
+ readonly knee: {
20
+ readonly label: "Knee";
21
+ readonly max: 18;
22
+ readonly min: 0;
23
+ readonly step: 1;
24
+ readonly unit: "dB";
25
+ };
26
+ readonly ratio: {
27
+ readonly label: "Ratio";
28
+ readonly max: 20;
29
+ readonly min: 1;
30
+ readonly step: 0.1;
31
+ readonly unit: ":1";
32
+ };
33
+ readonly release: {
34
+ readonly label: "Release";
35
+ readonly max: 1000;
36
+ readonly min: 1;
37
+ readonly step: 1;
38
+ readonly unit: "ms";
39
+ };
40
+ readonly threshold: {
41
+ readonly label: "Threshold";
42
+ readonly max: 0;
43
+ readonly min: -60;
44
+ readonly step: 1;
45
+ readonly unit: "dB";
46
+ };
47
+ };
48
+ type CompressorParameter = keyof typeof COMPRESSOR_PARAMETERS;
49
+ export declare const CompressorSettingsSchema: Schema.Struct<{
50
+ readonly attack: Schema.Number;
51
+ readonly enabled: Schema.Boolean;
52
+ readonly gain: Schema.Number;
53
+ readonly knee: Schema.Number;
54
+ readonly ratio: Schema.Number;
55
+ readonly release: Schema.Number;
56
+ readonly threshold: Schema.Number;
57
+ }>;
58
+ type CompressorSettings = typeof CompressorSettingsSchema.Type;
59
+ export declare const DEFAULT_COMPRESSOR_SETTINGS: Readonly<CompressorSettings>;
60
+ interface CompressorPrimitive {
61
+ readonly input: GainNode;
62
+ readonly output: GainNode;
63
+ readonly compressorNode: DynamicsCompressorNode;
64
+ readonly delayNode: DelayNode;
65
+ readonly set: (next: CompressorSettings, immediate?: boolean) => void;
66
+ readonly setVolume: (value: number) => void;
67
+ readonly getSettings: () => CompressorSettings;
68
+ readonly dispose: () => void;
69
+ }
70
+ /**
71
+ * Runtime type guard validating a partial compressor settings patch against
72
+ * the defined parameter ranges.
73
+ */
74
+ export declare function isCompressorPatch(value: unknown): value is Partial<CompressorSettings>;
75
+ /**
76
+ * Converts `CompressorSettings` to Couch's exact FFmpeg / mpv `libavfilter` string.
77
+ */
78
+ export declare function compressorToFfmpegFilter(settings: CompressorSettings): string;
79
+ /**
80
+ * Creates a delay-aligned Web Audio `DynamicsCompressorNode` graph:
81
+ * - Wet branch: `input -> DynamicsCompressorNode -> makeup (GainNode) -> wet (GainNode) -> output (GainNode)`
82
+ * - Dry branch: `input -> delay (6 ms matching Web Audio lookahead) -> dry (GainNode) -> output`
83
+ * - Clickless bypass crossfade (10 ms prime + 40 ms linear ramp + unused branch disconnect).
84
+ */
85
+ export declare function createCompressor(context: BaseAudioContext, initialSettings?: CompressorSettings): CompressorPrimitive;
86
+ /**
87
+ * Upstream `@opendaw/studio-core` `EngineWorklet` monitoring cap:
88
+ * 8 monitoring channels = 4 stereo sources (or 8 mono sources).
89
+ */
90
+ export declare const DEFAULT_MAX_MONITORING_CHANNELS = 8;
91
+ export declare const DEFAULT_MAX_STEREO_SOURCES = 4;
92
+ export declare const DSP_SWITCH_SECONDS = 0.03;
93
+ interface ExternalDspCapabilities {
94
+ readonly crossOriginIsolated: boolean;
95
+ readonly sharedArrayBuffer: boolean;
96
+ readonly audioWorklet: boolean;
97
+ readonly maxMonitoringChannels: number;
98
+ readonly maxStereoSources: number;
99
+ readonly canRunWasmDsp: boolean;
100
+ }
101
+ interface DspCapabilityOverrides {
102
+ readonly crossOriginIsolated?: boolean;
103
+ readonly sharedArrayBuffer?: boolean;
104
+ readonly audioWorklet?: boolean;
105
+ readonly maxMonitoringChannels?: number;
106
+ }
107
+ interface DspPluginRequirement {
108
+ readonly sharedArrayBuffer?: boolean;
109
+ readonly audioWorklet?: boolean;
110
+ readonly maxMonitoringChannels?: number;
111
+ }
112
+ type DspWriteOutcome = "applied" | "structural" | "unavailable";
113
+ /**
114
+ * Clean MIT `AudioNode` / DSP plugin seam for external engines (such as upstream
115
+ * single-stereo-master `EngineWorklet` DSP engines) with zero `@opendaw/*`
116
+ * imports inside `@avoid.quest/audio`.
117
+ *
118
+ * A plugin may attach to:
119
+ * - the shared stereo master bus (`connectMasterBus` / `disconnectMasterBus`),
120
+ * - individual registered sources (`connectSource` / `disconnectSource`), or
121
+ * - both (e.g. single stereo master bus + bounded monitoring sends).
122
+ */
123
+ interface DspPlugin {
124
+ readonly id: string;
125
+ readonly name: string;
126
+ readonly requirements?: DspPluginRequirement;
127
+ /**
128
+ * Optional static algorithmic / worklet round-trip latency in seconds for
129
+ * downstream delay compensation (e.g. aligning dry/cue/multi-sink buses).
130
+ */
131
+ readonly latencySeconds?: number;
132
+ /**
133
+ * Optional dynamic latency reporter (takes precedence over `latencySeconds`).
134
+ */
135
+ readonly getLatencySeconds?: () => number;
136
+ /**
137
+ * Connects a single shared stereo-master DSP insert (`input -> [plugin] -> output`),
138
+ * avoiding per-source worklet/engine duplication.
139
+ */
140
+ readonly connectMasterBus?: (input: AudioNode, output: AudioNode) => Effect.Effect<void, AudioUnsupportedError | AudioWorkletError> | void;
141
+ readonly disconnectMasterBus?: () => Effect.Effect<void> | void;
142
+ /**
143
+ * Connects an individual registered source (`input -> [plugin] -> output`),
144
+ * subject to `maxMonitoringChannels` capacity enforcement.
145
+ */
146
+ readonly connectSource?: (sourceId: string, input: AudioNode, output: AudioNode, channels: 1 | 2) => Effect.Effect<void, AudioUnsupportedError | AudioWorkletError> | void;
147
+ readonly disconnectSource?: (sourceId: string) => Effect.Effect<void> | void;
148
+ readonly updateParameter?: (sourceId: string, effectId: string, parameter: string, value: number | boolean | string) => DspWriteOutcome;
149
+ readonly dispose?: () => Effect.Effect<void> | void;
150
+ }
151
+ interface DspPluginHostOptions {
152
+ readonly capabilities?: DspCapabilityOverrides;
153
+ readonly switchSeconds?: number;
154
+ /**
155
+ * Optional destination `AudioNode` automatically wired from `masterOutput`.
156
+ */
157
+ readonly masterDestination?: AudioNode;
158
+ }
159
+ interface RegisteredDspSource {
160
+ readonly sourceId: string;
161
+ readonly channels: 1 | 2;
162
+ readonly activeMode: "bypass" | "plugin";
163
+ }
164
+ interface DspPluginHost {
165
+ /** Shared stereo master bus input node (sum upstream decks/channels here). */
166
+ readonly masterInput: GainNode;
167
+ /** Shared stereo master bus output node (route to destination / multi-sink). */
168
+ readonly masterOutput: GainNode;
169
+ readonly getCapabilities: () => ExternalDspCapabilities;
170
+ readonly getAllocatedChannels: () => number;
171
+ readonly getActivePlugin: () => DspPlugin | undefined;
172
+ readonly getLatencySeconds: () => number;
173
+ readonly isMasterBusActive: () => boolean;
174
+ readonly getSources: () => readonly RegisteredDspSource[];
175
+ readonly registerSource: (sourceId: string, source: AudioNode, destination: AudioNode, channels?: 1 | 2) => Effect.Effect<RegisteredDspSource, AudioUnsupportedError | AudioWorkletError>;
176
+ readonly unregisterSource: (sourceId: string) => Effect.Effect<void>;
177
+ readonly attachPlugin: (plugin: DspPlugin) => Effect.Effect<void, AudioUnsupportedError | AudioWorkletError>;
178
+ readonly detachPlugin: () => Effect.Effect<void>;
179
+ readonly setBypass: (bypass: boolean) => void;
180
+ readonly isBypassed: () => boolean;
181
+ readonly updateParameter: (sourceId: string, effectId: string, parameter: string, value: number | boolean | string) => DspWriteOutcome;
182
+ readonly dispose: () => Effect.Effect<void>;
183
+ }
184
+ /**
185
+ * Inspects COOP/COEP (`crossOriginIsolated`), `SharedArrayBuffer`, and `AudioWorkletNode`
186
+ * support plus the upstream 4-stereo-source (8-channel) monitoring budget.
187
+ */
188
+ export declare function detectExternalDspCapabilities(overrides?: DspCapabilityOverrides): ExternalDspCapabilities;
189
+ /**
190
+ * Creates a clickless `DspPluginHost` managing:
191
+ * - A shared stereo-master insert shell (`masterInput -> masterBypassGain || masterPluginInput -> [DspPlugin] -> masterPluginOutput -> masterPluginGain -> masterOutput`)
192
+ * - Optional per-source routing slots bounded by the 4-stereo-source (8-channel) monitoring cap
193
+ * - 30 ms clickless crossfades (waiting for fade-out before disconnecting on detach)
194
+ * - COOP/COEP `SharedArrayBuffer` capability gating and latency compensation reporting.
195
+ */
196
+ export declare function createDspPluginHost(context: BaseAudioContext, options?: DspPluginHostOptions): DspPluginHost;
197
+ type CrossfadeCurve = "equalPower" | "linear" | "exponential";
198
+ export declare const DEFAULT_CROSSFADE_STEPS = 48;
199
+ export declare const DEFAULT_PARAM_TIME_CONSTANT_S = 0.01;
200
+ export declare const MIN_EXPONENTIAL_GAIN = 0.0001;
201
+ interface GainPrimitive {
202
+ readonly node: GainNode;
203
+ readonly input: GainNode;
204
+ readonly output: GainNode;
205
+ readonly setGain: (value: number, rampSeconds?: number) => number;
206
+ readonly getGain: () => number;
207
+ readonly dispose: () => void;
208
+ }
209
+ interface PanPrimitive {
210
+ readonly node: StereoPannerNode;
211
+ readonly input: StereoPannerNode;
212
+ readonly output: StereoPannerNode;
213
+ readonly setPan: (value: number, rampSeconds?: number) => number;
214
+ readonly getPan: () => number;
215
+ readonly dispose: () => void;
216
+ }
217
+ interface BiquadFilterOptions {
218
+ readonly type?: BiquadFilterType;
219
+ readonly frequency?: number;
220
+ readonly q?: number;
221
+ readonly gain?: number;
222
+ readonly detune?: number;
223
+ }
224
+ interface BiquadFilterPrimitive {
225
+ readonly node: BiquadFilterNode;
226
+ readonly input: BiquadFilterNode;
227
+ readonly output: BiquadFilterNode;
228
+ readonly setType: (type: BiquadFilterType) => void;
229
+ readonly setFrequency: (hz: number, rampSeconds?: number) => number;
230
+ readonly setQ: (q: number, rampSeconds?: number) => number;
231
+ readonly setGain: (db: number, rampSeconds?: number) => number;
232
+ readonly setDetune: (cents: number, rampSeconds?: number) => number;
233
+ readonly dispose: () => void;
234
+ }
235
+ interface CrossfadePrimitive {
236
+ readonly inputA: GainNode;
237
+ readonly inputB: GainNode;
238
+ readonly output: GainNode;
239
+ readonly getMix: () => number;
240
+ readonly setMix: (mix: number, durationSeconds?: number, curve?: CrossfadeCurve) => number;
241
+ readonly dispose: () => void;
242
+ }
243
+ /**
244
+ * Generates a 48-step (`Float32Array(steps + 1)`) fade-in and fade-out gain curve pair
245
+ * for `AudioParam.setValueCurveAtTime`.
246
+ */
247
+ export declare function createCrossfadeCurves(steps?: number, curve?: CrossfadeCurve): {
248
+ readonly fadeIn: Float32Array;
249
+ readonly fadeOut: Float32Array;
250
+ };
251
+ /**
252
+ * Evaluates equal-power, linear, or exponential gains for a mix value in `[0, 1]`
253
+ * (`0` = 100% A, `1` = 100% B).
254
+ */
255
+ export declare function computeCrossfadeGains(mix: number, curve?: CrossfadeCurve): {
256
+ readonly gainA: number;
257
+ readonly gainB: number;
258
+ };
259
+ export declare function createGain(context: BaseAudioContext, initialGain?: number): GainPrimitive;
260
+ export declare function createPan(context: BaseAudioContext, initialPan?: number): PanPrimitive;
261
+ export declare function createBiquadFilter(context: BaseAudioContext, options?: BiquadFilterOptions): BiquadFilterPrimitive;
262
+ /**
263
+ * Equal-power (or linear/exponential) two-input crossfader (`inputA` + `inputB` -> `output`).
264
+ */
265
+ export declare function createCrossfade(context: BaseAudioContext, initialMix?: number, defaultCurve?: CrossfadeCurve): CrossfadePrimitive;
266
+ export type { BiquadFilterOptions, BiquadFilterPrimitive, CompressorParameter, CompressorPrimitive, CompressorSettings, CrossfadeCurve, CrossfadePrimitive, DspCapabilityOverrides, DspPlugin, DspPluginHost, DspPluginHostOptions, DspPluginRequirement, DspWriteOutcome, ExternalDspCapabilities, GainPrimitive, PanPrimitive, RegisteredDspSource };