or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

components.mdcore.mdeffects.mdevents.mdindex.mdinstruments.mdsignals.mdsources.md

instruments.mddocs/

0

# Synthesizers and Instruments

1

2

Ready-to-use musical instruments including monophonic and polyphonic synthesizers with various synthesis techniques for creating musical sounds.

3

4

## Capabilities

5

6

### Basic Synthesizer

7

8

Simple oscillator-based synthesizer with ADSR envelope.

9

10

```typescript { .api }

11

/**

12

* Basic synthesizer composed of an oscillator and amplitude envelope

13

*/

14

class Synth {

15

constructor(options?: Partial<SynthOptions>);

16

17

/** The oscillator */

18

readonly oscillator: OmniOscillator;

19

20

/** The frequency signal */

21

readonly frequency: Signal<"frequency">;

22

23

/** The detune signal in cents */

24

readonly detune: Signal<"cents">;

25

26

/** The amplitude envelope */

27

readonly envelope: AmplitudeEnvelope;

28

29

/** Trigger attack (note on) */

30

triggerAttack(note: Frequency, time?: Time, velocity?: NormalRange): this;

31

32

/** Trigger release (note off) */

33

triggerRelease(time?: Time): this;

34

35

/** Trigger attack and release */

36

triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: NormalRange): this;

37

38

/** Connect to destination */

39

toDestination(): this;

40

41

/** Set note (for monophonic playing) */

42

setNote(note: Frequency, time?: Time): this;

43

}

44

45

interface SynthOptions {

46

oscillator: OmniOscillatorSynthOptions;

47

envelope: Omit<EnvelopeOptions, "context">;

48

detune: Cents;

49

portamento: Time;

50

}

51

```

52

53

**Usage Examples:**

54

55

```typescript

56

import { Synth, start } from "tone";

57

58

const synth = new Synth({

59

oscillator: {

60

type: "sine"

61

},

62

envelope: {

63

attack: 0.1,

64

decay: 0.2,

65

sustain: 0.5,

66

release: 0.8

67

}

68

}).toDestination();

69

70

// Play single note

71

await start();

72

synth.triggerAttackRelease("C4", "8n");

73

74

// Play sequence

75

const notes = ["C4", "E4", "G4", "C5"];

76

notes.forEach((note, i) => {

77

synth.triggerAttackRelease(note, "8n", i * 0.5);

78

});

79

```

80

81

### Monophonic Synthesizers

82

83

Advanced monophonic synthesizers with different synthesis methods.

84

85

```typescript { .api }

86

/**

87

* Monophonic synthesizer with filter

88

*/

89

class MonoSynth {

90

constructor(options?: Partial<MonoSynthOptions>);

91

92

readonly oscillator: OmniOscillator;

93

readonly frequency: Signal<"frequency">;

94

readonly detune: Signal<"cents">;

95

readonly filter: Filter;

96

readonly envelope: AmplitudeEnvelope;

97

readonly filterEnvelope: FrequencyEnvelope;

98

99

triggerAttack(note: Frequency, time?: Time, velocity?: NormalRange): this;

100

triggerRelease(time?: Time): this;

101

triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: NormalRange): this;

102

}

103

104

/**

105

* Amplitude modulation synthesizer

106

*/

107

class AMSynth {

108

constructor(options?: Partial<AMSynthOptions>);

109

110

readonly oscillator: AMOscillator;

111

readonly frequency: Signal<"frequency">;

112

readonly detune: Signal<"cents">;

113

readonly envelope: AmplitudeEnvelope;

114

115

triggerAttack(note: Frequency, time?: Time, velocity?: NormalRange): this;

116

triggerRelease(time?: Time): this;

117

triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: NormalRange): this;

118

}

119

120

/**

121

* Frequency modulation synthesizer

122

*/

123

class FMSynth {

124

constructor(options?: Partial<FMSynthOptions>);

125

126

readonly oscillator: FMOscillator;

127

readonly frequency: Signal<"frequency">;

128

readonly detune: Signal<"cents">;

129

readonly envelope: AmplitudeEnvelope;

130

131

triggerAttack(note: Frequency, time?: Time, velocity?: NormalRange): this;

132

triggerRelease(time?: Time): this;

133

triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: NormalRange): this;

134

}

135

136

/**

137

* Two-oscillator synthesizer

138

*/

139

class DuoSynth {

140

constructor(options?: Partial<DuoSynthOptions>);

141

142

readonly voice0: MonoSynth;

143

readonly voice1: MonoSynth;

144

readonly frequency: Signal<"frequency">;

145

readonly detune: Signal<"cents">;

146

readonly vibratoAmount: Signal<"normalRange">;

147

readonly vibratoRate: Signal<"frequency">;

148

149

triggerAttack(note: Frequency, time?: Time, velocity?: NormalRange): this;

150

triggerRelease(time?: Time): this;

151

triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: NormalRange): this;

152

}

153

```

