@nodetool-ai/audio-nodes 0.8.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.
- package/README.md +62 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-context.d.ts +7 -0
- package/dist/lib/audio-context.d.ts.map +1 -0
- package/dist/lib/audio-context.js +42 -0
- package/dist/lib/audio-context.js.map +1 -0
- package/dist/lib/audio-wav.d.ts +133 -0
- package/dist/lib/audio-wav.d.ts.map +1 -0
- package/dist/lib/audio-wav.js +504 -0
- package/dist/lib/audio-wav.js.map +1 -0
- package/dist/lib/biquad.d.ts +48 -0
- package/dist/lib/biquad.d.ts.map +1 -0
- package/dist/lib/biquad.js +127 -0
- package/dist/lib/biquad.js.map +1 -0
- package/dist/lib/cv.d.ts +141 -0
- package/dist/lib/cv.d.ts.map +1 -0
- package/dist/lib/cv.js +261 -0
- package/dist/lib/cv.js.map +1 -0
- package/dist/lib/synth-dsp.d.ts +43 -0
- package/dist/lib/synth-dsp.d.ts.map +1 -0
- package/dist/lib/synth-dsp.js +88 -0
- package/dist/lib/synth-dsp.js.map +1 -0
- package/dist/nodes/audio.d.ts +527 -0
- package/dist/nodes/audio.d.ts.map +1 -0
- package/dist/nodes/audio.js +1816 -0
- package/dist/nodes/audio.js.map +1 -0
- package/dist/nodes/game.d.ts +68 -0
- package/dist/nodes/game.d.ts.map +1 -0
- package/dist/nodes/game.js +304 -0
- package/dist/nodes/game.js.map +1 -0
- package/dist/nodes/lib-audio-dsp.d.ts +146 -0
- package/dist/nodes/lib-audio-dsp.d.ts.map +1 -0
- package/dist/nodes/lib-audio-dsp.js +477 -0
- package/dist/nodes/lib-audio-dsp.js.map +1 -0
- package/dist/nodes/lib-audio-effects.d.ts +174 -0
- package/dist/nodes/lib-audio-effects.d.ts.map +1 -0
- package/dist/nodes/lib-audio-effects.js +962 -0
- package/dist/nodes/lib-audio-effects.js.map +1 -0
- package/dist/nodes/output.d.ts +29 -0
- package/dist/nodes/output.d.ts.map +1 -0
- package/dist/nodes/output.js +179 -0
- package/dist/nodes/output.js.map +1 -0
- package/dist/nodes/preview.d.ts +26 -0
- package/dist/nodes/preview.d.ts.map +1 -0
- package/dist/nodes/preview.js +44 -0
- package/dist/nodes/preview.js.map +1 -0
- package/dist/nodes/realtime-audio.d.ts +118 -0
- package/dist/nodes/realtime-audio.d.ts.map +1 -0
- package/dist/nodes/realtime-audio.js +391 -0
- package/dist/nodes/realtime-audio.js.map +1 -0
- package/dist/nodes/synthesis.d.ts +194 -0
- package/dist/nodes/synthesis.d.ts.map +1 -0
- package/dist/nodes/synthesis.js +955 -0
- package/dist/nodes/synthesis.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical audio encoding/decoding helpers shared across the base-nodes
|
|
3
|
+
* audio node implementations.
|
|
4
|
+
*
|
|
5
|
+
* - `encodeWav` / `decodeWav` operate in Float32 sample space ([-1, 1]) and
|
|
6
|
+
* handle 16-bit PCM WAV with proper chunk traversal.
|
|
7
|
+
* - `audioBytes` / `audioBytesAsync` / `audioRefFromBytes` deal with the raw
|
|
8
|
+
* byte stream inside an `AudioRef`, independent of format. These are the
|
|
9
|
+
* single source of truth for every nodetool audio node — do not duplicate
|
|
10
|
+
* them at call sites.
|
|
11
|
+
*/
|
|
12
|
+
import { base64ToBytes, bytesToBase64, loadNodeFsPromises, loadNodeOs, loadNodePath } from "@nodetool-ai/nodes-utils";
|
|
13
|
+
import { IS_NODE, importNodeBuiltin } from "@nodetool-ai/config";
|
|
14
|
+
import { fetchExternalMedia } from "@nodetool-ai/runtime";
|
|
15
|
+
import { loadOfflineAudioContext } from "./audio-context.js";
|
|
16
|
+
import { isNonEmptyString, isObjectLike, isString } from "@nodetool-ai/node-sdk";
|
|
17
|
+
/** Decode a base64 string to bytes, or pass through an existing Uint8Array. */
|
|
18
|
+
export function toBytes(value) {
|
|
19
|
+
if (!value)
|
|
20
|
+
return new Uint8Array();
|
|
21
|
+
if (value instanceof Uint8Array)
|
|
22
|
+
return value;
|
|
23
|
+
if (!isString(value))
|
|
24
|
+
throw new Error("Invalid audio data");
|
|
25
|
+
return base64ToBytes(value);
|
|
26
|
+
}
|
|
27
|
+
/** Synchronously extract raw bytes from an AudioRef's inline `data` field. */
|
|
28
|
+
export function audioBytes(audio) {
|
|
29
|
+
if (!isObjectLike(audio))
|
|
30
|
+
return new Uint8Array();
|
|
31
|
+
return toBytes(audio.data);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract raw bytes from an AudioRef, falling back to URI-based retrieval
|
|
35
|
+
* (storage, `file://`, `http(s)://`) when no inline data is present.
|
|
36
|
+
*/
|
|
37
|
+
export async function audioBytesAsync(audio, context) {
|
|
38
|
+
if (!isObjectLike(audio))
|
|
39
|
+
return new Uint8Array();
|
|
40
|
+
const ref = audio;
|
|
41
|
+
if (ref.data)
|
|
42
|
+
return toBytes(ref.data);
|
|
43
|
+
if (isNonEmptyString(ref.uri)) {
|
|
44
|
+
try {
|
|
45
|
+
if (context?.storage) {
|
|
46
|
+
const stored = await context.storage.retrieve(ref.uri);
|
|
47
|
+
if (stored !== null)
|
|
48
|
+
return new Uint8Array(stored);
|
|
49
|
+
}
|
|
50
|
+
if (ref.uri.startsWith("file://")) {
|
|
51
|
+
const fs = await loadNodeFsPromises();
|
|
52
|
+
return new Uint8Array(await fs.readFile(uriToPath(ref.uri)));
|
|
53
|
+
}
|
|
54
|
+
if (ref.uri.startsWith("http://") || ref.uri.startsWith("https://")) {
|
|
55
|
+
// Caller-supplied uri: the media-ref egress policy decides, not this
|
|
56
|
+
// helper. A refusal throws into the catch below and reads as no bytes.
|
|
57
|
+
const response = await fetchExternalMedia(ref.uri);
|
|
58
|
+
if (!response.ok)
|
|
59
|
+
return new Uint8Array();
|
|
60
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return new Uint8Array();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return new Uint8Array();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolve an AudioRef to bytes, throwing a descriptive error when nothing
|
|
71
|
+
* playable can be loaded. Effect nodes use this instead of silently returning
|
|
72
|
+
* their input on empty bytes — a no-op effect is indistinguishable from a
|
|
73
|
+
* working one, so failure must be loud.
|
|
74
|
+
*/
|
|
75
|
+
export async function requireAudioBytes(audio, context) {
|
|
76
|
+
const bytes = await audioBytesAsync(audio, context);
|
|
77
|
+
if (bytes.length > 0)
|
|
78
|
+
return bytes;
|
|
79
|
+
const ref = (isObjectLike(audio) ? audio : {});
|
|
80
|
+
if (!ref.uri && !ref.asset_id && !ref.data) {
|
|
81
|
+
throw new Error("No audio connected: this effect needs audio on its input, but none was provided.");
|
|
82
|
+
}
|
|
83
|
+
if (ref.uri) {
|
|
84
|
+
throw new Error(`Could not load audio from "${ref.uri}": it resolved to zero bytes. The file may be missing, empty, or stored somewhere this node can't reach.`);
|
|
85
|
+
}
|
|
86
|
+
if (ref.asset_id) {
|
|
87
|
+
throw new Error(`Could not load audio for asset "${ref.asset_id}": no inline data and no resolvable URI. The asset may be unavailable in this context.`);
|
|
88
|
+
}
|
|
89
|
+
throw new Error("Could not load audio: the connected reference is empty (0 bytes).");
|
|
90
|
+
}
|
|
91
|
+
/** Strip a `file://` scheme from a URI, returning a plain filesystem path. */
|
|
92
|
+
export function uriToPath(uriOrPath) {
|
|
93
|
+
if (uriOrPath.startsWith("file://")) {
|
|
94
|
+
try {
|
|
95
|
+
// Use the Web-standard URL API instead of node:url's fileURLToPath
|
|
96
|
+
// so this helper loads in any runtime. On Windows, the pathname
|
|
97
|
+
// comes back as "/C:/path/foo" — strip the leading slash before
|
|
98
|
+
// returning a real Windows path.
|
|
99
|
+
const pathname = decodeURIComponent(new URL(uriOrPath).pathname);
|
|
100
|
+
return /^\/[A-Za-z]:\//.test(pathname) ? pathname.slice(1) : pathname;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Fallback for non-standard URIs like file://C:\path
|
|
104
|
+
return uriOrPath.slice("file://".length);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return uriOrPath;
|
|
108
|
+
}
|
|
109
|
+
/** Wrap raw bytes into an AudioRef (base64-encoding the data). */
|
|
110
|
+
export function audioRefFromBytes(data, uri) {
|
|
111
|
+
return {
|
|
112
|
+
type: "audio",
|
|
113
|
+
uri: uri ?? "",
|
|
114
|
+
data: bytesToBase64(data)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Semantic alias for `audioRefFromBytes` at sites that specifically emit WAV. */
|
|
118
|
+
export function audioRefFromWav(wav, uri) {
|
|
119
|
+
return audioRefFromBytes(wav, uri);
|
|
120
|
+
}
|
|
121
|
+
/** Concatenate Uint8Arrays into a single buffer. */
|
|
122
|
+
export function concatBytes(chunks) {
|
|
123
|
+
const total = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
124
|
+
const out = new Uint8Array(total);
|
|
125
|
+
let offset = 0;
|
|
126
|
+
for (const c of chunks) {
|
|
127
|
+
out.set(c, offset);
|
|
128
|
+
offset += c.length;
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
/** Write an ASCII tag (e.g. "RIFF") into a byte buffer at `offset`. */
|
|
133
|
+
function writeAscii(out, offset, text) {
|
|
134
|
+
for (let i = 0; i < text.length; i++)
|
|
135
|
+
out[offset + i] = text.charCodeAt(i);
|
|
136
|
+
}
|
|
137
|
+
/** Read bytes [start, end) as an ASCII string. */
|
|
138
|
+
function asciiAt(bytes, start, end) {
|
|
139
|
+
let text = "";
|
|
140
|
+
for (let i = start; i < end && i < bytes.length; i++) {
|
|
141
|
+
text += String.fromCharCode(bytes[i]);
|
|
142
|
+
}
|
|
143
|
+
return text;
|
|
144
|
+
}
|
|
145
|
+
/** Write the canonical 44-byte RIFF/WAVE PCM header into `out`. */
|
|
146
|
+
function writeWavHeader(out, view, sampleRate, numChannels, dataSize) {
|
|
147
|
+
const bitsPerSample = 16;
|
|
148
|
+
const blockAlign = (numChannels * bitsPerSample) / 8;
|
|
149
|
+
const byteRate = sampleRate * blockAlign;
|
|
150
|
+
writeAscii(out, 0, "RIFF");
|
|
151
|
+
view.setUint32(4, 36 + dataSize, true);
|
|
152
|
+
writeAscii(out, 8, "WAVE");
|
|
153
|
+
writeAscii(out, 12, "fmt ");
|
|
154
|
+
view.setUint32(16, 16, true);
|
|
155
|
+
view.setUint16(20, 1, true); // PCM
|
|
156
|
+
view.setUint16(22, numChannels, true);
|
|
157
|
+
view.setUint32(24, sampleRate, true);
|
|
158
|
+
view.setUint32(28, byteRate, true);
|
|
159
|
+
view.setUint16(32, blockAlign, true);
|
|
160
|
+
view.setUint16(34, bitsPerSample, true);
|
|
161
|
+
writeAscii(out, 36, "data");
|
|
162
|
+
view.setUint32(40, dataSize, true);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Wrap a buffer of already-encoded little-endian 16-bit PCM samples in a
|
|
166
|
+
* RIFF/WAVE container. Use when the caller already has Int16 samples (e.g.
|
|
167
|
+
* from a TTS provider streaming `response_format: "pcm"`) — avoids the
|
|
168
|
+
* Int16 → Float32 → Int16 round-trip that `encodeWav` would impose.
|
|
169
|
+
*/
|
|
170
|
+
export function encodePcm16Wav(pcmBytes, sampleRate, numChannels = 1) {
|
|
171
|
+
const dataSize = pcmBytes.length;
|
|
172
|
+
const out = new Uint8Array(44 + dataSize);
|
|
173
|
+
const view = new DataView(out.buffer);
|
|
174
|
+
writeWavHeader(out, view, sampleRate, numChannels, dataSize);
|
|
175
|
+
out.set(pcmBytes, 44);
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Encode Float32 samples (expected range [-1, 1]) as a 16-bit PCM WAV file.
|
|
180
|
+
* Samples outside the range are clipped. Channels are interleaved.
|
|
181
|
+
*/
|
|
182
|
+
export function encodeWav(samples, sampleRate, numChannels = 1) {
|
|
183
|
+
const dataSize = samples.length * 2;
|
|
184
|
+
const out = new Uint8Array(44 + dataSize);
|
|
185
|
+
const view = new DataView(out.buffer);
|
|
186
|
+
writeWavHeader(out, view, sampleRate, numChannels, dataSize);
|
|
187
|
+
for (let i = 0; i < samples.length; i++) {
|
|
188
|
+
const s = Math.max(-1, Math.min(1, samples[i]));
|
|
189
|
+
view.setInt16(44 + i * 2, Math.round(s * 0x7fff), true);
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Locate the `fmt ` and `data` chunks in a RIFF/WAVE byte stream and return
|
|
195
|
+
* the format fields plus the byte range of the PCM payload.
|
|
196
|
+
*
|
|
197
|
+
* Chunks are traversed honoring RIFF word-alignment (odd-sized chunks carry a
|
|
198
|
+
* trailing pad byte), so layouts that interleave `LIST`/`JUNK`/`fact` chunks
|
|
199
|
+
* — and non-canonical `fmt ` sizes (e.g. WAVE_FORMAT_EXTENSIBLE) — are read
|
|
200
|
+
* correctly. Returns null when the input is not a RIFF/WAVE file or has no
|
|
201
|
+
* `data` chunk.
|
|
202
|
+
*/
|
|
203
|
+
export function readWavHeader(bytes) {
|
|
204
|
+
if (bytes.length < 12)
|
|
205
|
+
return null;
|
|
206
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
207
|
+
if (asciiAt(bytes, 0, 4) !== "RIFF" || asciiAt(bytes, 8, 12) !== "WAVE") {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
let sampleRate = 0;
|
|
211
|
+
let numChannels = 0;
|
|
212
|
+
let bitsPerSample = 0;
|
|
213
|
+
let audioFormat = 0;
|
|
214
|
+
let dataOffset = -1;
|
|
215
|
+
let dataSize = 0;
|
|
216
|
+
let offset = 12;
|
|
217
|
+
while (offset + 8 <= bytes.length) {
|
|
218
|
+
const chunkId = asciiAt(bytes, offset, offset + 4);
|
|
219
|
+
const chunkSize = view.getUint32(offset + 4, true);
|
|
220
|
+
const body = offset + 8;
|
|
221
|
+
if (chunkId === "fmt " && body + 16 <= bytes.length) {
|
|
222
|
+
audioFormat = view.getUint16(body, true);
|
|
223
|
+
numChannels = view.getUint16(body + 2, true);
|
|
224
|
+
sampleRate = view.getUint32(body + 4, true);
|
|
225
|
+
bitsPerSample = view.getUint16(body + 14, true);
|
|
226
|
+
// WAVE_FORMAT_EXTENSIBLE carries the real PCM/float tag in the first
|
|
227
|
+
// two bytes of its SubFormat GUID (at fmt body + 24); unwrap it so
|
|
228
|
+
// downstream sees a plain 1 (int) or 3 (float).
|
|
229
|
+
if (audioFormat === 0xfffe && body + 26 <= bytes.length) {
|
|
230
|
+
audioFormat = view.getUint16(body + 24, true);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else if (chunkId === "data") {
|
|
234
|
+
// `fmt ` always precedes `data` in a well-formed file, so the format
|
|
235
|
+
// fields are populated by the time we get here.
|
|
236
|
+
dataOffset = body;
|
|
237
|
+
dataSize = chunkSize;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
offset = body + chunkSize + (chunkSize & 1);
|
|
241
|
+
}
|
|
242
|
+
if (dataOffset < 0)
|
|
243
|
+
return null;
|
|
244
|
+
const available = bytes.length - dataOffset;
|
|
245
|
+
if (dataSize <= 0 || dataSize > available)
|
|
246
|
+
dataSize = available;
|
|
247
|
+
return {
|
|
248
|
+
sampleRate,
|
|
249
|
+
numChannels,
|
|
250
|
+
bitsPerSample,
|
|
251
|
+
audioFormat,
|
|
252
|
+
dataOffset,
|
|
253
|
+
dataSize
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Parse already-loaded WAV bytes into Float32 samples (channel-interleaved).
|
|
258
|
+
* Returns null when the input is not a valid RIFF/WAVE file or carries a
|
|
259
|
+
* format this decoder doesn't handle (caller then falls back to WebAudio /
|
|
260
|
+
* ffmpeg).
|
|
261
|
+
*
|
|
262
|
+
* Supported: integer PCM at 8/16/24/32-bit and IEEE float at 32-bit — the
|
|
263
|
+
* formats `encodeWav`, ffmpeg, and common recorders emit. This is the only
|
|
264
|
+
* decode path with no native-addon or subprocess dependency, so keeping it
|
|
265
|
+
* broad lets edge/workers/browser runtimes decode without ffmpeg. Subchunks
|
|
266
|
+
* are traversed, so layouts with `LIST`/`JUNK`/etc. before `data` work.
|
|
267
|
+
*/
|
|
268
|
+
export function parseWavBytes(bytes) {
|
|
269
|
+
const header = readWavHeader(bytes);
|
|
270
|
+
if (!header)
|
|
271
|
+
return null;
|
|
272
|
+
const { sampleRate, numChannels, bitsPerSample, audioFormat, dataOffset, dataSize } = header;
|
|
273
|
+
const bytesPerSample = bitsPerSample / 8;
|
|
274
|
+
// format 3 = IEEE float (32-bit only); format 1 (or a 0 tag from minimal
|
|
275
|
+
// encoders) = integer PCM at 8/16/24/32-bit. Anything else → null.
|
|
276
|
+
const isFloat = audioFormat === 3 && bitsPerSample === 32;
|
|
277
|
+
const isPcm = (audioFormat === 1 || audioFormat === 0) &&
|
|
278
|
+
(bitsPerSample === 8 ||
|
|
279
|
+
bitsPerSample === 16 ||
|
|
280
|
+
bitsPerSample === 24 ||
|
|
281
|
+
bitsPerSample === 32);
|
|
282
|
+
if (!isFloat && !isPcm)
|
|
283
|
+
return null;
|
|
284
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
285
|
+
const totalSamples = Math.floor(dataSize / bytesPerSample);
|
|
286
|
+
const samples = new Float32Array(totalSamples);
|
|
287
|
+
for (let i = 0; i < totalSamples; i++) {
|
|
288
|
+
const pos = dataOffset + i * bytesPerSample;
|
|
289
|
+
if (isFloat) {
|
|
290
|
+
samples[i] = view.getFloat32(pos, true);
|
|
291
|
+
}
|
|
292
|
+
else if (bitsPerSample === 16) {
|
|
293
|
+
samples[i] = view.getInt16(pos, true) / 0x7fff;
|
|
294
|
+
}
|
|
295
|
+
else if (bitsPerSample === 8) {
|
|
296
|
+
samples[i] = (bytes[pos] - 128) / 128;
|
|
297
|
+
}
|
|
298
|
+
else if (bitsPerSample === 24) {
|
|
299
|
+
let v = bytes[pos] | (bytes[pos + 1] << 8) | (bytes[pos + 2] << 16);
|
|
300
|
+
if (v & 0x800000)
|
|
301
|
+
v -= 0x1000000; // sign-extend 24-bit
|
|
302
|
+
samples[i] = v / 0x7fffff;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
samples[i] = view.getInt32(pos, true) / 0x7fffffff; // 32-bit int PCM
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return { samples, sampleRate, numChannels };
|
|
309
|
+
}
|
|
310
|
+
/** Split channel-interleaved samples into per-channel planes. */
|
|
311
|
+
export function deinterleave(samples, numChannels) {
|
|
312
|
+
const channels = Math.max(1, numChannels);
|
|
313
|
+
const frames = Math.floor(samples.length / channels);
|
|
314
|
+
const planes = [];
|
|
315
|
+
for (let ch = 0; ch < channels; ch++) {
|
|
316
|
+
const plane = new Float32Array(frames);
|
|
317
|
+
for (let i = 0; i < frames; i++)
|
|
318
|
+
plane[i] = samples[i * channels + ch];
|
|
319
|
+
planes.push(plane);
|
|
320
|
+
}
|
|
321
|
+
return planes;
|
|
322
|
+
}
|
|
323
|
+
/** Interleave per-channel planes back into a single sample buffer. */
|
|
324
|
+
export function interleave(planes) {
|
|
325
|
+
const numChannels = planes.length;
|
|
326
|
+
const frames = numChannels > 0 ? planes[0].length : 0;
|
|
327
|
+
const out = new Float32Array(frames * numChannels);
|
|
328
|
+
for (let ch = 0; ch < numChannels; ch++) {
|
|
329
|
+
for (let i = 0; i < frames; i++) {
|
|
330
|
+
out[i * numChannels + ch] = planes[ch][i];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
/** Decode raw little-endian 16-bit PCM bytes into Float32 samples ([-1, 1]). */
|
|
336
|
+
export function pcm16ToFloat32(bytes) {
|
|
337
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
338
|
+
const count = Math.floor(bytes.length / 2);
|
|
339
|
+
const samples = new Float32Array(count);
|
|
340
|
+
for (let i = 0; i < count; i++) {
|
|
341
|
+
samples[i] = view.getInt16(i * 2, true) / 0x7fff;
|
|
342
|
+
}
|
|
343
|
+
return samples;
|
|
344
|
+
}
|
|
345
|
+
/** Encode Float32 samples (clipped to [-1, 1]) as little-endian 16-bit PCM bytes. */
|
|
346
|
+
export function float32ToPcm16(samples) {
|
|
347
|
+
const out = new Uint8Array(samples.length * 2);
|
|
348
|
+
const view = new DataView(out.buffer);
|
|
349
|
+
for (let i = 0; i < samples.length; i++) {
|
|
350
|
+
const s = Math.max(-1, Math.min(1, samples[i]));
|
|
351
|
+
view.setInt16(i * 2, Math.round(s * 0x7fff), true);
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Decode an AudioRef as WAV. Throws when the ref does not contain a valid
|
|
357
|
+
* WAV file.
|
|
358
|
+
*/
|
|
359
|
+
export function decodeWav(audio) {
|
|
360
|
+
const wav = parseWavBytes(audioBytes(audio));
|
|
361
|
+
if (!wav)
|
|
362
|
+
throw new Error("Invalid WAV file");
|
|
363
|
+
return wav;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Decode an AudioRef as WAV, returning null for non-WAV / malformed input
|
|
367
|
+
* instead of throwing. Use this when a caller wants to fall back to raw
|
|
368
|
+
* byte handling when the input is not WAV.
|
|
369
|
+
*/
|
|
370
|
+
export function tryDecodeWav(audio) {
|
|
371
|
+
return parseWavBytes(audioBytes(audio));
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Decode arbitrary audio bytes (WAV, or any compressed format — mp3, flac,
|
|
375
|
+
* ogg, m4a, WebM/Opus, …) into interleaved Float32 PCM.
|
|
376
|
+
*
|
|
377
|
+
* Decode order:
|
|
378
|
+
* 1. WAV is parsed directly — no subprocess, no native addon.
|
|
379
|
+
* 2. Otherwise WebAudio's `decodeAudioData` (`node-web-audio-api` on Node,
|
|
380
|
+
* the global in Chromium Web Workers). Handles mp3/flac/ogg-vorbis, but
|
|
381
|
+
* its Symphonia backend has no Opus/AAC/ALAC decoder.
|
|
382
|
+
* 3. On Node, when WebAudio can't decode the input — notably the WebM/Opus a
|
|
383
|
+
* browser `MediaRecorder` produces — fall back to ffmpeg, one of
|
|
384
|
+
* Nodetool's managed runtime tools (the same universal decoder the ASR
|
|
385
|
+
* nodes use).
|
|
386
|
+
*
|
|
387
|
+
* When nothing can decode the bytes we throw an actionable error rather than
|
|
388
|
+
* the opaque "Invalid WAV file" from `decodeWav`. Effect/DSP nodes use this
|
|
389
|
+
* instead of `decodeWav` so a stored `.mp3`/`.webm` input is processed rather
|
|
390
|
+
* than rejected.
|
|
391
|
+
*/
|
|
392
|
+
export async function decodeAudioToWav(bytes) {
|
|
393
|
+
const wav = parseWavBytes(bytes);
|
|
394
|
+
if (wav)
|
|
395
|
+
return wav;
|
|
396
|
+
// WebAudio first: always present on Node (node-web-audio-api) and in
|
|
397
|
+
// Chromium workers, and avoids a subprocess for the formats it supports.
|
|
398
|
+
const Ctor = await loadOfflineAudioContext();
|
|
399
|
+
let webAudioError;
|
|
400
|
+
if (Ctor) {
|
|
401
|
+
try {
|
|
402
|
+
return await decodeViaWebAudio(Ctor, bytes);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
webAudioError = error;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
// ffmpeg fallback (Node only): decodes what WebAudio's Symphonia backend
|
|
409
|
+
// can't — notably the WebM/Opus a browser MediaRecorder emits.
|
|
410
|
+
const viaFfmpeg = await tryFfmpegDecodeToWav(bytes);
|
|
411
|
+
if (viaFfmpeg)
|
|
412
|
+
return viaFfmpeg;
|
|
413
|
+
// Nothing decoded it. Throw a reason that fits the runtime — every branch
|
|
414
|
+
// keeps the "Could not decode audio" prefix that callers/tests match on.
|
|
415
|
+
const WAV_FORMATS = "WAV (8/16/24/32-bit PCM or 32-bit float)";
|
|
416
|
+
if (IS_NODE) {
|
|
417
|
+
const reason = Ctor
|
|
418
|
+
? `WebAudio can't read it (${webAudioError instanceof Error
|
|
419
|
+
? webAudioError.message
|
|
420
|
+
: String(webAudioError)}) and ffmpeg is unavailable`
|
|
421
|
+
: "WebAudio (node-web-audio-api) could not be loaded and ffmpeg is unavailable";
|
|
422
|
+
throw new Error(`Could not decode audio: input is not ${WAV_FORMATS} — ${reason}. ` +
|
|
423
|
+
`Install ffmpeg (the Package Manager UI can do this) to decode formats ` +
|
|
424
|
+
`like WebM/Opus, mp3, or m4a, or convert the audio to WAV upstream.`);
|
|
425
|
+
}
|
|
426
|
+
if (Ctor) {
|
|
427
|
+
throw new Error(`Could not decode audio: the bytes are neither WAV nor a format WebAudio ` +
|
|
428
|
+
`can read (${webAudioError instanceof Error
|
|
429
|
+
? webAudioError.message
|
|
430
|
+
: String(webAudioError)}).`);
|
|
431
|
+
}
|
|
432
|
+
// Browser worker without WebAudio (Firefox/Safari), or an Edge/Workers
|
|
433
|
+
// runtime with no WebAudio and no subprocess — only the pure-JS WAV path
|
|
434
|
+
// is available here.
|
|
435
|
+
throw new Error(`Could not decode audio: this runtime can only decode ${WAV_FORMATS} directly. ` +
|
|
436
|
+
`Convert the audio to WAV upstream, or run this node on a Node server where ` +
|
|
437
|
+
`ffmpeg can decode compressed formats.`);
|
|
438
|
+
}
|
|
439
|
+
/** Decode `bytes` via WebAudio into interleaved Float32 PCM. */
|
|
440
|
+
async function decodeViaWebAudio(Ctor, bytes) {
|
|
441
|
+
// decodeAudioData wants a standalone ArrayBuffer; slice to the ref's exact
|
|
442
|
+
// byte range in case `bytes` is a view onto a larger pooled buffer.
|
|
443
|
+
const arrayBuffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
444
|
+
// The constructor args don't affect decoding — decodeAudioData honors the
|
|
445
|
+
// file's own sample rate / channel count.
|
|
446
|
+
const ctx = new Ctor(1, 1, 44100);
|
|
447
|
+
const audioBuffer = await ctx.decodeAudioData(arrayBuffer);
|
|
448
|
+
const numChannels = audioBuffer.numberOfChannels;
|
|
449
|
+
const frames = audioBuffer.length;
|
|
450
|
+
const samples = new Float32Array(frames * numChannels);
|
|
451
|
+
for (let ch = 0; ch < numChannels; ch++) {
|
|
452
|
+
const channel = audioBuffer.getChannelData(ch);
|
|
453
|
+
for (let i = 0; i < frames; i++) {
|
|
454
|
+
samples[i * numChannels + ch] = channel[i];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return { samples, sampleRate: audioBuffer.sampleRate, numChannels };
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Decode arbitrary audio to WAV via ffmpeg, preserving the source channel
|
|
461
|
+
* count and sample rate (no `-ac`/`-ar` — an audio effect must not silently
|
|
462
|
+
* downmix or resample). Returns null off-Node, when ffmpeg isn't installed,
|
|
463
|
+
* or when the conversion fails — callers surface their own error. Output is
|
|
464
|
+
* 16-bit PCM, which the effect nodes re-encode to anyway, so no precision is
|
|
465
|
+
* lost relative to the node's result.
|
|
466
|
+
*/
|
|
467
|
+
async function tryFfmpegDecodeToWav(bytes) {
|
|
468
|
+
if (!IS_NODE || bytes.length === 0)
|
|
469
|
+
return null;
|
|
470
|
+
const childProcess = await importNodeBuiltin("node:child_process");
|
|
471
|
+
if (!childProcess)
|
|
472
|
+
return null;
|
|
473
|
+
const fs = await loadNodeFsPromises();
|
|
474
|
+
const os = await loadNodeOs();
|
|
475
|
+
const path = await loadNodePath();
|
|
476
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "nodetool-audio-decode-"));
|
|
477
|
+
const inPath = path.join(dir, "input.bin");
|
|
478
|
+
const outPath = path.join(dir, "output.wav");
|
|
479
|
+
try {
|
|
480
|
+
await fs.writeFile(inPath, bytes);
|
|
481
|
+
await new Promise((resolve, reject) => {
|
|
482
|
+
childProcess.execFile("ffmpeg", [
|
|
483
|
+
"-y",
|
|
484
|
+
"-loglevel",
|
|
485
|
+
"error",
|
|
486
|
+
"-i",
|
|
487
|
+
inPath,
|
|
488
|
+
"-c:a",
|
|
489
|
+
"pcm_s16le",
|
|
490
|
+
"-f",
|
|
491
|
+
"wav",
|
|
492
|
+
outPath
|
|
493
|
+
], { maxBuffer: 64 * 1024 * 1024 }, (error) => (error ? reject(error) : resolve()));
|
|
494
|
+
});
|
|
495
|
+
return parseWavBytes(new Uint8Array(await fs.readFile(outPath)));
|
|
496
|
+
}
|
|
497
|
+
catch {
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
finally {
|
|
501
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
//# sourceMappingURL=audio-wav.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio-wav.js","sourceRoot":"","sources":["../../src/lib/audio-wav.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,YAAY,EACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EACL,kBAAkB,EAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,uBAAuB,EAExB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACT,MAAM,uBAAuB,CAAC;AAc/B,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,KAAsC;IAC5D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,UAAU,EAAE,CAAC;IACpC,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,KAAK,C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OfflineAudioContext` is
|
|
6
|
+
* unavailable (Web Workers in Firefox/Safari — see `lib/audio-context.ts`).
|
|
7
|
+
* - The engine for the streaming filter nodes, whose `BiquadState` carries
|
|
8
|
+
* filter memory across chunk boundaries (something a per-chunk
|
|
9
|
+
* OfflineAudioContext cannot do).
|
|
10
|
+
*
|
|
11
|
+
* Coefficients follow the same cookbook formulas WebAudio's
|
|
12
|
+
* `BiquadFilterNode` is specified against, so parity with the WebAudio path
|
|
13
|
+
* is close but not bit-exact.
|
|
14
|
+
*/
|
|
15
|
+
import { type WavData } from "./audio-wav.js";
|
|
16
|
+
export type BiquadType = "lowpass" | "highpass" | "lowshelf" | "highshelf" | "peaking";
|
|
17
|
+
/** Filter coefficients, normalized by a0. */
|
|
18
|
+
export interface BiquadCoeffs {
|
|
19
|
+
b0: number;
|
|
20
|
+
b1: number;
|
|
21
|
+
b2: number;
|
|
22
|
+
a1: number;
|
|
23
|
+
a2: number;
|
|
24
|
+
}
|
|
25
|
+
/** Direct Form I delay-line state for one channel. */
|
|
26
|
+
export interface BiquadState {
|
|
27
|
+
x1: number;
|
|
28
|
+
x2: number;
|
|
29
|
+
y1: number;
|
|
30
|
+
y2: number;
|
|
31
|
+
}
|
|
32
|
+
/** WebAudio's default Q (Butterworth response for lowpass/highpass). */
|
|
33
|
+
export declare const DEFAULT_Q: number;
|
|
34
|
+
/** Compute normalized biquad coefficients per the RBJ Audio-EQ-Cookbook. */
|
|
35
|
+
export declare function biquadCoeffs(type: BiquadType, sampleRate: number, frequency: number, q?: number, gainDb?: number): BiquadCoeffs;
|
|
36
|
+
/** Fresh (all-zero) delay-line state. */
|
|
37
|
+
export declare function createBiquadState(): BiquadState;
|
|
38
|
+
/**
|
|
39
|
+
* Run a Direct Form I biquad over `input`, returning the filtered samples.
|
|
40
|
+
* Mutates `state` so callers can carry filter memory across chunks.
|
|
41
|
+
*/
|
|
42
|
+
export declare function processBiquad(coeffs: BiquadCoeffs, state: BiquadState, input: Float32Array): Float32Array;
|
|
43
|
+
/**
|
|
44
|
+
* Apply a biquad filter to whole interleaved WAV data (independent state per
|
|
45
|
+
* channel). Whole-buffer convenience used as the OfflineAudioContext fallback.
|
|
46
|
+
*/
|
|
47
|
+
export declare function applyBiquadToWav(wav: WavData, type: BiquadType, frequency: number, q?: number, gainDb?: number): WavData;
|
|
48
|
+
//# sourceMappingURL=biquad.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"biquad.d.ts","sourceRoot":"","sources":["../../src/lib/biquad.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,SAAS,CAAC;AAEd,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wEAAwE;AACxE,eAAO,MAAM,SAAS,QAAe,CAAC;AAEtC,4EAA4E;AAC5E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,CAAC,GAAE,MAAkB,EACrB,MAAM,SAAI,GACT,YAAY,CAqEd;AAED,yCAAyC;AACzC,wBAAgB,iBAAiB,IAAI,WAAW,CAE/C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,YAAY,GAClB,YAAY,CAkBd;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,EACjB,CAAC,GAAE,MAAkB,EACrB,MAAM,SAAI,GACT,OAAO,CAWT"}
|