A Monkey’s Audio file starts with the signature MAC and a 16-bit version: the
program’s version times 1000, so 3990 means version 3.99. All numbers are little-endian.
The layout changed in version 3.98, so a reader chooses a path from the version.
Signature and version
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 0 | 4 | char[4] | cID | MAC , with a trailing space |
| 4 | 2 | uint16 | nVersion | Version × 1000. Below 3980 the old header follows; from 3980 the descriptor does |
The SDK allows other data before the signature, so that files with an ID3v2 tag still work, but advises against adding it. The offsets below count from the signature, and FFmpeg calls the distance to it the junk length.
FFmpeg accepts versions 3800 to 3990. The SDK decodes 3000 to 3990 (the older ones with its Old/
code, described in the table below) and, as a special case, exactly 4110, which it treats as
3990; it refuses every other version (APE_ERROR_UNSUPPORTED_FILE_VERSION).
Descriptor (version 3980 and later)
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 0 | 4 | char[4] | cID | MAC |
| 4 | 2 | uint16 | nVersionEncoder | File format version × 1000 (3990 for the SDK’s files of the last twenty years) |
| 6 | 2 | uint16 | nVersionProgram | Version of the program that wrote the file × 1000, starting with 13.17 (13170). FFmpeg calls these two bytes padding; files written before the field existed have 0 there |
| 8 | 4 | uint32 | nDescriptorBytes | Size of the descriptor; 52 here. If larger, skip the extra bytes |
| 12 | 4 | uint32 | nHeaderBytes | Size of the header that follows; 24 here |
| 16 | 4 | uint32 | nSeekTableBytes | Size of the seek table |
| 20 | 4 | uint32 | nHeaderDataBytes | Size of the original file’s data before its audio (the WAV header) |
| 24 | 4 | uint32 | nAPEFrameDataBytes | Size of the compressed frames, low 32 bits |
| 28 | 4 | uint32 | nAPEFrameDataBytesHigh | The same, high 32 bits |
| 32 | 4 | uint32 | nTerminatingDataBytes | Size of the original file’s data after its audio, not counting tags |
| 36 | 16 | uint8[16] | cFileMD5 | MD5 hash of the file, as described below |
Notes
- ID.
MACfor a file of integer samples;MACFfor one of 32-bit floating-point samples (format flag 0x1000). The SDK’s reader accepts both. - Sizes. The descriptor, the header, the seek table and the stored WAV header follow one another, each with its size here, so a reader finds the first frame at
nDescriptorBytes + nHeaderBytes + nSeekTableBytes + nHeaderDataBytesfrom the marker. A descriptor or header longer than the SDK writes (52 and 24 bytes) is skipped over past the fields it knows. - Frame data bytes (low and high words together) count the frames up to and including the last 4-byte word of the last frame, so the frames end at
first frame + nAPEFrameDataBytes; the terminating data follows, then the tags. - Limits the SDK enforces. 1 to 32 channels; blocks per frame above 0, and up to 1,000,000 (10,000,000 at level 5000, and for any level in a file before 3.98); a final frame no longer than a full frame; a seek table no larger than the file; a stored WAV header or trailer up to 8 MiB.
The file MD5
Files from version 3.98 on record an MD5 in the descriptor. It is the MD5 of these byte ranges, in this order:
- the stored WAV header (
nHeaderDataBytesbytes; none when flag 0x20 is set), - the frame data, including its last word (
nAPEFrameDataBytesbytes), - the terminating data (
nTerminatingDataBytesbytes), - the 24-byte header, as stored,
- the whole seek table.
The descriptor itself is left out, which is how it can hold the result. The explorer’s Checks section computes this and compares it. A file whose encoder did not fill it in has 16 zero bytes. This order is taken from the SDK’s writer; no complete file from a real encoder was available to test it against, so it is checked only against the files the research encoder wrote.
Header (version 3980 and later)
The header follows the descriptor, usually at offset 52.
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 0 | 2 | uint16 | nCompressionLevel | Compression level |
| 2 | 2 | uint16 | nFormatFlags | Format flags |
| 4 | 4 | uint32 | nBlocksPerFrame | Audio blocks (samples per channel) in a frame |
| 8 | 4 | uint32 | nFinalFrameBlocks | Blocks in the last frame |
| 12 | 4 | uint32 | nTotalFrames | Number of frames |
| 16 | 2 | uint16 | nBitsPerSample | Bits per sample |
| 18 | 2 | uint16 | nChannels | Channels |
| 20 | 4 | uint32 | nSampleRate | Sample rate in hertz |
The total number of blocks is
nFinalFrameBlocks + nBlocksPerFrame × (nTotalFrames − 1).
Old header (before version 3980)
Older files have one 32-byte header, then optional fields controlled by its flags.
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 0 | 4 | char[4] | cID | MAC |
| 4 | 2 | uint16 | nVersion | Version × 1000 |
| 6 | 2 | uint16 | nCompressionLevel | Compression level |
| 8 | 2 | uint16 | nFormatFlags | Format flags |
| 10 | 2 | uint16 | nChannels | 1 or 2 |
| 12 | 4 | uint32 | nSampleRate | Sample rate in hertz |
| 16 | 4 | uint32 | nHeaderBytes | Bytes of WAV header stored after the MAC header |
| 20 | 4 | uint32 | nTerminatingBytes | Bytes stored after the audio |
| 24 | 4 | uint32 | nTotalFrames | Number of frames |
| 28 | 4 | uint32 | nFinalFrameBlocks | Blocks in the last frame |
| 32 | 4 | uint32 | nPeakLevel | Only with flag 4 |
| 32 or 36 | 4 | uint32 | nSeekElements | Only with flag 16: entries in the seek table. Without it there is one per frame |
Values the old header implies
| Value | Rule |
|---|---|
| Bits per sample | 8 with flag 1, 24 with flag 8, otherwise 16 |
| Blocks per frame | 294,912 (73,728 × 4) from version 3950 |
| 73,728 from version 3900, or from 3800 at compression level 4000 or above | |
| 9,216 otherwise |
Format flags
| Value | Name | Meaning |
|---|---|---|
| 1 | MAC_FORMAT_FLAG_8_BIT | 8-bit samples (obsolete) |
| 2 | MAC_FORMAT_FLAG_CRC | Uses CRC-32 error detection (obsolete) |
| 4 | MAC_FORMAT_FLAG_HAS_PEAK_LEVEL | A 32-bit peak level follows the header (obsolete) |
| 8 | MAC_FORMAT_FLAG_24_BIT | 24-bit samples (obsolete) |
| 16 | MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS | The number of seek elements follows the peak level |
| 32 | MAC_FORMAT_FLAG_CREATE_WAV_HEADER | No WAV header is stored; create one on decompression |
| 64 | APE_FORMAT_FLAG_AIFF | The original file was an AIFF, not a WAV: the decoder writes AIFF |
| 128 | APE_FORMAT_FLAG_W64 | The original was a Sony Wave64 |
| 256 | APE_FORMAT_FLAG_SND | The original was a Sun or NeXT SND (AU) file |
| 512 | APE_FORMAT_FLAG_BIG_ENDIAN | The original samples were big-endian (the decoder swaps them back) |
| 1024 | APE_FORMAT_FLAG_CAF | The original was an Apple CAF |
| 2048 | APE_FORMAT_FLAG_SIGNED_8_BIT | 8-bit values were signed in the original (AIFF, CAF, AU) |
| 4096 | APE_FORMAT_FLAG_FLOATING_POINT | The samples are 32-bit IEEE floats (the file ID is then MACF) |
The names and values come from the SDK’s header file (version 13.46 of the program). Bits 13 to 15 are not defined; the explorer marks them “unknown” when set. In a version 3.98 header the obsolete flags 1, 2, 4, 8 and 16 are not needed: the header has its own bits-per-sample field, every frame has a CRC, and the seek table size is in the descriptor. A flag may still be set in such files; a reader ignores it. The 8-bit, 24-bit, peak-level and seek-element flags matter only to the old header.
Compression levels
| Value | Name |
|---|---|
| 1000 | Fast |
| 2000 | Normal |
| 3000 | High |
| 4000 | Extra high |
| 5000 | Insane (FFmpeg rejects this level below version 3930) |
Each level selects the filters the decoder runs. Nothing else is a level: the SDK’s encoder rejects any other value, so a header with 2500, or with a higher number such as 6000, is not a file this format describes, and the explorer reports it as not a level the SDK defines.
Blocks per frame by level
A version 3.98 or later header stores the number of blocks in a frame. The SDK’s encoder sets it from
the level: 73,728 for fast, normal and high; four times that (294,912) for extra high; sixteen times
(1,179,648) for insane. A decoder reads the number from the header and does not need the rule. The
test file NoLegacy-cut.ape (high, 24-bit) and luckynight-partial.ape (normal)
both have 73,728.
Seek table
After the header comes one 32-bit little-endian number for each frame: the offset of the frame’s first
byte from the MAC marker. A file over 4 GiB wraps the numbers: an entry smaller than the
one before means one more 232 has to be added. The frames
page explains the low two bits, which tell how far into a 4-byte word the frame starts. In a file
of version 3.98 or later the table has exactly nTotalFrames entries, and the first entry
is the offset of the first frame. A file before 3.98 with flag 16 may have a different count in its
header; the entries still belong to the first frames. The explorer reports a table with fewer entries
than frames, and one whose first entry is not where the frames start.
Bit table (version 3.80 and older)
In a file of version 3800 (3.80) or older one byte per frame follows the seek table: how many bits into its
first byte the frame starts. The frames of every later version start on a byte. The rule is
version <= 3800 in the SDK (APEHeader.cpp, AnalyzeOld) and
version < 3810 in FFmpeg (ape.c lines 257 and 306); no version lies between the two
limits, so they agree. The test files luckynight-mac380-c2000.ape
and -c4000.ape have one.
The stored WAV header and trailer
Monkey’s Audio keeps enough of the original file to write it back byte for byte. The bytes of the
original before its sound (nHeaderDataBytes, usually the 44-byte RIFF/WAVE header) sit after
the seek table; the bytes after its sound (nTerminatingDataBytes: a LIST chunk,
an ID3 tag, anything) sit after the frames, before the APE tag. The explorer reads both as RIFF chunks
when the format flags do not say the original was an AIFF, Wave64, SND or CAF file, and checks the
fmt chunk against the APE header (channels, rate, bits) and the data chunk
size against the number of blocks.
With flag 32 no header is stored (nHeaderDataBytes is 0) and the decoder builds the usual
44-byte WAV header from the format fields; for 4 GiB of sound or more it builds an RF64 header instead.
The explorer rebuilds the original file the same way (the “Original file” entry: header, samples, trailer),
and the result equals what the SDK’s decompressor writes.
The header the decoder builds (flag 32)
Both come from the SDK’s FillWaveHeader and FillRF64Header. The format chunk is always
plain PCM (format tag 1, 16 bytes), whatever the samples are, even for a floating-point file. All numbers
are little-endian; audio is blocks × channels × bytes per sample, and trailer the
terminating data bytes.
| Offset | Size | 44-byte RIFF header | 80-byte RF64 header (audio ≥ 4 GiB) |
|---|---|---|---|
| 0 | 4 | RIFF | RF64 |
| 4 | 4 | audio + 36 + trailer | 0xFFFFFFFF |
| 8 | 4 | WAVE | WAVE |
| 12 | 4 | fmt | ds64 |
| 16 | 4 | 16 | 28 (the ds64 chunk size) |
| 20 | 16 / 8 | tag 1, channels (2), rate (4), bytes a second (4), block align (2), bits (2) | RIFF size: 80 + audio − 8 (8 bytes) |
| 28 | 8 | (the fields above continue to 36) | data size: audio |
| 36 | 4 / 8 | data | sample count: audio ÷ block align (blocks) |
| 40 | 4 | audio (0xFFFFFFFF from 4 GiB) | (the sample count continues) |
| 44 | 4 | (the sound starts) | table length: 0 |
| 48 | 4 + 4 | fmt , 16 | |
| 56 | 16 | tag 1, channels, rate, bytes a second, block align, bits | |
| 72 | 4 + 4 | data, 0xFFFFFFFF |
The samples follow in the layout of the original file: little-endian unless flag 512 says big-endian; 8-bit samples unsigned unless flag 2048 says signed; the trailer after them.
Versions and what they changed
| File version | What changes (for a reader) |
|---|---|
| 3000 to 3790 (3.00 to 3.79) | Same single 32-byte header and bit-packed frames as 3.80 (with the bit table, 9,216 blocks a frame at every level), frame check a 32-bit CRC when flag 2 is set, otherwise the Rice-coded (parameter 30) sum of absolute sample values, 0 meaning silence; 8-bit samples are unsigned bytes. The predictor changes at 3320 (fast and normal replaced; high and extra high take a new first stage), 3600 and 3700 (high and extra high); extra high begins each channel with a count (4 bits below 3320, else 3 bits) and then count + 1 pairs of coefficients (6 bits each; 5 bits from 3320 to 3599). Read from the SDK 13.46 Old/ source. |
| 3800 (3.80) | Oldest files FFmpeg reads. Old header, bit table after the seek table, CRC stored with all 32 bits, bit-oriented entropy code (3.80 to 3.85 Rice code with running sums), 9,216 blocks a frame (73,728 at level 4000) |
| 3810 to 3820 | No bit table; frames start on a byte |
| 3821 and later | Bit 31 of the stored CRC says that a word of special codes (silence, pseudo-stereo) follows; the CRC drops its lowest bit |
| 3860 | Rice code with a running parameter (3.86 to 3.89) |
| 3890 (above 3880) | A long run of the Rice code’s unary part (16 or more) raises the parameter by 4 instead of being sent in full |
| 3900 | Range coder; the stored CRC and the special codes are whole bytes in the stream; 73,728 blocks a frame |
| 3910 | The range coder’s bit counts can exceed 16 |
| 3930 | NN filters, the four-tap predictor, stereo channels interleaved in the stream, level 5000 |
| 3950 | The new predictor with its cross-channel second stage; 294,912 blocks a frame in the old header |
| 3980 | The descriptor layout (this page’s first tables), the new NN-filter adaptation |
| 3990 | The range coder’s symbol table and pivot-based escape (entropy page); what every encoder since writes, whatever the program version |
How each row is known. Verified (V, a real file written by that version’s encoder
was parsed, decoded and its checks passed): 3.80, 3.88, 3.89, 3.90, 3.91, 3.92, 3.94, 3.96, 3.97 and 3.99
(3.90 and 3.96 from the mutagen and TagLib test files; the others from FFmpeg’s and the project’s own
sample files). Verified from the program itself (V, the 3.51 and 3.80 installers’ MAC.dll and
MAC_Info.dll disassembled, never run): version 3.51 writes MAC , 3510, the level,
flags 6 (CRC and peak level; 7 for 8-bit, 14 for 24-bit), channels, rate, the header bytes, the terminating
bytes, the frame count and the final frame, 9,216 blocks a frame at every level, and its reader takes the 32-byte
header, 4 bytes of peak level when flag 4 is set, the stored WAV header, a seek table of 4 bytes a frame and then
a bit table of 1 byte a frame; it accepts levels 1000 to 4000 only. Version 3.80 writes the same fields with
3800, flags 6, 7 or 14, and 9,216 blocks a frame, or 73,728 at level 4000. Inferred (I, read from source and
not checked against a file or a binary): 3.00 to 3.50, 3.52 to 3.79, 3.81 to 3.87 and 3.95; no installer
or encoder file of these versions could be obtained, and the encoder that wrote them cannot be run. The sources agree with each other for the old header: the 3.51 Winamp-plugin
MAC.h (version 3510: the 32-byte structure with flags 1, 2, 4 and 8, 9,216 blocks a frame),
the 4.12 and 13.46 SDKs (APEHeader.cpp), FFmpeg (ape.c) and Rockbox
(libdemac/parser.c, which also sets 73,728 × 4 blocks from 3950 and 73,728 from 3900, or from
3800 at level 4000 and above). Rockbox’s player refuses files below 3970. The 3.88 SDK’s
MACDll.dll (disassembled, never run) builds its header with MAC , 3880, flags 6, 7
or 14, and the SDK headers of 3.88, 3.95 (alpha 2), 3.96 (beta 1, in its Source folder), 3.97 and 3.98 (alpha 1) define the file
version as 3880, 3950, 3960, 3970 and 3980 in the same way.
The program’s own version is a separate number: Monkey’s Audio 4.x, 5.x … 13.x all write 3990. This was
read from the 4.11 installer itself: its MACDll.dll returns 3990 (mov eax, 0xf96)
from GetVersionNumber, and the 4.12 SDK names the same value MAC_FILE_VERSION_NUMBER
beside the program version 4.12. So the 4.11 program writes ordinary 3990 files. The program history also
records that files with the version 4110 (“a couple of reports; origin unknown”) decode with the current
code: the SDK accepts exactly the file version 4110 and decodes it as 3990. A 3.99 file with its version
changed to 4110 decodes to the same samples. No program writes 4110; the origin of those files is not known.
These boundaries are the places FFmpeg’s decoder and the SDK switch code.
Worked example
The start of luckynight-partial.ape, a version 3.99 file at Normal level, 16-bit stereo at
44,100 Hz (from FFmpeg’s test suite; the file is cut after 1 MiB, which is why the frame data is
larger than the file):
00 4D 41 43 20 "MAC "
04 96 0F nVersionEncoder 3990
06 00 00 nVersionProgram 0 (not recorded)
08 34 00 00 00 nDescriptorBytes 52
0C 18 00 00 00 nHeaderBytes 24
10 94 00 00 00 nSeekTableBytes 148 (37 frames)
14 2C 00 00 00 nHeaderDataBytes 44 (a WAV header is stored)
18 D8 54 63 00 nAPEFrameDataBytes 6,509,784
1C 00 00 00 00 nAPEFrameDataBytesHigh 0
20 00 00 00 00 nTerminatingDataBytes 0
24 81 47 91 1A F3 F0 60 23 67 03 AC 65 57 EE 6A 7C cFileMD5
34 D0 07 nCompressionLevel 2000 (normal)
36 00 00 nFormatFlags 0
38 00 20 01 00 nBlocksPerFrame 73,728
3C A0 32 00 00 nFinalFrameBlocks 12,960
40 25 00 00 00 nTotalFrames 37
44 10 00 nBitsPerSample 16
46 02 00 nChannels 2
48 44 AC 00 00 nSampleRate 44,100
4C 0C 01 00 00 seek table: frame 0 at 268
50 10 0E 02 00 frame 1 at 134,672 …
E0 52 49 46 46 … "RIFF" …, the 44-byte WAV header, then the first frame at 268 (0x10C)
Total blocks: 36 × 73,728 + 12,960 = 2,667,168, which at 44,100 Hz is 60.5 seconds.
The start of luckynight-mac391b1-c2000.ape, written by Monkey’s Audio 3.91 beta 1 (an old
header, flags 0x16: CRC, peak level and seek elements):
00 4D 41 43 20 "MAC "
04 46 0F nVersion 3910
06 D0 07 nCompressionLevel 2000
08 16 00 nFormatFlags 0x16
0A 02 00 nChannels 2
0C 44 AC 00 00 nSampleRate 44,100
10 2C 00 00 00 nHeaderBytes 44 (stored WAV header)
14 00 00 00 00 nTerminatingBytes 0
18 25 00 00 00 nTotalFrames 37
1C A0 32 00 00 nFinalFrameBlocks 12,960
20 15 7D 00 00 nPeakLevel 32,021 (flag 4)
24 25 00 00 00 seek elements 37 (flag 16)
28 52 49 46 46 … the stored WAV header (44 bytes), then the 148-byte seek table, then the frames
Here the blocks per frame (73,728) come from the version, since the header does not store them.
Source: Monkey’s Audio SDK 13.46 (MAC_1346_SDK.zip from monkeysaudio.com): Shared/MACLib.h (APE_DESCRIPTOR, APE_HEADER, the compression levels, the format flags, which the SDK calls APE_FORMAT_FLAG_* where FFmpeg’s ape.c keeps the older MAC_FORMAT_FLAG_* names for the first six), Source/MACLib/APEHeader.h and APEHeader.cpp (the pre-3980 header, the blocks-per-frame rules). There is no separate official file-format document: monkeysaudio.com’s developers page holds no format notes. The table of file versions below is taken from the program’s version history, not from a specification. Every offset, width, flag and level above is compared with the SDK by scripts/ape/spec-check.mjs.