Every sampler has an opinion

Record middle C on a piano nobody has tuned since spring and it comes out ten cents flat: a tenth of a semitone. Alone, you would never notice. Against anything in tune, it beats.

A sampler can fix that, if the file tells it how. Writing that down sounds like the simplest job a file format could have. It turns out the formats disagree about what they are writing down, and each one’s answer is an opinion about what a sample is.

WAV describes

WAV’s sampler chunk was not written by the people who wrote WAV. Three audio companies, Digidesign, Sonic Foundry and Turtle Beach, added it in 1993, and Microsoft published it the following year. It stores two things: the MIDI note at which the sample plays at its original pitch, and a fraction of a semitone up from that note, as an unsigned 32-bit number.

Up. There is no down. This chunk cannot say “ten cents flat of C”. It has to say “B, and nine-tenths of the way to C”, which it writes as 3,865,470,566 parts of 4,294,967,296.

That is less a flaw than a worldview. The chunk describes the recording: this is the pitch it has. What to do about it is the sampler’s business. It even records how long one sample lasts, in nanoseconds, in case anyone was wondering about the rate. The same document defines a second chunk, from IBM, that takes the opposite view, with a signed fine-tune of −50 to +50 cents. WAV, being WAV, holds both opinions.

AIFF instructs

Apple’s AIFF, from 1988, takes the opposite view. Its instrument chunk holds a base note and a detune in cents, from −50 to +50, defined as how much the instrument should alter the pitch on playback. The same flat C becomes note 60, detune +10: play it ten cents higher.

AIFF has other opinions. It assumes a sample is a note somebody is holding, so an instrument carries two loops: a sustain loop that repeats while the key is down, and a release loop for after it comes up. And it stores the sample rate as an 80-bit floating-point number, the extended format of the Mac’s standard numerics library at the time, so 44,100 arrives with more precision than any sample clock will ever need.

SoundFont remembers the hardware

SoundFont came from E-mu and Creative in the mid-1990s, to load instruments into the memory of a Sound Blaster card. It agrees with AIFF about tuning: an original pitch, and a signed correction in cents that the player applies. Ours gets +10.

But the hardware shows through everywhere. Every sample must be followed by at least 46 samples of silence, so the card’s interpolator never reads past the end into the next sound. Envelope times are written in timecents, 1,200 times the base-2 logarithm of the time in seconds, so zero means one second and every doubling adds 1,200. And if a SoundFont says nothing about release, the default is −12,000 timecents: just under a millisecond. Lift your finger and the note is gone.

SFZ is for people

SFZ, from 2004, is not binary at all. It is a text file. The flat C is pitch_keycenter=60 and tune=10, and you can read it, write it and fix it in any editor. Its opinion is that an instrument should stay legible to the person who made it.

Newer formats go further. Decent Sampler’s presets are XML that describes the instrument’s face as well as its samples: the background, the knobs, what each one turns. Its opinion is that an instrument is not finished until you can play it.

An empty field is an opinion too

The field you leave out is never neutral. A SoundFont that names no release lets go in under a millisecond. A WAV with no sampler chunk has no root note at all, and whatever reads it has to guess. Every default was a decision somebody made more than thirty years ago on behalf of an instrument they never met.

So moving a kit between instruments is not translation. Copy the numbers across and you get the sign wrong, because WAV’s description is not AIFF’s instruction. Drop a loop the other side cannot express. Inherit a release you never chose. It is closer to diplomacy: carry the meaning, then say it the way the other side says things.

Two dozen accents

Hardware samplers have opinions no spec writes down: the rate they run at, the depth they keep, whether a sound may be stereo, how long it may last. SoundEdit fits folders of sounds to two dozen of them and writes kits for several, and the work in every export is the same: hold the meaning steady while the words change. The note in tune. The loop where the player put it. The tail still ringing when the key comes up.

None of this is visible when it works. You load the kit, play middle C, and it is in tune. The only sign anyone did anything is what you do not hear.

SoundEdit is on the Mac App Store, from the people who made Wave Editor and Sample Manager.

And if your product has to speak somebody else’s file format like a native: that is the day job. audiofile.engineering/engineering.