@harmonia-audio/effects 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,377 @@
1
+ /**
2
+ * Interface for audio effects that can be chained in a pipeline.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * class MyEffect implements AudioEffect {
7
+ * process(samples: Buffer): Buffer { return samples; }
8
+ * reset(): void {}
9
+ * destroy(): void {}
10
+ * }
11
+ * ```
12
+ */
13
+ interface AudioEffect {
14
+ /** Process a buffer of audio samples in-place or returning a new buffer. */
15
+ process(samples: Buffer): Buffer;
16
+ /** Reset effect state (e.g., filter history). */
17
+ reset(): void;
18
+ /** Release any native resources. */
19
+ destroy(): void;
20
+ }
21
+
22
+ /**
23
+ * Chainable audio effects processing pipeline.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { EffectsPipeline, VolumeEffect, EqualizerEffect } from '@harmonia/effects';
28
+ *
29
+ * const pipeline = new EffectsPipeline()
30
+ * .add(new VolumeEffect(0.8))
31
+ * .add(new EqualizerEffect([{ frequency: 1000, gain: 3, q: 1.0 }]));
32
+ *
33
+ * const processed = pipeline.process(pcmBuffer);
34
+ * ```
35
+ */
36
+ declare class EffectsPipeline {
37
+ private readonly effects;
38
+ /**
39
+ * Add an effect to the pipeline.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * pipeline.add(new VolumeEffect(0.5));
44
+ * ```
45
+ */
46
+ add(effect: AudioEffect): this;
47
+ /**
48
+ * Remove an effect from the pipeline.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * pipeline.remove(volumeEffect);
53
+ * ```
54
+ */
55
+ remove(effect: AudioEffect): this;
56
+ /**
57
+ * Clear all effects from the pipeline.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * pipeline.clear();
62
+ * ```
63
+ */
64
+ clear(): this;
65
+ /**
66
+ * Process audio through all effects in the pipeline.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const processed = pipeline.process(pcmBuffer);
71
+ * ```
72
+ */
73
+ process(samples: Buffer): Buffer;
74
+ /**
75
+ * Reset all effects in the pipeline.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * pipeline.reset();
80
+ * ```
81
+ */
82
+ reset(): void;
83
+ /**
84
+ * Destroy the pipeline and all effects.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * pipeline.destroy();
89
+ * ```
90
+ */
91
+ destroy(): void;
92
+ /** The number of effects in the pipeline. */
93
+ get length(): number;
94
+ }
95
+
96
+ /**
97
+ * Volume control effect.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const vol = new VolumeEffect(0.5); // 50% volume
102
+ * const output = vol.process(pcmBuffer);
103
+ * ```
104
+ */
105
+ declare class VolumeEffect implements AudioEffect {
106
+ private _volume;
107
+ constructor(volume?: number);
108
+ /** Get the current volume level (0.0 to 10.0). */
109
+ get volume(): number;
110
+ /**
111
+ * Set the volume level.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * vol.setVolume(0.8);
116
+ * ```
117
+ */
118
+ setVolume(volume: number): void;
119
+ process(samples: Buffer): Buffer;
120
+ reset(): void;
121
+ destroy(): void;
122
+ }
123
+
124
+ /**
125
+ * Configuration for a single equalizer band.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const band: EqualizerBand = { frequency: 1000, gain: 3, q: 1.0 };
130
+ * ```
131
+ */
132
+ interface EqualizerBand {
133
+ readonly frequency: number;
134
+ readonly gain: number;
135
+ readonly q: number;
136
+ }
137
+ /**
138
+ * Multi-band parametric equalizer effect using biquad filters.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const eq = new EqualizerEffect([
143
+ * { frequency: 60, gain: 3, q: 0.7 },
144
+ * { frequency: 1000, gain: -2, q: 1.0 },
145
+ * { frequency: 8000, gain: 1, q: 1.4 },
146
+ * ]);
147
+ * const output = eq.process(pcmBuffer);
148
+ * ```
149
+ */
150
+ declare class EqualizerEffect implements AudioEffect {
151
+ private readonly filters;
152
+ private readonly sampleRate;
153
+ constructor(bands: readonly EqualizerBand[], sampleRate?: number);
154
+ process(samples: Buffer): Buffer;
155
+ reset(): void;
156
+ destroy(): void;
157
+ }
158
+
159
+ /**
160
+ * Options for the compressor effect.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const options: CompressorOptions = {
165
+ * threshold: -20,
166
+ * ratio: 4,
167
+ * attack: 5,
168
+ * release: 100,
169
+ * };
170
+ * ```
171
+ */
172
+ interface CompressorOptions {
173
+ readonly threshold: number;
174
+ readonly ratio: number;
175
+ readonly attack: number;
176
+ readonly release: number;
177
+ readonly makeupGain?: number;
178
+ readonly knee?: number;
179
+ readonly sampleRate?: number;
180
+ }
181
+ /**
182
+ * Dynamic range compressor effect.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * const compressor = new CompressorEffect({
187
+ * threshold: -20,
188
+ * ratio: 4,
189
+ * attack: 5,
190
+ * release: 100,
191
+ * });
192
+ * const output = compressor.process(pcmBuffer);
193
+ * ```
194
+ */
195
+ declare class CompressorEffect implements AudioEffect {
196
+ private readonly native;
197
+ constructor(options: CompressorOptions);
198
+ process(samples: Buffer): Buffer;
199
+ reset(): void;
200
+ destroy(): void;
201
+ }
202
+
203
+ /**
204
+ * Options for the noise gate effect.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * const gate = new NoiseGateEffect({ threshold: -40, attack: 1, release: 50, hold: 20 });
209
+ * ```
210
+ */
211
+ interface NoiseGateOptions {
212
+ readonly threshold: number;
213
+ readonly attack: number;
214
+ readonly release: number;
215
+ readonly hold: number;
216
+ readonly sampleRate?: number;
217
+ }
218
+ /**
219
+ * Noise gate effect that silences audio below a threshold.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * const gate = new NoiseGateEffect({
224
+ * threshold: -40,
225
+ * attack: 1,
226
+ * release: 50,
227
+ * hold: 20,
228
+ * });
229
+ * const output = gate.process(pcmBuffer);
230
+ * ```
231
+ */
232
+ declare class NoiseGateEffect implements AudioEffect {
233
+ private readonly native;
234
+ constructor(options: NoiseGateOptions);
235
+ process(samples: Buffer): Buffer;
236
+ reset(): void;
237
+ destroy(): void;
238
+ }
239
+
240
+ /**
241
+ * Options for the delay/echo effect.
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * const delay = new DelayEffect({ delayMs: 300, feedback: 0.4, wet: 0.3 });
246
+ * ```
247
+ */
248
+ interface DelayOptions {
249
+ readonly delayMs: number;
250
+ readonly feedback: number;
251
+ readonly wet: number;
252
+ readonly sampleRate?: number;
253
+ }
254
+ /**
255
+ * Delay/echo audio effect.
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * const delay = new DelayEffect({
260
+ * delayMs: 300,
261
+ * feedback: 0.4,
262
+ * wet: 0.3,
263
+ * });
264
+ * const output = delay.process(pcmBuffer);
265
+ * ```
266
+ */
267
+ declare class DelayEffect implements AudioEffect {
268
+ private readonly native;
269
+ constructor(options: DelayOptions);
270
+ process(samples: Buffer): Buffer;
271
+ reset(): void;
272
+ destroy(): void;
273
+ }
274
+
275
+ /**
276
+ * Convolution reverb effect using an impulse response.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * import { readFileSync } from 'fs';
281
+ *
282
+ * const ir = readFileSync('./hall-ir.pcm');
283
+ * const reverb = new ReverbEffect(ir);
284
+ * const output = reverb.process(pcmBuffer);
285
+ * ```
286
+ */
287
+ declare class ReverbEffect implements AudioEffect {
288
+ private readonly native;
289
+ constructor(impulseResponse: Buffer);
290
+ process(samples: Buffer): Buffer;
291
+ reset(): void;
292
+ destroy(): void;
293
+ }
294
+
295
+ /**
296
+ * Pitch shifting effect using a phase vocoder.
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * const pitch = new PitchShiftEffect(1.5); // shift up by 50%
301
+ * const output = pitch.process(pcmBuffer);
302
+ * ```
303
+ */
304
+ declare class PitchShiftEffect implements AudioEffect {
305
+ private readonly native;
306
+ constructor(pitchFactor: number, fftSize?: number);
307
+ /**
308
+ * Update the pitch factor at runtime.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * pitch.setPitchFactor(0.8);
313
+ * ```
314
+ */
315
+ setPitchFactor(factor: number): void;
316
+ process(samples: Buffer): Buffer;
317
+ reset(): void;
318
+ destroy(): void;
319
+ }
320
+
321
+ /**
322
+ * Stereo widening effect with mono downmix capability.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * const widener = new StereoWidenerEffect(1.5);
327
+ * const wider = widener.process(stereoBuffer);
328
+ * ```
329
+ */
330
+ declare class StereoWidenerEffect implements AudioEffect {
331
+ private _width;
332
+ private _monoOutput;
333
+ constructor(width?: number, monoOutput?: boolean);
334
+ /**
335
+ * Set the stereo width.
336
+ *
337
+ * @example
338
+ * ```ts
339
+ * widener.setWidth(2.0);
340
+ * ```
341
+ */
342
+ setWidth(width: number): void;
343
+ process(samples: Buffer): Buffer;
344
+ reset(): void;
345
+ destroy(): void;
346
+ }
347
+
348
+ /**
349
+ * Options for loudness normalization.
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * const normalizer = new LoudnessNormalizerEffect({ targetLufs: -14 });
354
+ * ```
355
+ */
356
+ interface LoudnessOptions {
357
+ readonly targetLufs: number;
358
+ readonly sampleRate?: number;
359
+ }
360
+ /**
361
+ * Loudness normalization effect targeting a specific LUFS level.
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * const normalizer = new LoudnessNormalizerEffect({ targetLufs: -14 });
366
+ * const normalized = normalizer.process(pcmBuffer);
367
+ * ```
368
+ */
369
+ declare class LoudnessNormalizerEffect implements AudioEffect {
370
+ private readonly native;
371
+ constructor(options: LoudnessOptions);
372
+ process(samples: Buffer): Buffer;
373
+ reset(): void;
374
+ destroy(): void;
375
+ }
376
+
377
+ export { type AudioEffect, CompressorEffect, type CompressorOptions, DelayEffect, type DelayOptions, EffectsPipeline, type EqualizerBand, EqualizerEffect, LoudnessNormalizerEffect, type LoudnessOptions, NoiseGateEffect, type NoiseGateOptions, PitchShiftEffect, ReverbEffect, StereoWidenerEffect, VolumeEffect };