@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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RBJ Audio-EQ-Cookbook biquad filters, pure TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* Serves two purposes:
|
|
5
|
+
* - Fallback for the batch filter nodes when `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 { deinterleave, interleave } from "./audio-wav.js";
|
|
16
|
+
/** WebAudio's default Q (Butterworth response for lowpass/highpass). */
|
|
17
|
+
export const DEFAULT_Q = Math.SQRT1_2;
|
|
18
|
+
/** Compute normalized biquad coefficients per the RBJ Audio-EQ-Cookbook. */
|
|
19
|
+
export function biquadCoeffs(type, sampleRate, frequency, q = DEFAULT_Q, gainDb = 0) {
|
|
20
|
+
// Clamp to a valid digital frequency range to keep the filter stable.
|
|
21
|
+
const nyquist = sampleRate / 2;
|
|
22
|
+
const f = Math.min(Math.max(frequency, 1), nyquist * 0.9999);
|
|
23
|
+
const w0 = (2 * Math.PI * f) / sampleRate;
|
|
24
|
+
const cosW0 = Math.cos(w0);
|
|
25
|
+
const sinW0 = Math.sin(w0);
|
|
26
|
+
const safeQ = Math.max(q, 1e-4);
|
|
27
|
+
const alpha = sinW0 / (2 * safeQ);
|
|
28
|
+
const A = Math.pow(10, gainDb / 40);
|
|
29
|
+
let b0;
|
|
30
|
+
let b1;
|
|
31
|
+
let b2;
|
|
32
|
+
let a0;
|
|
33
|
+
let a1;
|
|
34
|
+
let a2;
|
|
35
|
+
switch (type) {
|
|
36
|
+
case "lowpass": {
|
|
37
|
+
b0 = (1 - cosW0) / 2;
|
|
38
|
+
b1 = 1 - cosW0;
|
|
39
|
+
b2 = (1 - cosW0) / 2;
|
|
40
|
+
a0 = 1 + alpha;
|
|
41
|
+
a1 = -2 * cosW0;
|
|
42
|
+
a2 = 1 - alpha;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case "highpass": {
|
|
46
|
+
b0 = (1 + cosW0) / 2;
|
|
47
|
+
b1 = -(1 + cosW0);
|
|
48
|
+
b2 = (1 + cosW0) / 2;
|
|
49
|
+
a0 = 1 + alpha;
|
|
50
|
+
a1 = -2 * cosW0;
|
|
51
|
+
a2 = 1 - alpha;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "lowshelf": {
|
|
55
|
+
const twoSqrtAAlpha = 2 * Math.sqrt(A) * alpha;
|
|
56
|
+
b0 = A * (A + 1 - (A - 1) * cosW0 + twoSqrtAAlpha);
|
|
57
|
+
b1 = 2 * A * (A - 1 - (A + 1) * cosW0);
|
|
58
|
+
b2 = A * (A + 1 - (A - 1) * cosW0 - twoSqrtAAlpha);
|
|
59
|
+
a0 = A + 1 + (A - 1) * cosW0 + twoSqrtAAlpha;
|
|
60
|
+
a1 = -2 * (A - 1 + (A + 1) * cosW0);
|
|
61
|
+
a2 = A + 1 + (A - 1) * cosW0 - twoSqrtAAlpha;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case "highshelf": {
|
|
65
|
+
const twoSqrtAAlpha = 2 * Math.sqrt(A) * alpha;
|
|
66
|
+
b0 = A * (A + 1 + (A - 1) * cosW0 + twoSqrtAAlpha);
|
|
67
|
+
b1 = -2 * A * (A - 1 + (A + 1) * cosW0);
|
|
68
|
+
b2 = A * (A + 1 + (A - 1) * cosW0 - twoSqrtAAlpha);
|
|
69
|
+
a0 = A + 1 - (A - 1) * cosW0 + twoSqrtAAlpha;
|
|
70
|
+
a1 = 2 * (A - 1 - (A + 1) * cosW0);
|
|
71
|
+
a2 = A + 1 - (A - 1) * cosW0 - twoSqrtAAlpha;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "peaking": {
|
|
75
|
+
b0 = 1 + alpha * A;
|
|
76
|
+
b1 = -2 * cosW0;
|
|
77
|
+
b2 = 1 - alpha * A;
|
|
78
|
+
a0 = 1 + alpha / A;
|
|
79
|
+
a1 = -2 * cosW0;
|
|
80
|
+
a2 = 1 - alpha / A;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { b0: b0 / a0, b1: b1 / a0, b2: b2 / a0, a1: a1 / a0, a2: a2 / a0 };
|
|
85
|
+
}
|
|
86
|
+
/** Fresh (all-zero) delay-line state. */
|
|
87
|
+
export function createBiquadState() {
|
|
88
|
+
return { x1: 0, x2: 0, y1: 0, y2: 0 };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run a Direct Form I biquad over `input`, returning the filtered samples.
|
|
92
|
+
* Mutates `state` so callers can carry filter memory across chunks.
|
|
93
|
+
*/
|
|
94
|
+
export function processBiquad(coeffs, state, input) {
|
|
95
|
+
const { b0, b1, b2, a1, a2 } = coeffs;
|
|
96
|
+
let { x1, x2, y1, y2 } = state;
|
|
97
|
+
const out = new Float32Array(input.length);
|
|
98
|
+
for (let i = 0; i < input.length; i++) {
|
|
99
|
+
const x0 = input[i];
|
|
100
|
+
const y0 = b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
|
|
101
|
+
out[i] = y0;
|
|
102
|
+
x2 = x1;
|
|
103
|
+
x1 = x0;
|
|
104
|
+
y2 = y1;
|
|
105
|
+
y1 = y0;
|
|
106
|
+
}
|
|
107
|
+
state.x1 = x1;
|
|
108
|
+
state.x2 = x2;
|
|
109
|
+
state.y1 = y1;
|
|
110
|
+
state.y2 = y2;
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Apply a biquad filter to whole interleaved WAV data (independent state per
|
|
115
|
+
* channel). Whole-buffer convenience used as the OfflineAudioContext fallback.
|
|
116
|
+
*/
|
|
117
|
+
export function applyBiquadToWav(wav, type, frequency, q = DEFAULT_Q, gainDb = 0) {
|
|
118
|
+
const coeffs = biquadCoeffs(type, wav.sampleRate, frequency, q, gainDb);
|
|
119
|
+
const planes = deinterleave(wav.samples, wav.numChannels);
|
|
120
|
+
const filtered = planes.map((plane) => processBiquad(coeffs, createBiquadState(), plane));
|
|
121
|
+
return {
|
|
122
|
+
samples: interleave(filtered),
|
|
123
|
+
sampleRate: wav.sampleRate,
|
|
124
|
+
numChannels: wav.numChannels
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=biquad.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"biquad.js","sourceRoot":"","sources":["../../src/lib/biquad.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAgB,MAAM,gBAAgB,CAAC;AA0BxE,wEAAwE;AACxE,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAA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,GAAG,EAAE,CAAC;QACR,EAAE,GAAG,EAAE,CAAC;IACV,CAAC;IACD,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAY,EACZ,IAAgB,EAChB,SAAiB,EACjB,CAAC,GAAW,SAAS,EACrB,MAAM,GAAG,CAAC;IAEV,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACpC,aAAa,CAAC,MAAM,EAAE,iBAAiB,EAAE,EAAE,KAAK,CAAC,CAClD,CAAC;IACF,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC;QAC7B,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;KAC7B,CAAC;AACJ,CAAC"}
|
package/dist/lib/cv.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Control-voltage (CV) signal helpers for the modular synthesis nodes.
|
|
3
|
+
*
|
|
4
|
+
* CV rides the same chunk shape as streaming audio (`type:"chunk"`,
|
|
5
|
+
* `content_type:"audio"`, `done:true` terminator). In-process the payload is
|
|
6
|
+
* a native `Float32Array` (zero per-hop conversions); encoded string
|
|
7
|
+
* payloads from external sources are still decoded, where `encoding:"f32le"`
|
|
8
|
+
* matters for CV: pcm16 clamps to [-1,1] and quantizes, which is wrong for
|
|
9
|
+
* multi-octave pitch CV. `readSignalChunk` accepts all three forms, so any
|
|
10
|
+
* signal node accepts audio and CV interchangeably (Eurorack semantics).
|
|
11
|
+
*
|
|
12
|
+
* Also home to the sample-domain timing utilities:
|
|
13
|
+
* - `SampleFifo` / `alignedSignalStreams` — the "zip-with-hold" pattern for
|
|
14
|
+
* multi-input streaming nodes (the kernel has no sample-aligned zip;
|
|
15
|
+
* alignment is exact when one clock drives the patch, hold-last
|
|
16
|
+
* otherwise).
|
|
17
|
+
* - `abortableSleep` / `RealtimePacer` — wall-clock pacing for the
|
|
18
|
+
* free-running generators. Pacing only delays emission; signal content
|
|
19
|
+
* is identical to an unpaced run.
|
|
20
|
+
*/
|
|
21
|
+
import type { StreamingInputs } from "@nodetool-ai/node-sdk";
|
|
22
|
+
export type SignalEncoding = "pcm16le" | "f32le";
|
|
23
|
+
/** Default sample rate for synth generators (matches the chunk default). */
|
|
24
|
+
export declare const SYNTH_SAMPLE_RATE = 24000;
|
|
25
|
+
/** Frames per generated chunk (~21 ms @ 24 kHz). */
|
|
26
|
+
export declare const SYNTH_CHUNK_FRAMES = 512;
|
|
27
|
+
/** Default value for `@prop({ type: "chunk" })` declarations on signal nodes. */
|
|
28
|
+
export declare const CHUNK_PROP_DEFAULT: {
|
|
29
|
+
type: string;
|
|
30
|
+
node_id: null;
|
|
31
|
+
thread_id: null;
|
|
32
|
+
workflow_id: null;
|
|
33
|
+
content_type: string;
|
|
34
|
+
content: string;
|
|
35
|
+
content_metadata: {};
|
|
36
|
+
done: boolean;
|
|
37
|
+
thinking: boolean;
|
|
38
|
+
};
|
|
39
|
+
export interface SignalChunk {
|
|
40
|
+
/** Channel-interleaved samples; empty for done markers. */
|
|
41
|
+
samples: Float32Array;
|
|
42
|
+
sampleRate: number;
|
|
43
|
+
channels: number;
|
|
44
|
+
done: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse a streamed item as a signal (audio or CV) chunk. Returns null for
|
|
48
|
+
* non-audio chunks and non-chunk values, which callers skip. Decodes
|
|
49
|
+
* `encoding:"f32le"` payloads as little-endian float32; anything else
|
|
50
|
+
* (including absent metadata) takes the legacy pcm16le path.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readSignalChunk(item: unknown): SignalChunk | null;
|
|
53
|
+
/**
|
|
54
|
+
* Build a signal chunk in the shared chunk shape. Samples stay a native
|
|
55
|
+
* `Float32Array` — no encoding between nodes; the websocket transport
|
|
56
|
+
* encodes to base64 at the wire boundary. The `encoding` parameter is kept
|
|
57
|
+
* as metadata describing the *preferred wire encoding* for consumers that do
|
|
58
|
+
* serialize (pcm16le clamps to [-1,1], wrong for multi-octave CV).
|
|
59
|
+
*/
|
|
60
|
+
export declare function makeSignalChunk(samples: Float32Array, sampleRate: number, channels: number, done: boolean, encoding: SignalEncoding): {
|
|
61
|
+
type: string;
|
|
62
|
+
content: string | Float32Array<ArrayBufferLike>;
|
|
63
|
+
done: boolean;
|
|
64
|
+
content_type: string;
|
|
65
|
+
content_metadata: {
|
|
66
|
+
encoding: SignalEncoding;
|
|
67
|
+
sample_rate: number;
|
|
68
|
+
channels: number;
|
|
69
|
+
format: string;
|
|
70
|
+
duration_seconds: number;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/** End-of-stream marker: empty content, `done: true`. */
|
|
74
|
+
export declare function makeDoneSignalChunk(sampleRate: number, channels: number, encoding: SignalEncoding): Record<string, unknown>;
|
|
75
|
+
/** Decode little-endian float32 bytes (explicit DataView for endianness safety). */
|
|
76
|
+
export declare function f32leToFloat32(bytes: Uint8Array): Float32Array;
|
|
77
|
+
/** Encode samples as little-endian float32 bytes. */
|
|
78
|
+
export declare function float32ToF32le(samples: Float32Array): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Mono sample queue with hold-last semantics: pulling past the available
|
|
81
|
+
* samples repeats the last seen value ("hold", the modular sample-&-hold
|
|
82
|
+
* convention for a lagging or finished CV source) or fills zeros ("zero",
|
|
83
|
+
* correct for ended audio in a mixer). Initial held value is 0.
|
|
84
|
+
*/
|
|
85
|
+
export declare class SampleFifo {
|
|
86
|
+
private _segments;
|
|
87
|
+
private _offset;
|
|
88
|
+
private _available;
|
|
89
|
+
private _last;
|
|
90
|
+
get available(): number;
|
|
91
|
+
/** The most recently pushed (or pulled) sample value; 0 before any data. */
|
|
92
|
+
get last(): number;
|
|
93
|
+
push(samples: Float32Array): void;
|
|
94
|
+
pull(n: number, mode: "hold" | "zero"): Float32Array;
|
|
95
|
+
}
|
|
96
|
+
export interface AlignedFrame {
|
|
97
|
+
/** The primary (driving) chunk — never a done marker. */
|
|
98
|
+
primary: SignalChunk;
|
|
99
|
+
/**
|
|
100
|
+
* Per-CV-handle mono sample arrays, one value per primary *frame*
|
|
101
|
+
* (hold-last when a CV source lags or has ended). Unconnected handles are
|
|
102
|
+
* absent — check membership rather than relying on defaults.
|
|
103
|
+
*/
|
|
104
|
+
cv: Record<string, Float32Array>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Zip-with-hold: consume one primary stream and any number of CV streams,
|
|
108
|
+
* yielding the primary chunks paired with frame-aligned CV values.
|
|
109
|
+
*
|
|
110
|
+
* Sample-exact when all streams share cadence (a patch driven by a single
|
|
111
|
+
* clock source); otherwise CV degrades to hold-last. Deadlock-free: the
|
|
112
|
+
* single `inputs.any()` loop only blocks while some upstream is open, and a
|
|
113
|
+
* primary chunk is released as soon as every connected CV handle can cover
|
|
114
|
+
* it (buffered, done, or the whole loop ended). Multichannel CV inputs are
|
|
115
|
+
* collapsed to channel 0.
|
|
116
|
+
*/
|
|
117
|
+
export declare function alignedSignalStreams(inputs: StreamingInputs, opts: {
|
|
118
|
+
primary: string;
|
|
119
|
+
cvHandles: readonly string[];
|
|
120
|
+
}): AsyncGenerator<AlignedFrame>;
|
|
121
|
+
/** Sleep that resolves early (without throwing) when `signal` aborts. */
|
|
122
|
+
export declare function abortableSleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Drift-compensated wall-clock pacer for free-running generators: chunk k
|
|
125
|
+
* is released no earlier than the cumulative duration of chunks 0..k-1
|
|
126
|
+
* after start (absolute target times, same scheme as IntervalTriggerNode).
|
|
127
|
+
* Pacing never alters chunk contents — a paced render is bit-identical to
|
|
128
|
+
* an unpaced one.
|
|
129
|
+
*/
|
|
130
|
+
export declare class RealtimePacer {
|
|
131
|
+
private readonly _signal?;
|
|
132
|
+
private _nextTargetMs;
|
|
133
|
+
constructor(_signal?: AbortSignal | undefined);
|
|
134
|
+
/**
|
|
135
|
+
* Wait for the chunk's emission slot, then advance the next slot by
|
|
136
|
+
* `chunkMs` (this chunk's duration). Returns false when the run was
|
|
137
|
+
* cancelled — the caller must stop producing.
|
|
138
|
+
*/
|
|
139
|
+
waitNext(chunkMs: number): Promise<boolean>;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=cv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cv.d.ts","sourceRoot":"","sources":["../../src/lib/cv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAS7D,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,CAAC;AAEjD,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AACvC,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,iFAAiF;AACjF,eAAO,MAAM,kBAAkB;IAC7B,IAAI;IACJ,OAAO;IACP,SAAS;IACT,WAAW;IACX,YAAY;IACZ,OAAO;IACP,gBAAgB;IAChB,IAAI;IACJ,QAAQ;CACT,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,2DAA2D;IAC3D,OAAO,EAAE,YAAY,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,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AM,EAAE,eAAe,EACvB,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACtD,cAAc,CAAC,YAAY,CAAC,CA4C9B;AAcD,yEAAyE;AACzE,wBAAgB,cAAc,CAC5B,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;;;GAMG;AACH,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAFrC,OAAO,CAAC,aAAa,CAAc;IAEnC,YAA6B,OAAO,CAAC,EAAE,WAAW,YAAA,EAAI;IAEtD;;;;OAIG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKhD;CACF"}
|
package/dist/lib/cv.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { base64ToBytes } from "@nodetool-ai/nodes-utils";
|
|
2
|
+
import { pcm16ToFloat32 } from "./audio-wav.js";
|
|
3
|
+
import { isNonEmptyString, isObjectLike, isPositiveNumber } from "@nodetool-ai/node-sdk";
|
|
4
|
+
/** Default sample rate for synth generators (matches the chunk default). */
|
|
5
|
+
export const SYNTH_SAMPLE_RATE = 24000;
|
|
6
|
+
/** Frames per generated chunk (~21 ms @ 24 kHz). */
|
|
7
|
+
export const SYNTH_CHUNK_FRAMES = 512;
|
|
8
|
+
/** Default value for `@prop({ type: "chunk" })` declarations on signal nodes. */
|
|
9
|
+
export const CHUNK_PROP_DEFAULT = {
|
|
10
|
+
type: "chunk",
|
|
11
|
+
node_id: null,
|
|
12
|
+
thread_id: null,
|
|
13
|
+
workflow_id: null,
|
|
14
|
+
content_type: "audio",
|
|
15
|
+
content: "",
|
|
16
|
+
content_metadata: {},
|
|
17
|
+
done: false,
|
|
18
|
+
thinking: false
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Parse a streamed item as a signal (audio or CV) chunk. Returns null for
|
|
22
|
+
* non-audio chunks and non-chunk values, which callers skip. Decodes
|
|
23
|
+
* `encoding:"f32le"` payloads as little-endian float32; anything else
|
|
24
|
+
* (including absent metadata) takes the legacy pcm16le path.
|
|
25
|
+
*/
|
|
26
|
+
export function readSignalChunk(item) {
|
|
27
|
+
if (!isObjectLike(item))
|
|
28
|
+
return null;
|
|
29
|
+
const c = item;
|
|
30
|
+
if (c.content_type !== undefined && c.content_type !== "audio")
|
|
31
|
+
return null;
|
|
32
|
+
const meta = (c.content_metadata ?? {});
|
|
33
|
+
const sampleRate = isPositiveNumber(meta.sample_rate) ? meta.sample_rate : SYNTH_SAMPLE_RATE;
|
|
34
|
+
const channels = isPositiveNumber(meta.channels) ? meta.channels : 1;
|
|
35
|
+
let samples;
|
|
36
|
+
if (c.content instanceof Float32Array) {
|
|
37
|
+
// Native in-process payload — zero conversions.
|
|
38
|
+
samples = c.content;
|
|
39
|
+
}
|
|
40
|
+
else if (isNonEmptyString(c.content)) {
|
|
41
|
+
// Encoded payload (external sources, websocket wire format).
|
|
42
|
+
const bytes = base64ToBytes(c.content);
|
|
43
|
+
samples =
|
|
44
|
+
meta.encoding === "f32le" ? f32leToFloat32(bytes) : pcm16ToFloat32(bytes);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
samples = new Float32Array(0);
|
|
48
|
+
}
|
|
49
|
+
return { samples, sampleRate, channels, done: Boolean(c.done ?? false) };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build a signal chunk in the shared chunk shape. Samples stay a native
|
|
53
|
+
* `Float32Array` — no encoding between nodes; the websocket transport
|
|
54
|
+
* encodes to base64 at the wire boundary. The `encoding` parameter is kept
|
|
55
|
+
* as metadata describing the *preferred wire encoding* for consumers that do
|
|
56
|
+
* serialize (pcm16le clamps to [-1,1], wrong for multi-octave CV).
|
|
57
|
+
*/
|
|
58
|
+
export function makeSignalChunk(samples, sampleRate, channels, done, encoding) {
|
|
59
|
+
return {
|
|
60
|
+
type: "chunk",
|
|
61
|
+
content: samples.length > 0 ? samples : "",
|
|
62
|
+
done,
|
|
63
|
+
content_type: "audio",
|
|
64
|
+
content_metadata: {
|
|
65
|
+
encoding,
|
|
66
|
+
sample_rate: sampleRate,
|
|
67
|
+
channels,
|
|
68
|
+
format: "pcm",
|
|
69
|
+
duration_seconds: samples.length / Math.max(1, channels) / sampleRate
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** End-of-stream marker: empty content, `done: true`. */
|
|
74
|
+
export function makeDoneSignalChunk(sampleRate, channels, encoding) {
|
|
75
|
+
return makeSignalChunk(new Float32Array(0), sampleRate, channels, true, encoding);
|
|
76
|
+
}
|
|
77
|
+
/** Decode little-endian float32 bytes (explicit DataView for endianness safety). */
|
|
78
|
+
export function f32leToFloat32(bytes) {
|
|
79
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
80
|
+
const count = Math.floor(bytes.length / 4);
|
|
81
|
+
const out = new Float32Array(count);
|
|
82
|
+
for (let i = 0; i < count; i++)
|
|
83
|
+
out[i] = view.getFloat32(i * 4, true);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/** Encode samples as little-endian float32 bytes. */
|
|
87
|
+
export function float32ToF32le(samples) {
|
|
88
|
+
const out = new Uint8Array(samples.length * 4);
|
|
89
|
+
const view = new DataView(out.buffer);
|
|
90
|
+
for (let i = 0; i < samples.length; i++) {
|
|
91
|
+
view.setFloat32(i * 4, samples[i], true);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
// ── Sample FIFO + zip-with-hold ────────────────────────────────────
|
|
96
|
+
/**
|
|
97
|
+
* Mono sample queue with hold-last semantics: pulling past the available
|
|
98
|
+
* samples repeats the last seen value ("hold", the modular sample-&-hold
|
|
99
|
+
* convention for a lagging or finished CV source) or fills zeros ("zero",
|
|
100
|
+
* correct for ended audio in a mixer). Initial held value is 0.
|
|
101
|
+
*/
|
|
102
|
+
export class SampleFifo {
|
|
103
|
+
_segments = [];
|
|
104
|
+
_offset = 0;
|
|
105
|
+
_available = 0;
|
|
106
|
+
_last = 0;
|
|
107
|
+
get available() {
|
|
108
|
+
return this._available;
|
|
109
|
+
}
|
|
110
|
+
/** The most recently pushed (or pulled) sample value; 0 before any data. */
|
|
111
|
+
get last() {
|
|
112
|
+
return this._last;
|
|
113
|
+
}
|
|
114
|
+
push(samples) {
|
|
115
|
+
if (samples.length === 0)
|
|
116
|
+
return;
|
|
117
|
+
this._segments.push(samples);
|
|
118
|
+
this._available += samples.length;
|
|
119
|
+
}
|
|
120
|
+
pull(n, mode) {
|
|
121
|
+
const out = new Float32Array(n);
|
|
122
|
+
let written = 0;
|
|
123
|
+
while (written < n && this._segments.length > 0) {
|
|
124
|
+
const seg = this._segments[0];
|
|
125
|
+
const take = Math.min(n - written, seg.length - this._offset);
|
|
126
|
+
out.set(seg.subarray(this._offset, this._offset + take), written);
|
|
127
|
+
written += take;
|
|
128
|
+
this._offset += take;
|
|
129
|
+
if (this._offset >= seg.length) {
|
|
130
|
+
this._segments.shift();
|
|
131
|
+
this._offset = 0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
this._available -= written;
|
|
135
|
+
if (written > 0)
|
|
136
|
+
this._last = out[written - 1];
|
|
137
|
+
if (written < n && mode === "hold") {
|
|
138
|
+
out.fill(this._last, written);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Zip-with-hold: consume one primary stream and any number of CV streams,
|
|
145
|
+
* yielding the primary chunks paired with frame-aligned CV values.
|
|
146
|
+
*
|
|
147
|
+
* Sample-exact when all streams share cadence (a patch driven by a single
|
|
148
|
+
* clock source); otherwise CV degrades to hold-last. Deadlock-free: the
|
|
149
|
+
* single `inputs.any()` loop only blocks while some upstream is open, and a
|
|
150
|
+
* primary chunk is released as soon as every connected CV handle can cover
|
|
151
|
+
* it (buffered, done, or the whole loop ended). Multichannel CV inputs are
|
|
152
|
+
* collapsed to channel 0.
|
|
153
|
+
*/
|
|
154
|
+
export async function* alignedSignalStreams(inputs, opts) {
|
|
155
|
+
const connected = opts.cvHandles.filter((h) => inputs.hasStream(h));
|
|
156
|
+
const fifos = new Map(connected.map((h) => [h, new SampleFifo()]));
|
|
157
|
+
const cvDone = new Map(connected.map((h) => [h, false]));
|
|
158
|
+
const pending = [];
|
|
159
|
+
let primaryDone = false;
|
|
160
|
+
const frameCount = (chunk) => Math.floor(chunk.samples.length / Math.max(1, chunk.channels));
|
|
161
|
+
const covered = (frames) => connected.every((h) => cvDone.get(h) || (fifos.get(h)?.available ?? 0) >= frames);
|
|
162
|
+
function* drain(force) {
|
|
163
|
+
while (pending.length > 0) {
|
|
164
|
+
const frames = frameCount(pending[0]);
|
|
165
|
+
if (!force && !covered(frames))
|
|
166
|
+
break;
|
|
167
|
+
const primary = pending.shift();
|
|
168
|
+
const cv = {};
|
|
169
|
+
for (const h of connected)
|
|
170
|
+
cv[h] = fifos.get(h).pull(frames, "hold");
|
|
171
|
+
yield { primary, cv };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for await (const [handle, item] of inputs.any()) {
|
|
175
|
+
const chunk = readSignalChunk(item);
|
|
176
|
+
if (!chunk)
|
|
177
|
+
continue;
|
|
178
|
+
if (handle === opts.primary) {
|
|
179
|
+
if (chunk.done)
|
|
180
|
+
primaryDone = true;
|
|
181
|
+
else if (chunk.samples.length > 0)
|
|
182
|
+
pending.push(chunk);
|
|
183
|
+
}
|
|
184
|
+
else if (fifos.has(handle)) {
|
|
185
|
+
if (chunk.done)
|
|
186
|
+
cvDone.set(handle, true);
|
|
187
|
+
else
|
|
188
|
+
fifos.get(handle).push(monoChannel(chunk));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
yield* drain(false);
|
|
194
|
+
if (primaryDone && pending.length === 0)
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
// The any() loop ended (EOS everywhere) — release whatever is left with
|
|
198
|
+
// hold-last CV.
|
|
199
|
+
yield* drain(true);
|
|
200
|
+
}
|
|
201
|
+
/** Channel 0 of an interleaved chunk (CV is conceptually mono). */
|
|
202
|
+
function monoChannel(chunk) {
|
|
203
|
+
const channels = Math.max(1, chunk.channels);
|
|
204
|
+
if (channels === 1)
|
|
205
|
+
return chunk.samples;
|
|
206
|
+
const frames = Math.floor(chunk.samples.length / channels);
|
|
207
|
+
const out = new Float32Array(frames);
|
|
208
|
+
for (let i = 0; i < frames; i++)
|
|
209
|
+
out[i] = chunk.samples[i * channels];
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
// ── Realtime pacing ────────────────────────────────────────────────
|
|
213
|
+
/** Sleep that resolves early (without throwing) when `signal` aborts. */
|
|
214
|
+
export function abortableSleep(ms, signal) {
|
|
215
|
+
return new Promise((resolve) => {
|
|
216
|
+
if (!signal) {
|
|
217
|
+
setTimeout(resolve, ms);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (signal.aborted) {
|
|
221
|
+
resolve();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const onAbort = () => {
|
|
225
|
+
clearTimeout(timer);
|
|
226
|
+
resolve();
|
|
227
|
+
};
|
|
228
|
+
const timer = setTimeout(() => {
|
|
229
|
+
signal.removeEventListener("abort", onAbort);
|
|
230
|
+
resolve();
|
|
231
|
+
}, ms);
|
|
232
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Drift-compensated wall-clock pacer for free-running generators: chunk k
|
|
237
|
+
* is released no earlier than the cumulative duration of chunks 0..k-1
|
|
238
|
+
* after start (absolute target times, same scheme as IntervalTriggerNode).
|
|
239
|
+
* Pacing never alters chunk contents — a paced render is bit-identical to
|
|
240
|
+
* an unpaced one.
|
|
241
|
+
*/
|
|
242
|
+
export class RealtimePacer {
|
|
243
|
+
_signal;
|
|
244
|
+
_nextTargetMs = Date.now();
|
|
245
|
+
constructor(_signal) {
|
|
246
|
+
this._signal = _signal;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Wait for the chunk's emission slot, then advance the next slot by
|
|
250
|
+
* `chunkMs` (this chunk's duration). Returns false when the run was
|
|
251
|
+
* cancelled — the caller must stop producing.
|
|
252
|
+
*/
|
|
253
|
+
async waitNext(chunkMs) {
|
|
254
|
+
const waitMs = this._nextTargetMs - Date.now();
|
|
255
|
+
this._nextTargetMs += chunkMs;
|
|
256
|
+
if (waitMs > 0)
|
|
257
|
+
await abortableSleep(waitMs, this._signal);
|
|
258
|
+
return !(this._signal?.aborted ?? false);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=cv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/lib/cv.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAI/B,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AACvC,oDAAoD;AACpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,iFAAiF;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,OAAO;IACrB,OAAO,EAAE,EAAE;IACX,gBAAgB,EAAE,EAAE;IACpB,IAAI,EAAE,KAAK;IACX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AG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEnC,YAA6B,OAAqB;uBAArB,OAAO;IAAiB,CAAC;IAEtD;;;;OAIG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/C,IAAI,CAAC,aAAa,IAAI,OAAO,CAAC;QAC9B,IAAI,MAAM,GAAG,CAAC;YAAE,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3D,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure DSP cores for the modular synthesis nodes — oscillator waveforms and
|
|
3
|
+
* the ADSR envelope state machine. No streaming, no I/O: everything here is
|
|
4
|
+
* a per-sample function over plain numbers, unit-testable in isolation.
|
|
5
|
+
*/
|
|
6
|
+
export type Waveform = "sine" | "saw" | "square" | "triangle" | "noise";
|
|
7
|
+
/**
|
|
8
|
+
* One oscillator sample for `phase` ∈ [0, 1). Naive (non-bandlimited)
|
|
9
|
+
* waveforms — saw/square alias above a few kHz; polyBLEP is a follow-up.
|
|
10
|
+
*/
|
|
11
|
+
export declare function oscSample(wave: Waveform, phase: number, pulseWidth?: number): number;
|
|
12
|
+
export type AdsrStage = "idle" | "attack" | "decay" | "sustain" | "release";
|
|
13
|
+
/**
|
|
14
|
+
* Per-sample one-pole coefficients. Exponential segments (vs linear) cost
|
|
15
|
+
* the same per sample, give click-free analog-style curves, and make
|
|
16
|
+
* retrigger-from-current-level automatic — the pole just pulls the env
|
|
17
|
+
* from wherever it is toward the new target.
|
|
18
|
+
*/
|
|
19
|
+
export interface AdsrParams {
|
|
20
|
+
attackCoeff: number;
|
|
21
|
+
decayCoeff: number;
|
|
22
|
+
releaseCoeff: number;
|
|
23
|
+
sustain: number;
|
|
24
|
+
}
|
|
25
|
+
export interface AdsrState {
|
|
26
|
+
stage: AdsrStage;
|
|
27
|
+
env: number;
|
|
28
|
+
/** Previous sample's gate level (for edge detection). */
|
|
29
|
+
gateWasHigh: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Gate threshold: a CV sample ≥ 0.5 counts as gate-high. */
|
|
32
|
+
export declare const GATE_THRESHOLD = 0.5;
|
|
33
|
+
/** One-pole coefficient for a segment of `seconds` at `sampleRate`. */
|
|
34
|
+
export declare function adsrCoeff(seconds: number, sampleRate: number): number;
|
|
35
|
+
export declare function createAdsrState(): AdsrState;
|
|
36
|
+
/**
|
|
37
|
+
* Advance the envelope by one sample given the current gate level. Mutates
|
|
38
|
+
* `state`; returns the new envelope value. Gate edges (rising → attack
|
|
39
|
+
* retrigger from the current level, falling → release) are detected here,
|
|
40
|
+
* so calling this per sample inside a chunk gives sample-accurate timing.
|
|
41
|
+
*/
|
|
42
|
+
export declare function adsrStep(state: AdsrState, gateHigh: boolean, params: AdsrParams): number;
|
|
43
|
+
//# sourceMappingURL=synth-dsp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synth-dsp.d.ts","sourceRoot":"","sources":["../../src/lib/synth-dsp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAExE;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,UAAU,SAAM,GACf,MAAM,CAaR;AAID,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,yDAAyD;IACzD,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,6DAA6D;AAC7D,eAAO,MAAM,cAAc,MAAM,CAAC;AAQlC,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,UAAU,GACjB,MAAM,CA2CR"}
|