Tone.Sampler vs Synth in Tone.js

In web audio development using Tone.js, understanding the difference between sound sources is crucial for building performance-friendly and realistic audio applications. This article provides a direct comparison between Tone.Sampler and a standard synthesizer (such as Tone.Synth), explaining how they generate sound, their distinct technical architectures, and when to use each in your projects.

Understanding Tone.Sampler

Tone.Sampler is a member of the Tone.js library designed to play back pre-recorded audio files (samples) instead of generating audio from scratch. When you trigger a note on a sampler, it loads an audio file (like a .mp3 or .wav of a real instrument) and plays it back.

If you request a note that you haven’t uploaded a specific sample for, Tone.Sampler automatically pitch-shifts the closest available sample to match the requested pitch.

Key Characteristics of Tone.Sampler:

// Example of setting up a Tone.Sampler
const sampler = new Tone.Sampler({
  urls: {
    A1: "A1.mp3",
    A2: "A2.mp3",
  },
  baseUrl: "https://tonejs.github.io/audio/casio/",
  onload: () => {
    sampler.triggerAttackRelease("C2", "8n");
  }
}).toDestination();

Understanding the Standard Synthesizer (Tone.Synth)

A standard synthesizer in Tone.js, such as Tone.Synth, generates audio in real-time using mathematical calculations. It utilizes digital oscillators to produce basic waveforms (sine, square, triangle, or sawtooth waves) and shapes those waves using envelopes (ADSR) and filters.

Key Characteristics of Tone.Synth:

// Example of setting up a Tone.Synth
const synth = new Tone.Synth().toDestination();
// Play a note instantly without waiting for assets to load
synth.triggerAttackRelease("C4", "8n");

Key Differences At a Glance

Feature Tone.Sampler Standard Synth (Tone.Synth)
Sound Generation Plays back pre-recorded audio files. Synthesizes waveforms mathematically in real-time.
Sound Quality Highly realistic (great for acoustic instruments). Electronic, retro, or highly stylized.
Network Overhead High (must download audio files first). None (runs entirely via local code).
Memory & CPU Higher memory usage (RAM); lower CPU usage. Low memory usage; higher CPU usage for complex synthesis.
Customization Limited to the original recording and basic pitch-shifting. Highly customizable (modulate filters, envelopes, and waveforms).

Choosing the Right Tool for Your Project

Use Tone.Sampler if your goal is to build an app that sounds like a real instrument, such as a digital piano, a realistic drum machine, or an orchestral soundboard.

Use Tone.Synth (or other synthesis classes like Tone.FMSynth, Tone.AMSynth, or Tone.PolySynth) if you are building an interactive synthesizer, a chiptune game, or need a lightweight audio engine that works instantly without downloading heavy audio assets.