154

155

### Percussion Synthesizers

156

157

Specialized synthesizers for percussion sounds.

158

159

```typescript { .api }

160

/**

161

* Kick drum synthesizer

162

*/

163

class MembraneSynth {

164

constructor(options?: Partial<MembraneSynthOptions>);

165

166

readonly oscillator: OmniOscillator;

167

readonly envelope: AmplitudeEnvelope;

168

readonly octaves: number;

169

readonly pitchDecay: Time;

170

171

triggerAttack(note?: Frequency, time?: Time, velocity?: NormalRange): this;

172

triggerRelease(time?: Time): this;

173

triggerAttackRelease(note?: Frequency, duration?: Time, time?: Time, velocity?: NormalRange): this;

174

}

175

176

/**

177

* Metallic percussion synthesizer

178

*/

179

class MetalSynth {

180

constructor(options?: Partial<MetalSynthOptions>);

181

182

readonly frequency: Signal<"frequency">;

183

readonly envelope: AmplitudeEnvelope;

184

readonly harmonicity: Signal<"positive">;

185

readonly modulationIndex: Signal<"positive">;

186

readonly resonance: Signal<"frequency">;

187

readonly octaves: Signal<"number">;

188

189

triggerAttack(note?: Frequency, time?: Time, velocity?: NormalRange): this;

190

triggerRelease(time?: Time): this;

191

triggerAttackRelease(note?: Frequency, duration?: Time, time?: Time, velocity?: NormalRange): this;

192

}

193

194

/**

195

* Noise-based synthesizer

196

*/

197

class NoiseSynth {

198

constructor(options?: Partial<NoiseSynthOptions>);

199

200

readonly noise: Noise;

201

readonly envelope: AmplitudeEnvelope;

202

203

triggerAttack(time?: Time, velocity?: NormalRange): this;

204

triggerRelease(time?: Time): this;

205

triggerAttackRelease(duration: Time, time?: Time, velocity?: NormalRange): this;

206

}

207

208

/**

209

* Plucked string synthesizer

210

*/

211

class PluckSynth {

212

constructor(options?: Partial<PluckSynthOptions>);

213

214

readonly attackNoise: number;

215

readonly dampening: Signal<"frequency">;

216

readonly resonance: Signal<"normalRange">;

217

218

triggerAttack(note: Frequency, time?: Time): this;

219

triggerAttackRelease(note: Frequency, duration?: Time, time?: Time): this;

220

}

221

```

222

223

### Polyphonic Synthesizer

224

225

Wrapper for creating polyphonic versions of monophonic synthesizers.

226

227

```typescript { .api }

228

/**

229

* Polyphonic synthesizer that manages voice allocation

230

*/

231

class PolySynth<T = Synth> {

232

constructor(voice?: new () => T, options?: Partial<PolySynthOptions<T>>);

233

234

/** Maximum number of voices */

235

maxPolyphony: number;

236

237

/** Voice allocation mode */

238

options: PolySynthOptions<T>;

239

240

/** Trigger attack for single note or chord */

241

triggerAttack(notes: Frequency | Frequency[], time?: Time, velocity?: NormalRange | NormalRange[]): this;

242

243

/** Trigger release for single note or chord */

244

triggerRelease(notes: Frequency | Frequency[], time?: Time): this;

245

246

/** Trigger attack and release for single note or chord */

247

triggerAttackRelease(

248

notes: Frequency | Frequency[],

249

duration: Time | Time[],

250

time?: Time,

251

velocity?: NormalRange | NormalRange[]

252

): this;

253

254

/** Set options for all voices */

255

set(options: RecursivePartial<T["options"]>): this;

256

257

/** Get a voice by note */

258

get(note: Frequency): T | undefined;

259

260

/** Release all voices */

261

releaseAll(time?: Time): this;

262

263

/** Connect to destination */

264

toDestination(): this;

265

}

266

267

interface PolySynthOptions<T> {

268

maxPolyphony: number;

269

voice: new () => T;

270

context: Context;

271

}

272

```

273

274

**Usage Examples:**

275

276

```typescript

277

import { PolySynth, Synth, start } from "tone";

278

279

// Basic polyphonic synth

280

const polySynth = new PolySynth(Synth).toDestination();

281

282

await start();

283

284

// Play chord

285

polySynth.triggerAttackRelease(["C4", "E4", "G4"], "4n");

286

287

// Play with different durations

288

polySynth.triggerAttackRelease(

289

["C4", "E4", "G4", "B4"],

290

["8n", "4n", "2n", "1n"]

291

);

292

293

// Advanced synth with custom options

294

const fmPoly = new PolySynth(FMSynth, {

295

maxPolyphony: 8

296

}).toDestination();

297

298

fmPoly.set({

299

envelope: {

300

attack: 0.1,

301

release: 2

302

}

303

});

304

```

