XA Audio
CD-ROM XA ADPCM playback through the CD-ROM decoder.
Summary
ADPCM (Adaptive Differential PCM) compresses audio data encoded as 16-bit straight PCM to 1/4 of its size. A sector that stores ADPCM data is called an ADPCM sector, and strictly it is a real-time or mode 2 form 2 sector.12 The CD-ROM decoder decodes the sectors itself and sends the audio to the SPU mixer without using main memory, the sound buffer or an SPU voice.3 The XA data is held in the local memory of the CD subsystem and decoded there.4 The file format and the four audio types are described in XA.
Interleave
An ADPCM sector holds audio compressed to 1/4, so the disc delivers audio faster than it plays. To play an audio series without seeking for each sector, ADPCM sectors are recorded on the disc at every fourth sector for normal speed play and at every eighth sector for double speed play. Sony calls this interleave, and it makes it possible to read data from the other sectors while ADPCM plays.12
| Sector | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ... |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Contents | ADPCM | Data | Data | Data | Data | Data | Data | Data | ADPCM | Data | ... |
The interleave depends on the speed, the sample rate and the number of channels. psx-spx lists the usual values at double speed:5
| Interleave | Data format |
|---|---|
| 1/1 | 44100 Hz stereo CD audio at normal speed |
| 1/8 | 37800 Hz stereo ADPCM at double speed |
| 1/16 | 18900 Hz stereo ADPCM at double speed |
| 1/16 | 37800 Hz mono ADPCM at double speed |
| 1/32 | 18900 Hz mono ADPCM at double speed |
| 7/8 | 15 fps 320 x 224 MDEC video at double speed |
The other sectors can also hold other ADPCM channels. Sony's example interleaves 8 channels, A0 to A7, one after another, so the program can switch between 8 audio channels without a seek.6 psx-spx notes that it is not known whether the 1/16 and 1/32 interleaves always work, because the controller overwrites its buffer entries once every eight sectors. However, Crash Team Racing plays 37800 Hz mono at double speed, and 1/16 therefore works.5
Channel Selection
The channel to play is chosen by the file number and channel number in the subheader of each sector. CdlSetfilter sets the numbers to play, and CdlModeSF must be set in the mode for the filter to take effect.6 The file number selects the playing channel of a multichannel XA-ADPCM disc. The default is file 1 and channel 1.78
psx-spx gives the order in which the controller handles a sector. It first tries to send the sector to the ADPCM decoder, and if that fails it tries to send it to the CPU.9
| Check | Result |
|---|---|
| Sector is CD-DA, or not mode 2 | Not ADPCM |
| CdlModeRT (Setmode bit 6) is clear | Not ADPCM |
| CdlModeSF is set and the file or channel does not match | Not ADPCM |
| Submode does not have both the audio and real-time bits | Not ADPCM |
| All checks pass | Sent to the ADPCM decoder |
A sector that is not played as ADPCM goes to the CPU with INT1, unless CdlModeSF is set and the sector is an audio and real-time sector. With CdlModeRT or CdlModeSF set, INT1 therefore comes only for the data sectors.910 Since the sector size in the mode does not apply to ADPCM, the decoder always decodes the full 900h bytes.10
Playing XA Audio
XA-ADPCM sectors are organized in files instead of tracks. They are therefore played with a read command instead of CdlPlay.10 The SPU is first set up for CD input. The program then sets CdlModeRT (and CdlModeSF if needed) with CdlSetmode, sets the start sector with CdlSetloc and issues a read, normally CdlReadS.10 CdlReadN retries even in CdlModeRT, so CdlReadS is used to inhibit retries.11 There is no way to detect the end of XA playback automatically. The program polls the sector ID periodically to find it.12
Sector Layout
An ADPCM sector carries 12h portions of 128 bytes (900h bytes), and the rest of its 914h-byte data area is zero. Each portion holds a 16-byte header and 28 data words of 4 bytes.13
| Offset | Contents |
|---|---|
| 00h to 03h | Copy of the bytes at 04h to 07h |
| 04h | Header of block 1 (mono) or block 1 left |
| 05h | Header of block 2 (mono) or block 1 right |
| 06h | Header of block 3 (mono) or block 2 left |
| 07h | Header of block 4 (mono) or block 2 right |
| 08h to 0Bh | Headers of blocks 5 to 8 (mono) or blocks 3 and 4 (stereo), unused in 8-bit mode |
| 0Ch to 0Fh | Copy of the bytes at 08h to 0Bh |
The copies let the controller replace a header that it read with an error.13 Each header byte holds the shift in bits 0 to 3 (0 to 12, where 0 is loudest) and the filter in bits 4 and 5. Bits 6 and 7 are unused.14
The 28 data words follow at 10h to 7Fh. Word N holds sample N of every block: in 4-bit mode eight nibbles for blocks 1 to 8, and in 8-bit mode four bytes for blocks 1 to 4. In stereo the entries alternate between left and right, and the first entry is left.15
Decoding
The decoding is the same as for SPU-ADPCM in SPU ADPCM. Each 4-bit sample is shifted left by 12 (or an 8-bit sample by 8), then right by the shift, and the filter adds a weighted sum of the two previous outputs.1416 XA uses only filters 0 to 3, with weights (0, 0), (60, 0), (115, -52) and (98, -55) in 64ths. The SPU also has filter 4.17 For 8-bit data the useful shifts are 0 to 8, and the reserved shifts 13 to 15 act as 9.14
The decoder converts the 37800 Hz output to 44100 Hz with a 25-point zigzag interpolation. The SPU uses a 4-point Gaussian interpolation instead. A six-step counter makes seven outputs from every six samples (37800 x 7 / 6 = 44100). Each 900h-byte sector holds a multiple of six samples, so the counter is the same at the start and end of each sector.1819 The counter starts at a random value at power on.19 Emphasis is supported but no known game uses it.20
Sound Map
In sound map mode the host sends ADPCM data to the decoder through WRDATA in place of the disc. This is useful for testing XA-ADPCM from an executable, and it supports both 4-bit and 8-bit data, while the SPU supports only 4-bit.21 The procedure from psx-spx is as follows:21
| Step | Action |
|---|---|
| 1 | Set the SPU main volume and CD input volume, and enable CD input in ATTR bit 0 |
| 2 | Send Stop, then Demute if muted |
| 3 | Write the coding information to CI |
| 4 | Clear ADPMUTE in ADPCTL |
| 5 | Set SMEN and BFWR in HCHPCTL |
| 6 | Write 900h bytes in the ADPCM sector layout to WRDATA, waiting for DRQSTS before each byte |
Output starts after the last of the 900h bytes is written. The decoder stores the block in one of three 900h-byte slots, but it does not always play the slot that was written last.21 The data sheet adds that the BFWRDY interrupt shows room for one more sector and BFEMPT shows that the decoder has run out of sectors. SMADPCLR in HCLRCTL ends sound map decoding at once.2223
References
-
^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 11-3, Table 11-1.
-
^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 11-16, Figure 11-2.
-
^ psx-spx. Sound Processing Unit (SPU), SPU-ADPCM vs XA-ADPCM. https://psx-spx.consoledev.net/soundprocessingunitspu/
-
^ Sony Computer Entertainment. The Un-Official PlayStation Development FAQ, CD Conference. Release v1.3. February 29, 1996. Question 1.6.33.
-
^ a b psx-spx. CDROM Format, CDROM XA Subheader, File, Channel, Interleave, Audio/Video Interleave. https://psx-spx.consoledev.net/cdromformat/
-
^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 11-17, Figure 11-3.
-
^ Sony Computer Entertainment. The Un-Official PlayStation Development FAQ, CD Conference. Release v1.3. February 29, 1996. Question 1.6.24.
-
^ Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 11-10.
-
^ a b psx-spx. CDROM Drive, CDROM - Control Commands, Data/ADPCM Sector Filtering/Delivery. https://psx-spx.consoledev.net/cdromdrive/
-
^ a b c d psx-spx. CDROM Drive, CDROM - CD Audio Commands, Playing XA-ADPCM Sectors. https://psx-spx.consoledev.net/cdromdrive/
-
^ Sony Computer Entertainment. The Un-Official PlayStation Development FAQ, CD Conference. Release v1.3. February 29, 1996. Question 1.6.28.
-
^ Sony Computer Entertainment. The Un-Official PlayStation Development FAQ, CD Conference. Release v1.3. February 29, 1996. Question 1.1.2.
-
^ a b psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, ADPCM Sectors. https://psx-spx.consoledev.net/cdromformat/
-
^ a b c psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, XA-ADPCM Header Bytes. https://psx-spx.consoledev.net/cdromformat/
-
^ psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, XA-ADPCM Data Words. https://psx-spx.consoledev.net/cdromformat/
-
^ psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, decode_28_nibbles. https://psx-spx.consoledev.net/cdromformat/
-
^ psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, Pos/neg Tables. https://psx-spx.consoledev.net/cdromformat/
-
^ psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, 25-point Zigzag Interpolation. https://psx-spx.consoledev.net/cdromformat/
-
^ a b psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, Uninitialized Six-step Counter. https://psx-spx.consoledev.net/cdromformat/
-
^ psx-spx. CDROM Format, CDROM XA Audio ADPCM Compression, XA-ADPCM Emphasis. https://psx-spx.consoledev.net/cdromformat/
-
^ a b c psx-spx. CDROM Drive, CDROM Controller I/O Ports, Sound Map Flowchart. https://psx-spx.consoledev.net/cdromdrive/
-
^ Sony Corporation. CXD1199AQ CD-ROM Decoder. Page 41, section 3-2-5.
-
^ Sony Corporation. CXD1199AQ CD-ROM Decoder. Page 36, section 3-1-7.