The MDAT chunk is the sound: the sample frames one after the other, with nothing else between
them. A frame is one sample from every channel: first the left channel, then the right, then any others
(as Channels in the header says). All values are big-endian.
Bit packing
The bits of the samples are really packed: a sample of 3 bits takes 3 bits, not a byte or a word. The bits of a byte are used from the most significant down. This is Richard Koerber’s drawing, for 3-bit samples, 2 channels and no compression:
| byte 1 | byte 2 | byte 3 | |
|---|---|---|---|
| bit of the byte | 76543210 | 76543210 | 76543210 |
| channel | lllrrrll | lrrrlllr | rrlllrrr |
| bit of the sample | 21021021 | 02102102 | 10210210 |
So frame 1 is the first six bits of byte 1 (left lll, right rrr), and frame 2 starts with the last two bits of byte 1 and goes on in the first four bits of byte 2.
The number of frames is the size of MDAT in bits ÷ (SampleSizeC × Channels); whole bytes left over after the last whole
frame are not played, and the viewer says how many. With SampleSizeC a multiple of 8 every sample is a whole number of
bytes and clicking a waveform selects its bytes.
More examples from maud.doc
MacroSystem’s own document draws the same packing for other sizes. In each drawing the lower line says which channel each bit belongs to (l left, r right):
| Samples | Bytes | Channels |
|---|---|---|
| 4 stereo samples with 4 bits each | 32103210 32103210 32103210 32103210 | llllrrrr llllrrrr llllrrrr llllrrrr |
| 3 stereo samples with 3 bits each | 21021021 02102102 10 | lllrrrll lrrrlllr rr000000 00000000 (the last byte, and the byte that follows to reach a word boundary, are zero bits) |
| 2 mono samples with 16 bits each | MSB sample 0, LSB, MSB sample 1, LSB | each sample is two whole bytes, most significant first |
| stereo multichannel, 6 channels | c0l c0r c1l c1r c2l c2r, then c3l c3r c4l c4r c5l c5r, … | a frame is the left and right sample of each channel pair in turn |
The end of the data stream is padded to a word boundary “to follow the IFF rules”. Samples of 8 bits are unsigned: 0 is the minimum analog amplitude and 255 the maximum, “commonly used in the personal computer industry”; 16-bit samples are signed (two’s complement), −32,768 the minimum and 32,767 the maximum, “the standard of representing 16 bit digital audio (compact disk)”.
Sample values with no compression
- A sample of exactly 8 bits is unsigned: 0 to 255 with 128 as silence.
- A sample of any other size, below or above 8 bits, is signed two’s complement.
- Samples are always big-endian.
The 8-bit rule is the format’s author’s, and SoX, OpenMPT, FFmpeg and the explorer follow it. maud.datatype
reads 8-bit samples as signed, which is why the tool ma2s exists (code 11 below). The explorer reads
1 to 32 bits.
Compression codes
The Compression field of the header holds one of these. The names are the constants of MacroSystem’s
maud.i; “16 → 8 bit” and so on are its own comments.
| Code | Name | Meaning | Explorer |
|---|---|---|---|
| 0 | MCOMP_NONE | PCM, packed as above | decoded |
| 1 | MCOMP_FIBDELTA | “Fibonacci Delta Compression as used in 8SVX” | decoded |
| 2 | MCOMP_ALAW | 16 → 8 bit, European PCM standard A-law | decoded |
| 3 | MCOMP_ULAW | 16 → 8 bit, American PCM standard µ-law | decoded |
| 4 | MCOMP_ADPCM2 | 16 → 2 bit, ADPCM compression | named, not decoded |
| 5 | MCOMP_ADPCM3 | 16 → 3 bit, ADPCM compression | named, not decoded |
| 6 | MCOMP_ADPCM4 | 16 → 4 bit, ADPCM compression | named, not decoded |
| 7 | MCOMP_ADPCM5 | 16 → 5 bit, ADPCM compression | named, not decoded |
| 8 | MCOMP_LONGDAT | 16 → 12 bit, used for DAT-longplay | named, not decoded |
| 9 | (unofficial) | floating-point samples, from the aw2m tool | decoded |
| 11 | (unofficial) | 8-bit signed samples, from the ma2s tool | decoded |
The format’s author states that only codes 0, 2 and 3 are used: “I don’t know one single program that saves in other compression modes. Even the multisnd.library does not support other compression modes.”
Code 1: Fibonacci delta
The include file calls code 1 “‘Fibonacci Delta Compression’ as used in 8SVX” and says no more. The format’s author knows of no program that writes it, but SoundFX,
the sample editor by Stefan Kost, does: its IFF-MAUD saver offers “FDPCM8_4: FibonacciDelta (2:1) compressed 8bit” and, for it, writes SampleSizeC 4, SampleSizeU 8 and Compression 1
(read from the saver module’s code, which hands the data itself to the main program, whose code was not examined). The explorer therefore reads the MDAT as an 8SVX Fibonacci-delta body: a pad byte, the
initial value as a signed byte, then two 4-bit codes to a byte, the high nibble first. Each code selects a difference that is added to the
running value, which wraps in a signed byte; the initial value itself is not output. A stream of n bytes gives 2 × (n − 2) samples of 8 bits, signed.
| Code | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Delta | −34 | −21 | −13 | −8 | −5 | −3 | −2 | −1 | 0 | 1 | 2 | 3 | 5 | 8 | 13 | 21 |
With more than one channel, the explorer divides MDAT into one such stream for each channel, one after the other, as a compressed
stereo 8SVX body is laid out (the left channel’s stream, then the right’s, each with its own pad byte and initial value). This arrangement
is the 8SVX convention, not something a MAUD document states. Another arrangement fits the frame model of maud.doc, where the sample size is 4 bits: a frame of one 4-bit code per channel (llllrrrr for stereo); nothing found shows which one SoundFX writes. The bytes 00 40 89 7B as a mono MDAT are the
samples 64, 65, 64 and 67.
Codes 2 and 3: A-law and µ-law
Each sample is one byte of the ITU-T G.711 A-law (code 2) or µ-law (code 3) coding of a 16-bit sample, so SampleSizeC is 8 and
SampleSizeU 16. The explorer decodes a byte through the standard G.711 table and divides by 32,768; all 256 codes of both laws give the
same values as FFmpeg’s decoder.
Codes 4 to 8: not used by any program
The include file names ADPCM to 2, 3, 4 and 5 bits and “LONGDAT” (16 bits to 12, for DAT long play) and gives no algorithm for any of them. What was looked at to find one:
- the author’s own statement, quoted above;
- the readers:
maud.datatypelists “FIBDELTA, ADPCM2-5, LONGDAT” as unsupported; FFmpeg’siff.creads codes 0, 2 and 3 only; SoX and OpenMPT read neither; - the writers:
aw2m, MaudExchange, MakeMAUD andma2swrite or convert none of them; SoundFX’s saver writes PCM of 8, 16, 24 and 32 bits, code 1, µ-law (code 3) and A-law (code 2) and no other code; - MacroSystem’s own binaries, disassembled:
multisnd.library2.0 (12 December 1995, Richard Koerber) andtoccata.library12.0 (1997) compare the compression field only with 2 and 3 and treat everything else as 8 or 16-bit linear samples; neither contains a Fibonacci-delta table; Samplitude Opus 3.5 contains the message “Can’t read compressed MAUD files!”.
There is therefore nothing to derive the algorithms from. The explorer shows the header of such a file, names the code and flags it; it plays nothing.
Code 9: floating point (unofficial)
Lorence Lombardo’s Amiga tool aw2m (AIFF and WAV to MAUD) writes “compression ID 9 for floating point audio. Although this is not really compression it is the same
principal used by AIFC and WAV file types to identify floating point audio”, and hopes it will be accepted as official. The samples are big-endian IEEE 754
numbers; the explorer reads 32 and 64 bits (SampleSizeC) and flags other sizes.
Code 11: signed 8-bit (unofficial)
The Amiga tool ma2s converts an 8-bit MAUD file to signed samples, because maud.datatype reads 8-bit samples as signed and the format says unsigned.
It marks the result with code 11, so that a signed 8-bit file can be told from a standard one. The explorer reads code 11 as signed 8-bit PCM.
Source: Richard Koerber’s message of 8 August 1997 with maud.i (MAUDINFO.TXT): the packing drawing, the 8-bit rule, big-endian, the compression constants and their comments, and the statement quoted above;
the aw2m and ma2s readmes (Aminet) for codes 9 and 11; the maud.datatype guide for its list of unsupported codes; the disassembly of MacroSystem’s libraries and Samplitude for the rest.
The Fibonacci table and the nibble order are EA’s (8SVX Appendix C).