305

306

### Sample-based Instrument

307

308

Multi-sample instrument with automatic pitch shifting.

309

310

```typescript { .api }

311

/**

312

* Polyphonic sampler instrument

313

*/

314

class Sampler {

315

constructor(urls?: {[note: string]: string} | ToneAudioBuffer, options?: Partial<SamplerOptions>);

316

317

/** Base URL for loading samples */

318

baseUrl: string;

319

320

/** Attack time */

321

attack: Time;

322

323

/** Release time */

324

release: Time;

325

326

/** Curve type for attack/release */

327

curve: "linear" | "exponential";

328

329

/** Add sample */

330

add(note: string, url: string | ToneAudioBuffer, callback?: () => void): this;

331

332

/** Check if sample exists */

333

has(note: string): boolean;

334

335

/** Trigger attack */

336

triggerAttack(notes: Frequency | Frequency[], time?: Time, velocity?: NormalRange | NormalRange[]): this;

337

338

/** Trigger release */

339

triggerRelease(notes: Frequency | Frequency[], time?: Time): this;

340

341

/** Trigger attack and release */

342

triggerAttackRelease(

343

notes: Frequency | Frequency[],

344

duration: Time | Time[],

345

time?: Time,

346

velocity?: NormalRange | NormalRange[]

347

): this;

348

349

/** Release all notes */

350

releaseAll(time?: Time): this;

351

352

/** Connect to destination */

353

toDestination(): this;

354

}

355

356

interface SamplerOptions {

357

attack: Time;

358

release: Time;

359

onload: () => void;

360

onerror: (error: Error) => void;

361

baseUrl: string;

362

curve: "linear" | "exponential";

363

urls: {[note: string]: string};

364

}

365

```

366

367

**Usage Examples:**

368

369

```typescript

370

import { Sampler, start } from "tone";

371

372

const sampler = new Sampler({

373

urls: {

374

"C4": "C4.mp3",

375

"D#4": "Ds4.mp3",

376

"F#4": "Fs4.mp3",

377

"A4": "A4.mp3"

378

},

379

release: 1,

380

baseUrl: "https://example.com/samples/"

381

}).toDestination();

382

383

// Wait for samples to load

384

await start();

385

await Tone.loaded();

386

387

// Play notes (automatic pitch shifting for missing samples)

388

sampler.triggerAttackRelease(["Eb4", "G4", "Bb4"], 4);

389

390

// Play with custom timing

391

sampler.triggerAttack("C4", 0);

392

sampler.triggerRelease("C4", "+2");

393

```

394

395

## Types

396

397

```typescript { .api }

398

interface EnvelopeOptions {

399

attack: Time;

400

decay: Time;

401

sustain: NormalRange;

402

release: Time;

403

attackCurve: EnvelopeCurve;

404

releaseCurve: EnvelopeCurve;

405

decayCurve: EnvelopeCurve;

406

}

407

408

interface MonophonicOptions {

409

detune: Cents;

410

portamento: Time;

411

onsilence: (voice: Monophonic<any>) => void;

412

}

413

414

interface OmniOscillatorSynthOptions {

415

type: OmniOscillatorType;

416

frequency: Frequency;

417

detune: Cents;

418

phase: Degrees;

419

volume: Decibels;

420

}

421

422

type EnvelopeCurve = "linear" | "exponential" | number[] | string;

423

type OmniOscillatorType = "sine" | "square" | "sawtooth" | "triangle" | "fatsine" | "fatsquare" | "fatsawtooth" | "fattriangle" | string;

424

425

interface MonoSynthOptions extends MonophonicOptions {

426

oscillator: OmniOscillatorSynthOptions;

427

filter: Omit<FilterOptions, "context">;

428

envelope: Omit<EnvelopeOptions, "context">;

429

filterEnvelope: Omit<FrequencyEnvelopeOptions, "context">;

430

}

431

432

interface AMSynthOptions extends MonophonicOptions {

433

oscillator: AMOscillatorOptions;

434

envelope: Omit<EnvelopeOptions, "context">;

435

}

436

437

interface FMSynthOptions extends MonophonicOptions {

438

oscillator: FMOscillatorOptions;

439

envelope: Omit<EnvelopeOptions, "context">;

440

}

441

442

interface DuoSynthOptions extends MonophonicOptions {

443

voice0: MonoSynthOptions;

444

voice1: MonoSynthOptions;

445

harmonicity: Positive;

446

vibratoAmount: NormalRange;

447

vibratoRate: Frequency;

448

}

449

```