@nodetool-ai/audio-nodes 0.8.9 → 0.8.14
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 +2 -0
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/audio-context.js +1 -1
- package/dist/lib/audio-wav.d.ts.map +1 -1
- package/dist/lib/audio-wav.js +62 -37
- package/dist/lib/audio-wav.js.map +1 -1
- package/dist/lib/biquad.d.ts +3 -44
- package/dist/lib/biquad.d.ts.map +1 -1
- package/dist/lib/biquad.js +3 -123
- package/dist/lib/biquad.js.map +1 -1
- package/dist/lib/cv.d.ts +7 -25
- package/dist/lib/cv.d.ts.map +1 -1
- package/dist/lib/cv.js +18 -34
- package/dist/lib/cv.js.map +1 -1
- package/dist/lib/effect-descriptors.d.ts +17 -0
- package/dist/lib/effect-descriptors.d.ts.map +1 -0
- package/dist/lib/effect-descriptors.js +107 -0
- package/dist/lib/effect-descriptors.js.map +1 -0
- package/dist/lib/effect-properties.d.ts +66 -0
- package/dist/lib/effect-properties.d.ts.map +1 -0
- package/dist/lib/effect-properties.js +392 -0
- package/dist/lib/effect-properties.js.map +1 -0
- package/dist/lib/signal-effect.d.ts +14 -0
- package/dist/lib/signal-effect.d.ts.map +1 -0
- package/dist/lib/signal-effect.js +63 -0
- package/dist/lib/signal-effect.js.map +1 -0
- package/dist/lib/transport.d.ts +15 -0
- package/dist/lib/transport.d.ts.map +1 -0
- package/dist/lib/transport.js +53 -0
- package/dist/lib/transport.js.map +1 -0
- package/dist/nodes/audio.d.ts.map +1 -1
- package/dist/nodes/audio.js +4 -2
- package/dist/nodes/audio.js.map +1 -1
- package/dist/nodes/lib-audio-dsp.d.ts +35 -62
- package/dist/nodes/lib-audio-dsp.d.ts.map +1 -1
- package/dist/nodes/lib-audio-dsp.js +31 -279
- package/dist/nodes/lib-audio-dsp.js.map +1 -1
- package/dist/nodes/lib-audio-effects.d.ts +29 -66
- package/dist/nodes/lib-audio-effects.d.ts.map +1 -1
- package/dist/nodes/lib-audio-effects.js +24 -517
- package/dist/nodes/lib-audio-effects.js.map +1 -1
- package/dist/nodes/realtime-audio.d.ts +14 -12
- package/dist/nodes/realtime-audio.d.ts.map +1 -1
- package/dist/nodes/realtime-audio.js +117 -116
- package/dist/nodes/realtime-audio.js.map +1 -1
- package/dist/nodes/sampler.d.ts +44 -0
- package/dist/nodes/sampler.d.ts.map +1 -0
- package/dist/nodes/sampler.js +243 -0
- package/dist/nodes/sampler.js.map +1 -0
- package/dist/nodes/signal-effects.d.ts +170 -0
- package/dist/nodes/signal-effects.d.ts.map +1 -0
- package/dist/nodes/signal-effects.js +309 -0
- package/dist/nodes/signal-effects.js.map +1 -0
- package/dist/nodes/synthesis.d.ts +34 -18
- package/dist/nodes/synthesis.d.ts.map +1 -1
- package/dist/nodes/synthesis.js +183 -218
- package/dist/nodes/synthesis.js.map +1 -1
- package/package.json +7 -6
- package/dist/lib/synth-dsp.d.ts +0 -43
- package/dist/lib/synth-dsp.d.ts.map +0 -1
- package/dist/lib/synth-dsp.js +0 -88
- package/dist/lib/synth-dsp.js.map +0 -1
|
@@ -4,32 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import { BitcrushProperties, CompressProperties, DistortionProperties, LimiterProperties, ReverbProperties, NoiseGateProperties, PhaserProperties } from "../lib/effect-properties.js";
|
|
8
|
+
import { BitcrushEffect, CompressEffect, DistortionEffect, LimiterEffect, ReverbEffect, NoiseGateEffect, PhaserEffect } from "../lib/effect-descriptors.js";
|
|
9
|
+
import { applyToClip } from "../lib/signal-effect.js";
|
|
7
10
|
import { BaseNode, prop } from "@nodetool-ai/node-sdk";
|
|
8
11
|
import { tagAsServer } from "@nodetool-ai/nodes-utils";
|
|
9
12
|
import { importHidden } from "@nodetool-ai/config";
|
|
10
13
|
import { requireAudioBytes, audioRefFromWav, decodeAudioToWav, encodeWav } from "../lib/audio-wav.js";
|
|
11
|
-
// ──
|
|
12
|
-
|
|
13
|
-
const { samples, sampleRate, numChannels } = wav;
|
|
14
|
-
const frameSamples = Math.floor(samples.length / numChannels);
|
|
15
|
-
const channels = [];
|
|
16
|
-
for (let ch = 0; ch < numChannels; ch++) {
|
|
17
|
-
const channelData = new Float32Array(frameSamples);
|
|
18
|
-
for (let i = 0; i < frameSamples; i++) {
|
|
19
|
-
channelData[i] = samples[i * numChannels + ch];
|
|
20
|
-
}
|
|
21
|
-
channels.push(fn(channelData, sampleRate));
|
|
22
|
-
}
|
|
23
|
-
const outFrames = channels[0].length;
|
|
24
|
-
const outSamples = new Float32Array(outFrames * numChannels);
|
|
25
|
-
for (let ch = 0; ch < numChannels; ch++) {
|
|
26
|
-
for (let i = 0; i < outFrames; i++) {
|
|
27
|
-
outSamples[i * numChannels + ch] = channels[ch][i];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return { samples: outSamples, sampleRate, numChannels };
|
|
31
|
-
}
|
|
32
|
-
export class BitcrushNode extends BaseNode {
|
|
14
|
+
// ── Bitcrush ──────────────────────────────────────────────────────
|
|
15
|
+
export class BitcrushNode extends BitcrushProperties {
|
|
33
16
|
static nodeType = "lib.audio.Bitcrush";
|
|
34
17
|
static title = "Bitcrush";
|
|
35
18
|
static description = "Applies a bitcrushing effect to an audio file, reducing bit depth and/or sample rate.\n audio, effect, distortion\n\n Use cases:\n - Create lo-fi or retro-style audio effects\n - Simulate vintage digital audio equipment\n - Add digital distortion and artifacts to sounds";
|
|
@@ -39,27 +22,7 @@ export class BitcrushNode extends BaseNode {
|
|
|
39
22
|
static inlineFields = [];
|
|
40
23
|
static inputFields = ["audio"];
|
|
41
24
|
async process(context) {
|
|
42
|
-
|
|
43
|
-
const bitDepth = this.bit_depth;
|
|
44
|
-
const srrFactor = this.sample_rate_reduction;
|
|
45
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
46
|
-
const wav = await decodeAudioToWav(bytes);
|
|
47
|
-
const result = processPerChannel(wav, (ch) => {
|
|
48
|
-
// Number of quantization steps for the target bit depth. Guard against
|
|
49
|
-
// bitDepth === 1 (the prop minimum), which would otherwise yield 0 and
|
|
50
|
-
// produce NaN samples via division by zero.
|
|
51
|
-
const levels = Math.max(1, Math.pow(2, bitDepth) - 1);
|
|
52
|
-
const out = new Float32Array(ch.length);
|
|
53
|
-
for (let i = 0; i < ch.length; i++) {
|
|
54
|
-
const idx = Math.floor(i / srrFactor) * srrFactor;
|
|
55
|
-
const srcIdx = Math.min(idx, ch.length - 1);
|
|
56
|
-
out[i] = Math.round(ch[srcIdx] * levels) / levels;
|
|
57
|
-
}
|
|
58
|
-
return out;
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
62
|
-
};
|
|
25
|
+
return { output: await applyToClip(BitcrushEffect, this, this.audio, context) };
|
|
63
26
|
}
|
|
64
27
|
}
|
|
65
28
|
__decorate([
|
|
@@ -76,27 +39,8 @@ __decorate([
|
|
|
76
39
|
description: "The audio file to process."
|
|
77
40
|
})
|
|
78
41
|
], BitcrushNode.prototype, "audio", void 0);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
type: "int",
|
|
82
|
-
default: 8,
|
|
83
|
-
title: "Bit Depth",
|
|
84
|
-
description: "The bit depth to reduce the audio to. Lower values create more distortion.",
|
|
85
|
-
min: 1,
|
|
86
|
-
max: 16
|
|
87
|
-
})
|
|
88
|
-
], BitcrushNode.prototype, "bit_depth", void 0);
|
|
89
|
-
__decorate([
|
|
90
|
-
prop({
|
|
91
|
-
type: "int",
|
|
92
|
-
default: 1,
|
|
93
|
-
title: "Sample Rate Reduction",
|
|
94
|
-
description: "Factor by which to reduce the sample rate. Higher values create more aliasing.",
|
|
95
|
-
min: 1,
|
|
96
|
-
max: 100
|
|
97
|
-
})
|
|
98
|
-
], BitcrushNode.prototype, "sample_rate_reduction", void 0);
|
|
99
|
-
export class CompressNode extends BaseNode {
|
|
42
|
+
// ── Compress ──────────────────────────────────────────────────────
|
|
43
|
+
export class CompressNode extends CompressProperties {
|
|
100
44
|
static nodeType = "lib.audio.Compress";
|
|
101
45
|
static title = "Compress";
|
|
102
46
|
static description = "Applies dynamic range compression to an audio file.\n audio, effect, dynamics\n\n Use cases:\n - Even out volume levels in a recording\n - Increase perceived loudness of audio\n - Control peaks in audio signals";
|
|
@@ -106,49 +50,7 @@ export class CompressNode extends BaseNode {
|
|
|
106
50
|
static inlineFields = [];
|
|
107
51
|
static inputFields = ["audio"];
|
|
108
52
|
async process(context) {
|
|
109
|
-
|
|
110
|
-
const thresholdDb = this.threshold;
|
|
111
|
-
const ratio = this.ratio;
|
|
112
|
-
const attackMs = this.attack;
|
|
113
|
-
const releaseMs = this.release;
|
|
114
|
-
const autoGain = this.auto_gain;
|
|
115
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
116
|
-
// Makeup gain: half of the reduction a 0 dBFS peak would receive — the
|
|
117
|
-
// usual "auto" heuristic. It restores most of the loudness lost to
|
|
118
|
-
// compression while staying clear of clipping the way full compensation
|
|
119
|
-
// (referenced to 0 dBFS) would on under-compressed transients.
|
|
120
|
-
const makeupDb = autoGain ? (-thresholdDb * (1 - 1 / ratio)) / 2 : 0;
|
|
121
|
-
const makeup = Math.pow(10, makeupDb / 20);
|
|
122
|
-
const wav = await decodeAudioToWav(bytes);
|
|
123
|
-
const result = processPerChannel(wav, (ch, sr) => {
|
|
124
|
-
const out = new Float32Array(ch.length);
|
|
125
|
-
const attackCoeff = Math.exp(-1 / ((sr * attackMs) / 1000));
|
|
126
|
-
const releaseCoeff = Math.exp(-1 / ((sr * releaseMs) / 1000));
|
|
127
|
-
const thresholdLin = Math.pow(10, thresholdDb / 20);
|
|
128
|
-
let envelope = 0;
|
|
129
|
-
for (let i = 0; i < ch.length; i++) {
|
|
130
|
-
const absVal = Math.abs(ch[i]);
|
|
131
|
-
if (absVal > envelope) {
|
|
132
|
-
envelope = attackCoeff * envelope + (1 - attackCoeff) * absVal;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
envelope = releaseCoeff * envelope + (1 - releaseCoeff) * absVal;
|
|
136
|
-
}
|
|
137
|
-
if (envelope > thresholdLin) {
|
|
138
|
-
const dbOver = 20 * Math.log10(envelope / thresholdLin);
|
|
139
|
-
const dbReduction = dbOver * (1 - 1 / ratio);
|
|
140
|
-
const gainReduction = Math.pow(10, -dbReduction / 20);
|
|
141
|
-
out[i] = ch[i] * gainReduction * makeup;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
out[i] = ch[i] * makeup;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return out;
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
151
|
-
};
|
|
53
|
+
return { output: await applyToClip(CompressEffect, this, this.audio, context) };
|
|
152
54
|
}
|
|
153
55
|
}
|
|
154
56
|
__decorate([
|
|
@@ -165,55 +67,8 @@ __decorate([
|
|
|
165
67
|
description: "The audio file to process."
|
|
166
68
|
})
|
|
167
69
|
], CompressNode.prototype, "audio", void 0);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
type: "float",
|
|
171
|
-
default: -20,
|
|
172
|
-
title: "Threshold",
|
|
173
|
-
description: "Threshold in dB above which compression is applied.",
|
|
174
|
-
min: -60,
|
|
175
|
-
max: 0
|
|
176
|
-
})
|
|
177
|
-
], CompressNode.prototype, "threshold", void 0);
|
|
178
|
-
__decorate([
|
|
179
|
-
prop({
|
|
180
|
-
type: "float",
|
|
181
|
-
default: 4,
|
|
182
|
-
title: "Ratio",
|
|
183
|
-
description: "Compression ratio. Higher values result in more compression.",
|
|
184
|
-
min: 1,
|
|
185
|
-
max: 20
|
|
186
|
-
})
|
|
187
|
-
], CompressNode.prototype, "ratio", void 0);
|
|
188
|
-
__decorate([
|
|
189
|
-
prop({
|
|
190
|
-
type: "float",
|
|
191
|
-
default: 5,
|
|
192
|
-
title: "Attack",
|
|
193
|
-
description: "Attack time in milliseconds.",
|
|
194
|
-
min: 0.1,
|
|
195
|
-
max: 100
|
|
196
|
-
})
|
|
197
|
-
], CompressNode.prototype, "attack", void 0);
|
|
198
|
-
__decorate([
|
|
199
|
-
prop({
|
|
200
|
-
type: "float",
|
|
201
|
-
default: 50,
|
|
202
|
-
title: "Release",
|
|
203
|
-
description: "Release time in milliseconds.",
|
|
204
|
-
min: 5,
|
|
205
|
-
max: 1000
|
|
206
|
-
})
|
|
207
|
-
], CompressNode.prototype, "release", void 0);
|
|
208
|
-
__decorate([
|
|
209
|
-
prop({
|
|
210
|
-
type: "bool",
|
|
211
|
-
default: true,
|
|
212
|
-
title: "Auto Gain",
|
|
213
|
-
description: "Apply automatic makeup gain to compensate for the level lost to compression, keeping the output roughly as loud as the input."
|
|
214
|
-
})
|
|
215
|
-
], CompressNode.prototype, "auto_gain", void 0);
|
|
216
|
-
export class DistortionNode extends BaseNode {
|
|
70
|
+
// ── Distortion ────────────────────────────────────────────────────
|
|
71
|
+
export class DistortionNode extends DistortionProperties {
|
|
217
72
|
static nodeType = "lib.audio.Distortion";
|
|
218
73
|
static title = "Distortion";
|
|
219
74
|
static description = "Applies a distortion effect to an audio file.\n audio, effect, distortion\n\n Use cases:\n - Add grit and character to instruments\n - Create aggressive sound effects\n - Simulate overdriven amplifiers";
|
|
@@ -223,22 +78,7 @@ export class DistortionNode extends BaseNode {
|
|
|
223
78
|
static inlineFields = [];
|
|
224
79
|
static inputFields = ["audio"];
|
|
225
80
|
async process(context) {
|
|
226
|
-
|
|
227
|
-
const driveDb = this.drive_db;
|
|
228
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
229
|
-
const wav = await decodeAudioToWav(bytes);
|
|
230
|
-
const drive = Math.pow(10, driveDb / 20);
|
|
231
|
-
const result = processPerChannel(wav, (ch) => {
|
|
232
|
-
const out = new Float32Array(ch.length);
|
|
233
|
-
for (let i = 0; i < ch.length; i++) {
|
|
234
|
-
const driven = ch[i] * drive;
|
|
235
|
-
out[i] = (2 / Math.PI) * Math.atan(driven);
|
|
236
|
-
}
|
|
237
|
-
return out;
|
|
238
|
-
});
|
|
239
|
-
return {
|
|
240
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
241
|
-
};
|
|
81
|
+
return { output: await applyToClip(DistortionEffect, this, this.audio, context) };
|
|
242
82
|
}
|
|
243
83
|
}
|
|
244
84
|
__decorate([
|
|
@@ -255,17 +95,8 @@ __decorate([
|
|
|
255
95
|
description: "The audio file to process."
|
|
256
96
|
})
|
|
257
97
|
], DistortionNode.prototype, "audio", void 0);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
type: "float",
|
|
261
|
-
default: 25,
|
|
262
|
-
title: "Drive Db",
|
|
263
|
-
description: "Amount of distortion to apply in decibels.",
|
|
264
|
-
min: 0,
|
|
265
|
-
max: 100
|
|
266
|
-
})
|
|
267
|
-
], DistortionNode.prototype, "drive_db", void 0);
|
|
268
|
-
export class LimiterNode extends BaseNode {
|
|
98
|
+
// ── Limiter ───────────────────────────────────────────────────────
|
|
99
|
+
export class LimiterNode extends LimiterProperties {
|
|
269
100
|
static nodeType = "lib.audio.Limiter";
|
|
270
101
|
static title = "Limiter";
|
|
271
102
|
static description = "Applies a limiter effect to an audio file.\n audio, effect, dynamics\n\n Use cases:\n - Prevent audio clipping\n - Increase perceived loudness without distortion\n - Control dynamic range of audio";
|
|
@@ -275,40 +106,7 @@ export class LimiterNode extends BaseNode {
|
|
|
275
106
|
static inlineFields = [];
|
|
276
107
|
static inputFields = ["audio"];
|
|
277
108
|
async process(context) {
|
|
278
|
-
|
|
279
|
-
const thresholdDb = this.threshold_db;
|
|
280
|
-
const releaseMs = this.release_ms;
|
|
281
|
-
const autoGain = this.auto_gain;
|
|
282
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
283
|
-
const wav = await decodeAudioToWav(bytes);
|
|
284
|
-
const threshold = Math.pow(10, thresholdDb / 20);
|
|
285
|
-
// Makeup gain brings the ceiling up to 0 dBFS. Limited peaks sit at
|
|
286
|
-
// `threshold`, so scaling by 1/threshold normalizes them to full scale
|
|
287
|
-
// without pushing past it.
|
|
288
|
-
const makeup = autoGain ? 1 / threshold : 1;
|
|
289
|
-
const result = processPerChannel(wav, (ch, sr) => {
|
|
290
|
-
const out = new Float32Array(ch.length);
|
|
291
|
-
const releaseCoeff = Math.exp(-1 / ((sr * releaseMs) / 1000));
|
|
292
|
-
let gainReduction = 1;
|
|
293
|
-
for (let i = 0; i < ch.length; i++) {
|
|
294
|
-
const absVal = Math.abs(ch[i]);
|
|
295
|
-
if (absVal > threshold) {
|
|
296
|
-
const targetGain = threshold / absVal;
|
|
297
|
-
if (targetGain < gainReduction) {
|
|
298
|
-
gainReduction = targetGain;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
gainReduction =
|
|
303
|
-
releaseCoeff * gainReduction + (1 - releaseCoeff) * 1.0;
|
|
304
|
-
}
|
|
305
|
-
out[i] = ch[i] * gainReduction * makeup;
|
|
306
|
-
}
|
|
307
|
-
return out;
|
|
308
|
-
});
|
|
309
|
-
return {
|
|
310
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
311
|
-
};
|
|
109
|
+
return { output: await applyToClip(LimiterEffect, this, this.audio, context) };
|
|
312
110
|
}
|
|
313
111
|
}
|
|
314
112
|
__decorate([
|
|
@@ -325,35 +123,8 @@ __decorate([
|
|
|
325
123
|
description: "The audio file to process."
|
|
326
124
|
})
|
|
327
125
|
], LimiterNode.prototype, "audio", void 0);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
type: "float",
|
|
331
|
-
default: -2,
|
|
332
|
-
title: "Threshold Db",
|
|
333
|
-
description: "Threshold in dB above which the limiter is applied.",
|
|
334
|
-
min: -60,
|
|
335
|
-
max: 0
|
|
336
|
-
})
|
|
337
|
-
], LimiterNode.prototype, "threshold_db", void 0);
|
|
338
|
-
__decorate([
|
|
339
|
-
prop({
|
|
340
|
-
type: "float",
|
|
341
|
-
default: 250,
|
|
342
|
-
title: "Release Ms",
|
|
343
|
-
description: "Release time in milliseconds.",
|
|
344
|
-
min: 1,
|
|
345
|
-
max: 1000
|
|
346
|
-
})
|
|
347
|
-
], LimiterNode.prototype, "release_ms", void 0);
|
|
348
|
-
__decorate([
|
|
349
|
-
prop({
|
|
350
|
-
type: "bool",
|
|
351
|
-
default: true,
|
|
352
|
-
title: "Auto Gain",
|
|
353
|
-
description: "Apply automatic makeup gain so the limited peaks reach 0 dBFS, turning the headroom below the ceiling into added loudness (maximizer behaviour)."
|
|
354
|
-
})
|
|
355
|
-
], LimiterNode.prototype, "auto_gain", void 0);
|
|
356
|
-
export class ReverbNode extends BaseNode {
|
|
126
|
+
// ── Reverb (Schroeder) ───────────────────────────────────────────
|
|
127
|
+
export class ReverbNode extends ReverbProperties {
|
|
357
128
|
static nodeType = "lib.audio.Reverb";
|
|
358
129
|
static title = "Reverb";
|
|
359
130
|
static description = "Applies a reverb effect to an audio file.\n audio, effect, reverb\n\n Use cases:\n - Add spatial depth to dry recordings\n - Simulate different room acoustics\n - Create atmospheric sound effects";
|
|
@@ -363,72 +134,7 @@ export class ReverbNode extends BaseNode {
|
|
|
363
134
|
static inlineFields = [];
|
|
364
135
|
static inputFields = ["audio"];
|
|
365
136
|
async process(context) {
|
|
366
|
-
|
|
367
|
-
const roomScale = this.room_scale;
|
|
368
|
-
const damping = this.damping;
|
|
369
|
-
const wetLevel = this.wet_level;
|
|
370
|
-
const dryLevel = this.dry_level;
|
|
371
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
372
|
-
const wav = await decodeAudioToWav(bytes);
|
|
373
|
-
const result = processPerChannel(wav, (ch, sr) => {
|
|
374
|
-
// Schroeder reverb: 4 parallel comb filters -> 2 series allpass filters
|
|
375
|
-
const baseCombDelays = [1557, 1617, 1491, 1422];
|
|
376
|
-
const baseAllpassDelays = [225, 556];
|
|
377
|
-
const scale = sr / 44100;
|
|
378
|
-
// Comb filter
|
|
379
|
-
function combFilter(input, delaySamples, feedback, damp) {
|
|
380
|
-
const out = new Float32Array(input.length);
|
|
381
|
-
const buf = new Float32Array(delaySamples);
|
|
382
|
-
let bufIdx = 0;
|
|
383
|
-
let filterStore = 0;
|
|
384
|
-
for (let i = 0; i < input.length; i++) {
|
|
385
|
-
const delayed = buf[bufIdx];
|
|
386
|
-
filterStore = delayed * (1 - damp) + filterStore * damp;
|
|
387
|
-
buf[bufIdx] = input[i] + filterStore * feedback;
|
|
388
|
-
out[i] = delayed;
|
|
389
|
-
bufIdx = (bufIdx + 1) % delaySamples;
|
|
390
|
-
}
|
|
391
|
-
return out;
|
|
392
|
-
}
|
|
393
|
-
// Allpass filter
|
|
394
|
-
function allpassFilter(input, delaySamples, feedback) {
|
|
395
|
-
const out = new Float32Array(input.length);
|
|
396
|
-
const buf = new Float32Array(delaySamples);
|
|
397
|
-
let bufIdx = 0;
|
|
398
|
-
for (let i = 0; i < input.length; i++) {
|
|
399
|
-
const delayed = buf[bufIdx];
|
|
400
|
-
buf[bufIdx] = input[i] + delayed * feedback;
|
|
401
|
-
out[i] = delayed - input[i] * feedback;
|
|
402
|
-
bufIdx = (bufIdx + 1) % delaySamples;
|
|
403
|
-
}
|
|
404
|
-
return out;
|
|
405
|
-
}
|
|
406
|
-
const feedback = roomScale * 0.28 + 0.7;
|
|
407
|
-
// Sum comb filters
|
|
408
|
-
const combOut = new Float32Array(ch.length);
|
|
409
|
-
for (const baseDelay of baseCombDelays) {
|
|
410
|
-
const delay = Math.round(baseDelay * scale);
|
|
411
|
-
const filtered = combFilter(ch, delay, feedback, damping);
|
|
412
|
-
for (let i = 0; i < ch.length; i++) {
|
|
413
|
-
combOut[i] += filtered[i];
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
// Series allpass filters
|
|
417
|
-
let apOut = combOut;
|
|
418
|
-
for (const baseDelay of baseAllpassDelays) {
|
|
419
|
-
const delay = Math.round(baseDelay * scale);
|
|
420
|
-
apOut = allpassFilter(apOut, delay, 0.5);
|
|
421
|
-
}
|
|
422
|
-
// Mix dry/wet
|
|
423
|
-
const out = new Float32Array(ch.length);
|
|
424
|
-
for (let i = 0; i < ch.length; i++) {
|
|
425
|
-
out[i] = ch[i] * dryLevel + apOut[i] * wetLevel;
|
|
426
|
-
}
|
|
427
|
-
return out;
|
|
428
|
-
});
|
|
429
|
-
return {
|
|
430
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
431
|
-
};
|
|
137
|
+
return { output: await applyToClip(ReverbEffect, this, this.audio, context) };
|
|
432
138
|
}
|
|
433
139
|
}
|
|
434
140
|
__decorate([
|
|
@@ -445,46 +151,6 @@ __decorate([
|
|
|
445
151
|
description: "The audio file to process."
|
|
446
152
|
})
|
|
447
153
|
], ReverbNode.prototype, "audio", void 0);
|
|
448
|
-
__decorate([
|
|
449
|
-
prop({
|
|
450
|
-
type: "float",
|
|
451
|
-
default: 0.5,
|
|
452
|
-
title: "Room Scale",
|
|
453
|
-
description: "Size of the simulated room. Higher values create larger spaces.",
|
|
454
|
-
min: 0,
|
|
455
|
-
max: 1
|
|
456
|
-
})
|
|
457
|
-
], ReverbNode.prototype, "room_scale", void 0);
|
|
458
|
-
__decorate([
|
|
459
|
-
prop({
|
|
460
|
-
type: "float",
|
|
461
|
-
default: 0.5,
|
|
462
|
-
title: "Damping",
|
|
463
|
-
description: "Amount of high frequency absorption. Higher values create a duller sound.",
|
|
464
|
-
min: 0,
|
|
465
|
-
max: 1
|
|
466
|
-
})
|
|
467
|
-
], ReverbNode.prototype, "damping", void 0);
|
|
468
|
-
__decorate([
|
|
469
|
-
prop({
|
|
470
|
-
type: "float",
|
|
471
|
-
default: 0.15,
|
|
472
|
-
title: "Wet Level",
|
|
473
|
-
description: "Level of the reverb effect in the output.",
|
|
474
|
-
min: 0,
|
|
475
|
-
max: 1
|
|
476
|
-
})
|
|
477
|
-
], ReverbNode.prototype, "wet_level", void 0);
|
|
478
|
-
__decorate([
|
|
479
|
-
prop({
|
|
480
|
-
type: "float",
|
|
481
|
-
default: 0.5,
|
|
482
|
-
title: "Dry Level",
|
|
483
|
-
description: "Level of the original signal in the output.",
|
|
484
|
-
min: 0,
|
|
485
|
-
max: 1
|
|
486
|
-
})
|
|
487
|
-
], ReverbNode.prototype, "dry_level", void 0);
|
|
488
154
|
/**
|
|
489
155
|
* Lazily load rubberband via a bundler-hidden import. The hidden import keeps
|
|
490
156
|
* the native/WASM package out of the web bundle (this file is loaded in the
|
|
@@ -725,7 +391,8 @@ __decorate([
|
|
|
725
391
|
max: 2
|
|
726
392
|
})
|
|
727
393
|
], TimeStretchNode.prototype, "rate", void 0);
|
|
728
|
-
|
|
394
|
+
// ── NoiseGate ─────────────────────────────────────────────────────
|
|
395
|
+
export class NoiseGateNode extends NoiseGateProperties {
|
|
729
396
|
static nodeType = "lib.audio.NoiseGate";
|
|
730
397
|
static title = "Noise Gate";
|
|
731
398
|
static description = "Applies a noise gate effect to an audio file.\n audio, effect, dynamics\n\n Use cases:\n - Reduce background noise in recordings\n - Clean up audio tracks with unwanted low-level sounds\n - Create rhythmic effects by gating sustained sounds";
|
|
@@ -735,41 +402,7 @@ export class NoiseGateNode extends BaseNode {
|
|
|
735
402
|
static inlineFields = [];
|
|
736
403
|
static inputFields = ["audio"];
|
|
737
404
|
async process(context) {
|
|
738
|
-
|
|
739
|
-
const thresholdDb = this.threshold_db;
|
|
740
|
-
const attackMs = Math.max(0.1, this.attack_ms);
|
|
741
|
-
const releaseMs = Math.max(1, this.release_ms);
|
|
742
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
743
|
-
const wav = await decodeAudioToWav(bytes);
|
|
744
|
-
const thresholdLin = Math.pow(10, thresholdDb / 20);
|
|
745
|
-
const result = processPerChannel(wav, (ch, sr) => {
|
|
746
|
-
const out = new Float32Array(ch.length);
|
|
747
|
-
const attackCoeff = Math.exp(-1 / ((sr * attackMs) / 1000));
|
|
748
|
-
const releaseCoeff = Math.exp(-1 / ((sr * releaseMs) / 1000));
|
|
749
|
-
let envelope = 0;
|
|
750
|
-
let gain = 0;
|
|
751
|
-
for (let i = 0; i < ch.length; i++) {
|
|
752
|
-
const absVal = Math.abs(ch[i]);
|
|
753
|
-
// Envelope follower: fast attack, slow release
|
|
754
|
-
if (absVal > envelope) {
|
|
755
|
-
envelope = attackCoeff * envelope + (1 - attackCoeff) * absVal;
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
758
|
-
envelope = releaseCoeff * envelope + (1 - releaseCoeff) * absVal;
|
|
759
|
-
}
|
|
760
|
-
// Gate: open when above threshold, close when below. Smooth the gain
|
|
761
|
-
// toward the target using the attack coefficient while opening and the
|
|
762
|
-
// release coefficient while closing, so both controls take effect.
|
|
763
|
-
const targetGain = envelope >= thresholdLin ? 1 : 0;
|
|
764
|
-
const coeff = targetGain > gain ? attackCoeff : releaseCoeff;
|
|
765
|
-
gain = coeff * gain + (1 - coeff) * targetGain;
|
|
766
|
-
out[i] = ch[i] * gain;
|
|
767
|
-
}
|
|
768
|
-
return out;
|
|
769
|
-
});
|
|
770
|
-
return {
|
|
771
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
772
|
-
};
|
|
405
|
+
return { output: await applyToClip(NoiseGateEffect, this, this.audio, context) };
|
|
773
406
|
}
|
|
774
407
|
}
|
|
775
408
|
__decorate([
|
|
@@ -786,37 +419,8 @@ __decorate([
|
|
|
786
419
|
description: "The audio file to process."
|
|
787
420
|
})
|
|
788
421
|
], NoiseGateNode.prototype, "audio", void 0);
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
type: "float",
|
|
792
|
-
default: -50,
|
|
793
|
-
title: "Threshold Db",
|
|
794
|
-
description: "Threshold in dB below which the gate is active.",
|
|
795
|
-
min: -90,
|
|
796
|
-
max: 0
|
|
797
|
-
})
|
|
798
|
-
], NoiseGateNode.prototype, "threshold_db", void 0);
|
|
799
|
-
__decorate([
|
|
800
|
-
prop({
|
|
801
|
-
type: "float",
|
|
802
|
-
default: 1,
|
|
803
|
-
title: "Attack Ms",
|
|
804
|
-
description: "Attack time in milliseconds.",
|
|
805
|
-
min: 0.1,
|
|
806
|
-
max: 100
|
|
807
|
-
})
|
|
808
|
-
], NoiseGateNode.prototype, "attack_ms", void 0);
|
|
809
|
-
__decorate([
|
|
810
|
-
prop({
|
|
811
|
-
type: "float",
|
|
812
|
-
default: 100,
|
|
813
|
-
title: "Release Ms",
|
|
814
|
-
description: "Release time in milliseconds.",
|
|
815
|
-
min: 5,
|
|
816
|
-
max: 1000
|
|
817
|
-
})
|
|
818
|
-
], NoiseGateNode.prototype, "release_ms", void 0);
|
|
819
|
-
export class PhaserNode extends BaseNode {
|
|
422
|
+
// ── Phaser ────────────────────────────────────────────────────────
|
|
423
|
+
export class PhaserNode extends PhaserProperties {
|
|
820
424
|
static nodeType = "lib.audio.Phaser";
|
|
821
425
|
static title = "Phaser";
|
|
822
426
|
static description = "Applies a phaser effect to an audio file.\n audio, effect, modulation\n\n Use cases:\n - Create sweeping, swooshing sounds\n - Add movement to static sounds\n - Produce psychedelic or space-like effects";
|
|
@@ -826,54 +430,7 @@ export class PhaserNode extends BaseNode {
|
|
|
826
430
|
static inlineFields = [];
|
|
827
431
|
static inputFields = ["audio"];
|
|
828
432
|
async process(context) {
|
|
829
|
-
|
|
830
|
-
const rateHz = this.rate_hz;
|
|
831
|
-
const depth = this.depth;
|
|
832
|
-
const centreFreqHz = this.centre_frequency_hz;
|
|
833
|
-
const feedback = this.feedback;
|
|
834
|
-
const mix = this.mix;
|
|
835
|
-
const bytes = await requireAudioBytes(audio, context);
|
|
836
|
-
const wav = await decodeAudioToWav(bytes);
|
|
837
|
-
const result = processPerChannel(wav, (ch, sr) => {
|
|
838
|
-
const out = new Float32Array(ch.length);
|
|
839
|
-
// 4-stage first-order all-pass phaser
|
|
840
|
-
const numStages = 4;
|
|
841
|
-
// Delay buffers: x[n-1] and y[n-1] for each stage
|
|
842
|
-
const xPrev = new Float32Array(numStages);
|
|
843
|
-
const yPrev = new Float32Array(numStages);
|
|
844
|
-
// Feedback delay
|
|
845
|
-
let feedbackSample = 0;
|
|
846
|
-
let lfoPhase = 0;
|
|
847
|
-
const lfoIncrement = (2 * Math.PI * rateHz) / sr;
|
|
848
|
-
for (let i = 0; i < ch.length; i++) {
|
|
849
|
-
// LFO modulates centre frequency
|
|
850
|
-
const lfo = Math.sin(lfoPhase) * depth;
|
|
851
|
-
lfoPhase += lfoIncrement;
|
|
852
|
-
if (lfoPhase > 2 * Math.PI)
|
|
853
|
-
lfoPhase -= 2 * Math.PI;
|
|
854
|
-
// Modulated frequency (centre ± depth range)
|
|
855
|
-
const modFreq = Math.max(20, Math.min(sr / 2 - 1, centreFreqHz * (1 + lfo)));
|
|
856
|
-
const tanVal = Math.tan((Math.PI * modFreq) / sr);
|
|
857
|
-
const a = (tanVal - 1) / (tanVal + 1);
|
|
858
|
-
// Input with feedback
|
|
859
|
-
const signal = ch[i] + feedbackSample * feedback;
|
|
860
|
-
// Apply all-pass filter stages
|
|
861
|
-
let apOut = signal;
|
|
862
|
-
for (let s = 0; s < numStages; s++) {
|
|
863
|
-
const newOut = a * apOut + xPrev[s] - a * yPrev[s];
|
|
864
|
-
xPrev[s] = apOut;
|
|
865
|
-
yPrev[s] = newOut;
|
|
866
|
-
apOut = newOut;
|
|
867
|
-
}
|
|
868
|
-
feedbackSample = apOut;
|
|
869
|
-
// Mix dry and wet
|
|
870
|
-
out[i] = ch[i] * (1 - mix) + apOut * mix;
|
|
871
|
-
}
|
|
872
|
-
return out;
|
|
873
|
-
});
|
|
874
|
-
return {
|
|
875
|
-
output: audioRefFromWav(encodeWav(result.samples, result.sampleRate, result.numChannels))
|
|
876
|
-
};
|
|
433
|
+
return { output: await applyToClip(PhaserEffect, this, this.audio, context) };
|
|
877
434
|
}
|
|
878
435
|
}
|
|
879
436
|
__decorate([
|
|
@@ -890,56 +447,6 @@ __decorate([
|
|
|
890
447
|
description: "The audio file to process."
|
|
891
448
|
})
|
|
892
449
|
], PhaserNode.prototype, "audio", void 0);
|
|
893
|
-
__decorate([
|
|
894
|
-
prop({
|
|
895
|
-
type: "float",
|
|
896
|
-
default: 1,
|
|
897
|
-
title: "Rate Hz",
|
|
898
|
-
description: "Rate of the phaser effect in Hz.",
|
|
899
|
-
min: 0.1,
|
|
900
|
-
max: 10
|
|
901
|
-
})
|
|
902
|
-
], PhaserNode.prototype, "rate_hz", void 0);
|
|
903
|
-
__decorate([
|
|
904
|
-
prop({
|
|
905
|
-
type: "float",
|
|
906
|
-
default: 0.5,
|
|
907
|
-
title: "Depth",
|
|
908
|
-
description: "Depth of the phaser effect.",
|
|
909
|
-
min: 0,
|
|
910
|
-
max: 1
|
|
911
|
-
})
|
|
912
|
-
], PhaserNode.prototype, "depth", void 0);
|
|
913
|
-
__decorate([
|
|
914
|
-
prop({
|
|
915
|
-
type: "float",
|
|
916
|
-
default: 1300,
|
|
917
|
-
title: "Centre Frequency Hz",
|
|
918
|
-
description: "Centre frequency of the phaser in Hz.",
|
|
919
|
-
min: 100,
|
|
920
|
-
max: 5000
|
|
921
|
-
})
|
|
922
|
-
], PhaserNode.prototype, "centre_frequency_hz", void 0);
|
|
923
|
-
__decorate([
|
|
924
|
-
prop({
|
|
925
|
-
type: "float",
|
|
926
|
-
default: 0,
|
|
927
|
-
title: "Feedback",
|
|
928
|
-
description: "Feedback of the phaser effect. Negative values invert the phase.",
|
|
929
|
-
min: -1,
|
|
930
|
-
max: 1
|
|
931
|
-
})
|
|
932
|
-
], PhaserNode.prototype, "feedback", void 0);
|
|
933
|
-
__decorate([
|
|
934
|
-
prop({
|
|
935
|
-
type: "float",
|
|
936
|
-
default: 0.5,
|
|
937
|
-
title: "Mix",
|
|
938
|
-
description: "Mix between the dry (original) and wet (effected) signals.",
|
|
939
|
-
min: 0,
|
|
940
|
-
max: 1
|
|
941
|
-
})
|
|
942
|
-
], PhaserNode.prototype, "mix", void 0);
|
|
943
450
|
// ── Export ────────────────────────────────────────────────────────
|
|
944
451
|
/**
|
|
945
452
|
* All pedalboard effects run on the server. They decode the input audio to PCM
|