0
# Audio Components
1
2
Lower-level building blocks including analysis tools, filters, envelopes, and channel utilities for custom audio processing.
3
4
## Capabilities
5
6
### Analysis Components
7
8
Tools for analyzing audio signals in real-time.
9
10
```typescript { .api }
11
/**
12
* Real-time FFT analyzer
13
*/
14
class FFT {
15
constructor(size?: number);
16
17
/** FFT size */
18
size: number;
19
20
/** Smoothing factor */
21
smoothing: NormalRange;
22
23
/** Get frequency domain data */
24
getValue(): Float32Array;
25
26
/** Get frequency value at index */
27
getFrequencyValue(frequency: Frequency): number;
28
}
29
30
/**
31
* Level meter for amplitude measurement
32
*/
33
class Meter {
34
constructor(smoothing?: NormalRange);
35
36
/** Smoothing factor */
37
smoothing: NormalRange;
38
39
/** Get current level */
40
getValue(): number;
41
42
/** Get level in decibels */
43
getLevel(): number;
44
}
45
46
/**
47
* Waveform analyzer for time domain visualization
48
*/
49
class Waveform {
50
constructor(size?: number);
51
52
/** Buffer size */
53
size: number;
54
55
/** Get time domain data */
56
getValue(): Float32Array;
57
}
58
59
/**
60
* Envelope follower for tracking amplitude
61
*/
62
class Follower {
63
constructor(attack?: Time, release?: Time);
64
65
/** Attack time */
66
attack: Time;
67
68
/** Release time */
69
release: Time;
70
71
/** Connect to audio parameter */
72
connect(param: AudioParam): this;
73
}
74
```
75
76
### Filter Components
77
78
Various filter types for frequency shaping.
79
80
```typescript { .api }
81
/**
82
* Biquad filter with multiple types
83
*/
84
class Filter {
85
constructor(frequency?: Frequency, type?: BiquadFilterType, rolloff?: number);
86
87
/** Cutoff frequency */
88
frequency: Signal<"frequency">;
89
90
/** Q factor (resonance) */
91
Q: Signal<"positive">;
92
93
/** Gain for peaking/shelving filters */
94
gain: Signal<"decibels">;
95
96
/** Filter type */
97
type: BiquadFilterType;
98
99
/** Filter rolloff (-12, -24, -48, -96 dB/oct) */
100
rolloff: number;
101
102
/** Get frequency response */
103
getFrequencyResponse(length?: number): Float32Array;
104
}
105
106
/**
107
* 3-band equalizer
108
*/
109
class EQ3 {
110
constructor(lowFrequency?: Frequency, highFrequency?: Frequency);
111
112
/** Low frequency gain */
113
low: Signal<"decibels">;
114
115
/** Mid frequency gain */
116
mid: Signal<"decibels">;
117
118
/** High frequency gain */
119
high: Signal<"decibels">;
120
121
/** Low/mid crossover frequency */
122
lowFrequency: Signal<"frequency">;
123
124
/** Mid/high crossover frequency */
125
highFrequency: Signal<"frequency">;
126
127
/** Low frequency Q */
128
Q: Signal<"positive">;
129
}
130
131
/**
132
* Convolution filter using impulse responses
133
*/
134
class Convolver {
135
constructor(url?: string | AudioBuffer | ToneAudioBuffer, onload?: () => void);
136
137
/** Impulse response buffer */
138
buffer: ToneAudioBuffer;
139
140
/** Normalize the impulse response */
141
normalize: boolean;
142
143
/** Load impulse response */
144
load(url: string): Promise<this>;
145
}
146
```
147
148
### Envelope Components
149
150
Envelope generators for shaping audio parameters over time.
151
152
```typescript { .api }
153
/**
154
* ADSR envelope generator
155
*/
156
class Envelope {
157
constructor(attack?: Time, decay?: Time, sustain?: NormalRange, release?: Time);
158
159
/** Attack time */
160
attack: Time;
161
162
/** Decay time */
163
decay: Time;
164
165
/** Sustain level */
166
sustain: NormalRange;
167
168
/** Release time */
169
release: Time;
170
171
/** Attack curve */
172
attackCurve: EnvelopeCurve;
173
174
/** Decay curve */
175
decayCurve: EnvelopeCurve;
176
177
/** Release curve */
178
releaseCurve: EnvelopeCurve;
179
180
/** Trigger attack phase */
181
triggerAttack(time?: Time, velocity?: NormalRange): this;
182
183
/** Trigger release phase */
184
triggerRelease(time?: Time): this;
185
186
/** Trigger attack and release */
187
triggerAttackRelease(duration: Time, time?: Time, velocity?: NormalRange): this;
188
189
/** Cancel envelope */
190
cancel(time?: Time): this;
191
192
/** Connect to audio parameter */
193
connect(destination: AudioParam): this;
194
}
195
196
/**
197
* Amplitude envelope (Envelope connected to Gain)
198
*/
199
class AmplitudeEnvelope extends Envelope {
200
constructor(attack?: Time, decay?: Time, sustain?: NormalRange, release?: Time);
201
202
/** Connect to audio node */
203
connect(destination: AudioNode): this;
204
}
205
206
/**
207
* Frequency envelope for filter modulation
208
*/
209
class FrequencyEnvelope extends Envelope {
210
constructor(attack?: Time, decay?: Time, sustain?: NormalRange, release?: Time);
211
212
/** Base frequency */
213
baseFrequency: Frequency;
214
215
/** Envelope range in octaves */
216
octaves: number;
217
218
/** Envelope exponent */
219
exponent: number;
220
}
221
222
type EnvelopeCurve = "linear" | "exponential" | number[] | string;
223
```
224
225
### Channel Components
226
227
Utilities for stereo processing and channel manipulation.
228
229
```typescript { .api }
230
/**
231
* Stereo panner
232
*/
233
class Panner {
234
constructor(pan?: NormalRange);
235
236
/** Pan position (-1 to 1) */
237
pan: Signal<"normalRange">;
238
}
239
240
/**
241
* Volume control with metering
242
*/
243
class Volume {
244
constructor(volume?: Decibels);
245
246
/** Volume in decibels */
247
volume: Signal<"decibels">;
248
249
/** Mute the volume */
250
mute: boolean;
251
}
252
253
/**
254
* Audio channel with volume and pan
255
*/
256
class Channel {
257
constructor(volume?: Decibels, pan?: NormalRange);
258
259
/** Volume control */
260
volume: Volume;
261
262
/** Pan control */
263
pan: Panner;
264
265
/** Mute the channel */
266
mute: boolean;
267
268
/** Solo the channel */
269
solo: boolean;
270
}
271
272
/**
273
* Crossfader between two inputs
274
*/
275
class CrossFade {
276
constructor(fade?: NormalRange);
277
278
/** Fade position (0 = A, 1 = B) */
279
fade: Signal<"normalRange">;
280
281
/** Input A */
282
a: Gain;
283
284
/** Input B */
285
b: Gain;
286
}
287
```
288
289
### Dynamics Components
290
291
Compression and gating for dynamics control.
292
293
```typescript { .api }
294
/**
295
* Audio compressor
296
*/
297
class Compressor {
298
constructor(threshold?: Decibels, ratio?: Positive);
299
300
/** Compression threshold */
301
threshold: Signal<"decibels">;
302
303
/** Compression ratio */
304
ratio: Signal<"positive">;
305
306
/** Attack time */
307
attack: Signal<"time">;
308
309
/** Release time */
310
release: Signal<"time">;
311
312
/** Knee softness */
313
knee: Signal<"decibels">;
314
315
/** Get current reduction amount */
316
reduction: number;
317
}
318
319
/**
320
* Noise gate
321
*/
322
class Gate {
323
constructor(threshold?: Decibels, attack?: Time, release?: Time);
324
325
/** Gate threshold */
326
threshold: Signal<"decibels">;
327
328
/** Attack time */
329
attack: Signal<"time">;
330
331
/** Release time */
332
release: Signal<"time">;
333
}
334
335
/**
336
* Peak limiter
337
*/
338
class Limiter {
339
constructor(threshold?: Decibels);
340
341
/** Limiting threshold */
342
threshold: Signal<"decibels">;
343
344
/** Get current reduction */
345
reduction: number;
346
}
347
```
348
349
**Usage Examples:**
350
351
```typescript
352
import { Oscillator, Filter, Envelope, Compressor, start } from "tone";
353
354
await start();
355
356
// Filter with envelope modulation
357
const osc = new Oscillator(220, "sawtooth");
358
const filter = new Filter(400, "lowpass");
359
const env = new FrequencyEnvelope(0.1, 0.2, 0.3, 1);
360
361
osc.connect(filter);
362
filter.toDestination();
363
364
// Connect envelope to filter frequency
365
env.connect(filter.frequency);
366
367
// Trigger envelope and oscillator
368
osc.start();
369
env.triggerAttackRelease("2n");
370
371
// Add compression
372
const comp = new Compressor(-24, 4);
373
filter.connect(comp);
374
comp.toDestination();
375
```
376
377
## Types
378
379
```typescript { .api }
380
type BiquadFilterType = "lowpass" | "highpass" | "bandpass" | "lowshelf" | "highshelf" | "notch" | "allpass" | "peaking";
381
382
interface FilterOptions {
383
frequency: Frequency;
384
type: BiquadFilterType;
385
Q: Positive;
386
gain: Decibels;
387
rolloff: number;
388
}
389
390
interface EnvelopeOptions {
391
attack: Time;
392
decay: Time;
393
sustain: NormalRange;
394
release: Time;
395
attackCurve: EnvelopeCurve;
396
decayCurve: EnvelopeCurve;
397
releaseCurve: EnvelopeCurve;
398
}
399
400
interface CompressorOptions {
401
threshold: Decibels;
402
ratio: Positive;
403
attack: Time;
404
release: Time;
405
knee: Decibels;
406
}
407
```