The BODY chunk holds the samples: signed 8-bit values from −128 to 127. If
sCompression in the voice
header is not 0, the whole chunk must be decompressed first, and everything on this
page then applies to the result. An odd-length chunk has a pad byte.
Samples
Each sample is one byte, a signed two’s-complement number: 0x00 is
silence, 0x7F is +127 and 0x80 is −128. This differs from the
unsigned 8-bit samples of WAV files, where silence is 0x80. There is no
header in the body: the first byte is the first sample.
The sampling rate is the 16-bit samplesPerSec of the voice header, so at
most 65,535 Hz. In the 400 real files this page was checked against, the rates run from
740 Hz to 37,286 Hz, with a median of 9,888 Hz. A rate of 0 cannot be played at.
The volume field does not change the stored samples. It is the level at
which an Amiga plays them, so that the samples themselves can use their whole range.
A decoder that wants a plain waveform can ignore it; a player multiplies by it.
Octaves
The body can hold the same sound at several octaves. They are stored from the highest pitch to the lowest, each one in two parts: first the one-shot part, played once, then the repeating part, which plays as long as the note is held. Each lower octave has twice as many samples as the one above it, covering the same number of cycles.
| Octave | Samples |
|---|---|
| 0, highest | oneShotHiSamples + repeatHiSamples |
| 1 | 2 × that |
| 2 | 4 × that |
| n | 2n × that |
The body holds (2ctOctave − 1) × (oneShotHiSamples
+ repeatHiSamples) samples in all. A three-octave sound of 100 samples in
its highest octave holds 100 + 200 + 400 = 700 samples.
Octave example
The specification’s example has oneShotHiSamples 24,
repeatHiSamples 16, samplesPerHiCycle 8 and
ctOctave 3. Every octave has the same 5 cycles (3 one-shot and 2
repeating), but the cycles are 8 samples long in the highest octave, 16 in the next
and 32 in the lowest.
| Octave | One-shot samples | Repeat samples | Body offset | Samples |
|---|---|---|---|---|
| 1, highest | 24 | 16 | 0 | 40 |
| 2 | 48 | 32 | 40 | 80 |
| 3, lowest | 96 | 64 | 120 | 160 |
The body is 40 + 80 + 160 = 280 bytes, which is (23 − 1) × 40. When the counts in the voice header and the length of the body do not agree, a player cannot know where the octaves start. The viewer on this site then shows the whole body as one waveform and marks the mismatch.
Playing a voice
As a one-shot sound: pick an octave (the lowest-frequency octave has
the most samples and so the best resolution), play its one-shot samples and then its
repeat samples once, at samplesPerSec, scaled by the volume and perhaps
the envelope.
As a musical note: pick the octave nearest the pitch wanted, play the
one-shot part, then play the repeat part again and again for as long as the note lasts.
For the highest octave the frequency is the playback rate divided by
samplesPerHiCycle, and each lower octave is an octave lower at the same
rate. A player needs the samplesPerHiCycle value to tune a note, and
ignores samplesPerSec.
To avoid clicks, the one-shot part should start near zero, and the end of the repeat
part should flow into its own start. repeatHiSamples divided by
samplesPerHiCycle should be a whole number of cycles. Real files do not
always follow this: of the 400 files checked, 67 have a repeat part, and 57 have
samplesPerHiCycle 0.
The Amiga’s sound hardware needs an even number of samples in each one-shot and
repeat part. The specification asks a driver to adjust an odd part or ignore the voice.
Some drivers also need samplesPerHiCycle to be a power of two.
The viewer plays the samples of each octave in turn. For a voice with a repeat part it also builds a looped preview: the one-shot part, then the repeat part of the lowest octave repeated until it fills about three seconds. This is one way to hear a loop; it is not something the file stores.
Stereo
A CHAN value of
6 means stereo. The body is then the left channel’s data followed by the right
channel’s, the two the same length: the channels are not interleaved. The counts in
the voice header are for one channel, so each half of the body has the octave layout
above. With SEQN chunks, repeatHiSamples is the body length
divided by two for stereo.
A value of 2 or 4 is one channel of samples meant for the left or right speaker. In
the 400 real files checked, 111 are marked right (4), 24 stereo (6) and 6 left (2); the
others have no CHAN chunk. Those marked right are ordinary mono sounds:
the viewer plays them in both ears and says which side the chunk asks for.
Fibonacci-delta compression
With sCompression 1, each sample is stored as a 4-bit code, an index into
a table of differences from the previous sample. The method roughly halves the data and
adds distortion; the specification advises against it for instruments.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 1 | pad | a pad byte, ignored |
| 1 | 1 | initial | the starting value, as a signed byte |
| 2 | n − 2 | codes | 4-bit codes, two to a byte, the high nibble first |
| Code | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Delta | −34 | −21 | −13 | −8 | −5 | −3 | −2 | −1 |
| Code | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|
| Delta | 0 | 1 | 2 | 3 | 5 | 8 | 13 | 21 |
Decoding starts from the initial value. For each code, add its delta to the running value and output the result as the next sample. A body of n compressed bytes decodes to 2 × (n − 2) samples.
Compressed stereo is two such streams one after the other, the left channel’s then the right channel’s, each with its own pad byte and initial value (below).
A worked example, with the bytes 00 40 89 7B:
| Step | Code | Delta | Output |
|---|---|---|---|
| initial | 64 | ||
high nibble of 89 | 8 | 0 | 64 |
low nibble of 89 | 9 | 1 | 65 |
high nibble of 7B | 7 | −1 | 64 |
low nibble of 7B | 11 | 3 | 67 |
The initial value is not itself output, so the four codes give four samples: 64, 65, 64 and 67.
Running past the range. The reference decoder keeps the running value in a signed byte, so a sum above 127 or below −128 wraps round. FFmpeg clips such a sum to 127 or −128 instead. The two give the same samples unless a code takes the value out of range; the viewer follows the reference code, wraps, and says how many codes do.
Which nibble first: the high one. The specification’s C code says so
in a comment (“Decode a data nybble; high nybble then low nybble”) and in the code
(if (i & 1) d &= 0xf; else d >>= 4;: even positions take the high
nibble). Two independent Amiga-side programs do the same: Wilhelm Noeker’s
wavepak (y += fibtab[c>>4] first, then
fibtab[c & 0xf]) and Sander van der Burg’s lib8svx
(compressedByte >> 4 for even offsets). FFmpeg’s decoder alone takes the
low nibble first (table[d & 0xF], then table[d >> 4]), so its
output equals the correct decoding with the two nibbles of every byte swapped. The viewer
uses the high nibble first.
Odd points. lib8svx also outputs the initial value as the first
sample, giving 2 × (n − 2) + 1 samples; the specification’s code does not, and neither does
this page. wavepak, the compressor, writes a pad byte of 0, then the initial value
(the first sample when the channel has an odd number of samples, otherwise 0, so the first code
follows from 0), then the codes, and pads an odd-length packed body with 0x88
(two zero deltas).
Compressed stereo
The registered CHAN text only says that a stereo body holds the left data and
then the right data, and the Fibonacci text describes one stream. The program that writes it
is wavepak: with CHAN = STEREO it packs the left half of the
uncompressed body and then the right half as two separate streams, each starting with its
own pad byte and initial value (pack_body(oldbody/2, "left") then
"right"), and it unpacks them the same way. FFmpeg divides the body in two and
decodes each half as its own stream, and so does the viewer.
Exponential-delta
sCompression 2 is Wilhelm Noeker’s “Exponential Delta”, written by his freeware
Amiga program wavepak 1.3 (26 October 1996, with C source; Aminet
mus/misc/wavepak). Its Aminet readme says it is “not an official standard (yet?)”: the
EA text defines only the codes 0 and 1 (“can be more kinds in the future”), and
wavepak “sets sCompression=2”. It works exactly as the Fibonacci delta above
(pad byte, initial value, two codes to a byte, high nibble first, the running value
wrapping in a signed byte, stereo as two streams) with this table of powers of two. The
documentation notes that Michael Henke’s PSMP player already reads it and that some players
treat every non-zero value as Fibonacci. FFmpeg reads it too (with the low nibble first, as
for code 1). The viewer labels it “not in the EA specification”.
| Code | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Delta | −128 | −64 | −32 | −16 | −8 | −4 | −2 | −1 |
| Code | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|
| Delta | 0 | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
ADPCM2 and ADPCM3
sCompression 3 and 4 are written by Lorence Lombardo’s Amiga program 8svx_comp 1.3 (2006 to 2010; Aminet mus/misc/8svx_comp, with Blitz Basic and 68000 assembler source). Its readme says that 1 and 2 were already taken, so ADPCM2 (two bits a sample, a quarter of the size) is number 3 and ADPCM3 (three bits a sample, about 2.7 times smaller) is number 4. Neither is in the EA specification. The coders are Christian Buchner’s 1993 ADPCM routines (the adaptive step of ZyXel’s scheme). The program reads and writes them inside an ordinary 8SVX file: the VHDR keeps the sample counts of the uncompressed sound and only sCompression changes, and the BODY is the packed codes with no header bytes. The viewer labels both “not in the EA specification”.
The decoder keeps two 16-bit numbers: an estimate that starts at 0 and a delta that starts at 5. Each code is a sign bit (its top bit) and a magnitude (the other bits). To decode a code, first take half the delta, rounded down, and add the delta once for each step of magnitude (all in 16-bit arithmetic). Subtract that amount from the estimate when the sign bit is set and add it otherwise. The sample is the estimate shifted right by six bits, held to −128 to 127. Then the delta is replaced by (delta × factor + 8192) shifted right by 14, where the factor depends on the magnitude and the multiplication uses the low 16 bits of the delta.
| Code | Bits | Magnitudes and factors | Packing |
|---|---|---|---|
| 3, ADPCM2 | 2 | 0: 0x3800; 1: 0x5600 (one delta added) | four codes a byte, the first in the top two bits |
| 4, ADPCM3 | 3 | 0: 0x399A; 1: 0x3A9F; 2: 0x4D14; 3: 0x6607 (that many deltas added) | eight codes in three bytes, the first in the top three bits, no gaps; the length must be a multiple of three |
The program does not restart the coder for a stereo body: it treats the whole BODY as one stream, so the left channel’s samples come first and the right channel’s follow with the state carried over; the viewer decodes it the same way and gives each channel half of the samples. The program’s own decoder refuses codes above 4.
SoundFX’s 16-bit forms
SoundFX writes a BITS chunk (Other chunks). When BITS says 16 and there is no LBDY, the BODY holds 16-bit samples: with sCompression 0 plain signed words, high byte first (as in 16SV); with 1 or 2 delta codes of 6 bits and 5 bits that no document describes and that were read from SoundFX’s own code. They are the same codes as the 16SV forms, so the packing, the two tables and the channel order are written out once, under SoundFX’s delta codes on the 16SV pages. In short: a signed 16-bit first sample, then one code for each further sample, the codes packed most significant bit first; a stereo body is the left channel’s packed data, then the right’s, each with its own first sample. A CHAN 30 (quadro) body is four whole channel runs one after another (as stereo is two), in SoundFX’s channel order 0 to 3, written by the same per-channel routines as stereo (SoundFX 4.3 IFF-8SVX_S.sfxmod, which calls the library’s save vector with 2 channels for stereo and 4 for quadro and bounds the loop by the channel count it holds). There are no padding codes: the leftover samples of the last group are written as the leading bytes of that group, as described under SoundFX’s delta codes.
The odd last sample. SoundFX works out the coded size of a channel as a number of bytes and truncates it, with no rounding (sfxsupport.library, the conversion at offset 0x1ec10). For the 4-bit form the size is the two header bytes plus half the remaining samples, which is floor(n / 2) + 1 bytes for n samples. A channel with an odd number of samples therefore loses its last sample when SoundFX saves it. A reader that decodes two samples for each byte after the two header bytes, as the viewer does, gets exactly the samples the file holds.
The same reading shows that SoundFX’s 4-bit forms (BITS 8) put the first sample’s high byte in the first byte of the packed data, where EA’s text has a pad byte, and the second sample’s high byte in the second byte, the starting value. A reader that follows EA’s text, as the viewer does, ignores the first byte and so plays two samples less at the start than SoundFX holds. The loader of SoundFX itself plays the two bytes as the first two samples.
Source: 8SVX IFF 8-Bit Sampled Voice (EA, 1985): Data Chunk BODY (octave layout, the sample-count formula, Figure 2’s example of 24, 16, 8 and 3 octaves), Appendix C Fibonacci Delta Compression (the sixteen deltas and the C code D1Unpack and DUnpack, high nibble first); the CHAN and SEQN paragraphs: the registered supplements 8SVX.CHAN.PAN (David Jones) and 8SVX.SEQN.FADE (Peter Norman) on the same wiki page. The text was read in EA’s own copy (Amiga Developer CD 2.1, Extras/IFF/Old_IFF_Packages/March_1986/iff.text/8svx; the same words are on Fish disks 16 and 64) as well as the wiki transcription. The delta tables, the nibble order and the worked example were checked against the text, the C code, wavepak 1.3 (Wilhelm Noeker, Aminet mus/misc/wavepak: wavepak.c and wavepak.doc) and lib8svx’s fibdelta.c by script.