An SFZ file can carry an audio file inside it, in a <sample> header, so that one file holds the instrument and its sound. These notes are in our words, from docs/headers/sample.md and its C encoder docs/assets/src/makesample.c (sfz-format repository, sfzformat.com), and from the sfizz source (Synth.cpp handleSampleOpcodes, utility/Base64.h, Parser.cpp).
The header
<region> sample=mysample.wav
<sample> name=mysample.wav data=[encoded-content-of-mysample.wav]
name is the file name that a region’s sample uses; the data is the audio file itself (a WAV in the examples), stored as text. There are two encodings.
Rapture’s encoding: data=
sfzformat.com describes the encoding of the Rapture instrument. Each byte is stored as one character: the byte plus 0x2A, modulo 256. If that character would be one of the “forbidden characters” 0x3D (=), 0x00, 0x09, 0x0A, 0x0D or 0x24 ($), the encoder writes the escape character = followed by the byte plus 0x40, modulo 256. The data ends with the end marker $ (0x24). A reader skips CR and LF, turns each plain character back into (character - 0x2A) and each = pair into (second - 0x40), modulo 256, and stops at the end marker. (The page’s own prose for decoding has two typing slips, b1 and b2 mixed; the C encoder is exact, and the decoder here is its inverse.) A WAV file is easy to spot: its first four bytes, RIFF, are written as |spp. The page also gives the 256-entry alphabet as a table; a script checked all 256 entries of it against the rule above and found them equal.
The viewer reads data= under <sample> as such: the value runs to the end marker (so it may hold anything, even < or a line end), is decoded, and opens as a file inside this one (the Open button), named by name. sfizz does not read data=: its source says “the sample data provided … doesn’t use base64 encoding, which is the only one sfizz knows how to decode” and skips the sample. The decoder was checked by encoding files with the real makesample.c.
sfizz’s encoding: base64data=
sfizz reads name= and base64data=. The data is standard base64 (A–Z, a–z, 0–9, +, /, up to two = of padding at the end); spaces, tabs and line ends are ignored; any other character, or a single character left over, makes the whole data empty. Its parser reads the value of base64data to the next < or #, “ignoring comments”, so the data may span many lines. The value is trimmed before it is decoded. The viewer decodes it the same way and opens it as a file.
Using an embedded sample
A region names the embedded file by its name. The viewer’s Samples tab marks such a region’s sample as an embedded <sample>, and its Embedded samples tab lists each one with its encoding and decoded size. A <sample> without a name, or without data, is reported as a problem (sfizz returns without loading when the name is empty).