The sources are the libcdio guide “CD Text Encoding and Decoding Guide” (the guide), the
MMC-3 draft revision 10g, Annex J (MMC-3), Sony’s “CD TEXT authoring and mastering”
documents (Sony, with the document number) and libcdio’s source (cdtext.c and
the example cdtext-raw.c). Where they differ, the page says so.
The 18-byte pack
A file is a run of 18-byte packs. Each has a header of four bytes, a text data field of twelve bytes and a CRC field of two (MMC-3 Table J.1; the guide: “Each pack consists of a 4-byte header, 12 bytes of payload, and 2 bytes of CRC”).
| Byte | Field | Meaning |
|---|---|---|
| 0 | Pack type | 0x80 to 0x8f: what kind of text or data the pack holds. |
| 1 | Track | Bit 7 is the extension flag; bits 0 to 6 the track number or pack element number. Below. |
| 2 | Sequence number | Counts the packs of a block from 0. |
| 3 | Block and character position | Bit 7 double-byte flag, bits 4 to 6 block number, bits 0 to 3 character position. |
| 4 to 15 | Text data | Twelve bytes of zero-ended text, or binary data for the types 0x86 to 0x89 and 0x8f. |
| 16 to 17 | CRC | Over bytes 0 to 15, below. |
The header bytes
Pack type (byte 0). The values and their meanings are on the pack types page. MMC-3 says the packs “shall be encoded in the order of the items listed” in its type table, and Sony’s checker (DOC10, rule 1-1) requires the types in a block to rise from 0x80 to 0x8f.
Track (byte 1). MMC-3: the most significant bit is the extension flag,
“normally set to 0b”; if it is 1 the pack “is used for an extended application that is
beyond the scope of this document”. The other seven bits are the track number when the text
belongs to a track; if the pack does not depend on a track, they are a pack element number
that depends on the pack type. The guide: a zero means the information is about the whole
album; for the text types 0x80 to 0x85 and 0x8e the number is the track of the text at
the start of the pack; for the table-of-contents types 0x88 and 0x89 it is a track
number too; for 0x8f it counts the record parts 0 to 2. Sony’s example shows the rule for
a text that began in an earlier pack: the pack 80 01 03 0f carries
eams, the end of track 1’s title, and the start of track 2’s, and has the track
byte 1 (DOC06). Sony’s checker requires the first pack of each new type to have the
track byte 0 (rule 1-10; Sony’s own 0x89 example does not follow it, and the explorer does
not apply the rule to 0x88 and 0x89), requires the disc identification and genre packs to
have 0 (1-11) and the track bytes of the text types not to pass the last track (1-7).
Sequence number (byte 2). MMC-3: “the number incrementally increased from the first Pack to the end in each Block. It starts from 00h to FFh.” The guide: the sequence numbers of each block are counted separately and all packs of block 0 come before those of block 1. Sony’s checker requires them to rise by one from 0 in every block (rule 1-8).
Block number and character position (byte 3). MMC-3 Table J.3 and the guide agree on the three fields:
- Bit 7: the double-byte flag. 0 means single-byte characters, 1 double-byte (below).
- Bits 4 to 6: the block number, 0 to 7: a set of text for one language.
- Bits 0 to 3: the character position, “the number of character in the
strings that belongs to the Text Data Field in the previous Pack” (MMC-3), from 0 to 15,
where 15 means the string began before the previous pack. A double-byte pair counts
as one character and the terminating null counts as a character (MMC-3). In Sony’s
example the pack
80 00 01 0chas 12, because the 12 charactersBILLY JOEL Sof the title in progress filled the previous pack, and80 01 03 0fhas 15 for the 15 characters ofThe River Of Drin the two packs before it (DOC06). The explorer takes the position as the number of characters of the string in progress that lie in earlier packs, at most 15; libcdio’s test filekrosishas 14 where 14 characters were carried, so a position is not forced up to 15 once a string is longer than the previous pack. MMC-3 and Sony’s checker (rule 2-2) say the position is 0 in the packs of types 0x88, 0x89 and 0x8f.
The CRC
MMC-3: the polynomial is X16 + X12 + X5 + 1, “all bits
shall be inverted”, and the field “is not mandatory for supporting CD-TEXT data”; Table J.1
calls the two bytes “CRC Field byte 0 or Reserved”. The guide writes the same rule as a
divisor: 0x11021 over bytes 0 to 15, the 16-bit remainder inverted (xor
0xFFFF) and written big-endian in bytes 16 and 17.
The explorer checks the rule on the ten example packs printed in the guide (all ten agree) and on every pack of Sony’s example file (98 packs, all agree), and reports a pack whose CRC differs as a problem. Because MMC-3 allows the bytes to be reserved, a wrong CRC is a problem and not a reason to refuse the file.
Blocks and the size of a file
The guide: the packs are grouped in up to eight blocks of at most 256 packs, each block for one language, so a file has at most 2048 packs; Sony says the same (DOC08: “the maximum possible number of Packs in a Text Group is 2048 and the recommended number … is less than 512”). MMC-3 says a block “consists of maximum 255 Pack Data” and that a group has “up to 8 types of language Blocks”. The guide adds that the total size of a block’s attribute set is “restricted by the fact that it has to be stored in at most 253 records with 12 bytes of payload”, which leaves room for the three 0x8f packs of the block size record.
Sony’s checker (DOC10) also requires: every block has at least one 0x80 pack and three 0x8f packs (1-2); the block numbers start at 0 and rise by one (1-19); the copyright byte and the first and last track are the same in every block (1-17, 1-18); and if block 0 does not use ISO-8859-1 or ASCII no other block does (1-16). It warns when a file has more than 512 packs (1-4).
How texts are split across packs
The guide: the twelve bytes “contain pieces of zero-terminated data”; “a text may span over several packs. Unused characters in a pack are used for the next text of the same pack type. If no text of the same type follows, then the remaining text bytes are set to 0.” MMC-3 says the same, adds that a string longer than a pack “is continued onto the succeeding Packs” and recommends a string of less than 160 bytes; Sony’s checker warns above 160 (rule 2-1) and wants at least as many terminators as there are tracks (last track minus first track plus one, rule 2-3) in each of the types 0x80 to 0x85. One string for the disc comes first (track 0), then one for each track.
The explorer joins the 12-byte pieces of one type in a block, splits them at the terminators, and numbers the texts from the track byte of each pack. The zeros that pad the last pack of a type after the last track’s text are not shown as texts.
The TAB rule. MMC-3: “in case the same character strings is used for
consecutive tracks, the Tab Indicator may be used to indicate the same as previous track. It
is a single tab code (09h) for single byte codes, and two tab codes for double bytes character
codes. It shall not used for the first track.” Sony’s checker adds that it is not used in the
fields that stand for the whole disc (rule 2-18). In a file such as libburn’s example, the
arranger of track 2 is a TAB and reads as the arranger of track 1, Tom Cat.
Double-byte text
MMC-3: a character string ends with “one null code for single byte, two null code for double byte”. The guide: when the character code of the block is MS-JIS (0x80 in the block size record), the characters are two bytes, the flag in byte 3 is 1, and two zero bytes terminate a text. The explorer reads a pack with the flag set two bytes at a time and reports a pack that sets the flag in a block whose character code is not MS-JIS. It decodes MS-JIS as Shift_JIS, the Japanese encoding of that name (the guide names “MS-JIS (japanese Kanji, double byte characters)” and no table).
The MMC header
A drive that returns CD-Text with the SCSI command READ TOC/PMA/ATIP, format 0101b, puts
four bytes before the packs: a 16-bit “CD-TEXT Data Length” that does not count itself,
then one byte called “First Track/Session/Reserved Field” and one “Last
Track/Session/Reserved Field” (MMC-3 Table 244; “if a Pack Data is recorded repeatedly on
the disc, the device should return it only once”). libcdio’s example
cdtext-raw.c skips these four bytes when the first byte is below 0x80, the file
size is the length field plus 2 (or plus 3), that size leaves 4 when divided by 18, and the
byte at offset 4 is a pack type (0x80 to 0x8f). The explorer uses the same test, and shows the
header as a node of its own.
The trailing zero
Sony’s binary file “consist of 18xN+1 bytes”: after the N packs “a NULL Code is appended at
the end of the binary data” and the end of the file “is judged by the NULL Code (0x00) that
appears at the 18xNth byte” (DOC08). Sony’s encoder also writes a second file for the program
area that holds only “19 bytes of null codes” (DOC03). libcdio’s example “ignores trailing
0” when the size leaves 1 after dividing by 18, and libcdio’s own test file
cdtext.cdt ends in one. The explorer accepts one trailing zero and shows it as
a node; any other bytes after the last whole pack are a problem.
Files named by CDTEXTFILE
The GNU ccd2cue manual says the libcdio guide documents the format of the file a cue sheet’s
CDTEXTFILE names, and the cue
sheet pages point here for the layout. The CDRWIN guide says how its editor makes such a
file but does not describe the bytes; this site read CDRWIN’s documentation, not its
program.