Search guides and the APICtrl K
  1. API reference
  2. DSP

sampler.h

Sample playback.

#include <sonore/sampler.h>
On this page

Design notes

A drum sampler, a multisampled instrument, a one-shot player: all of them are the same three problems, and each has a way of going quietly wrong.

PITCH. Playing a note is a rate change, but so is the difference between the file's sample rate and the session's. A 44.1 kHz sample played at 48 kHz without correction is sharp by a third of a semitone: enough to sound out of tune against anything else, and subtle enough to be blamed on the tuning of the other instrument.

INTERPOLATION. A rate change means reading between samples, and linear interpolation is a lowpass whose corner moves with the fraction. On a sustained sample that is a shimmer that follows the pitch.

LOOPS. Reading across a loop point has to see the samples on BOTH sides,
or the interpolator runs off the end of the loop into whatever follows and
clicks once per cycle.

The sample data is owned elsewhere (an ImpulseResponse, a WavData, anything) and referenced here, because a voice must not own or copy audio while the audio thread is running.

Types 2

Where a sample lives and how it should be played. Shared by every voice playing it, so the per-voice state stays tiny.

One voice playing one sample.

Deliberately does NOT include an envelope: the toolkit already has ADSR, and a voice that hard-codes one cannot be given a different shape. What it does own is position, rate and looping: the parts that are easy to get subtly wrong.

↑↓ to move↵ to openEvery public name in the headers, and every guide