CRI ADX ADPCM
- Company: CRI
- Samples:
- Sofdec files: http://samples.mplayerhq.hu/game-formats/sfd/
- Sega FILM files: http://samples.mplayerhq.hu/game-formats/film-cpk/ (*.CAK files contain CRI ADX ADPCM)
CRI ADX ADPCM is an ADPCM format primarily used in Sega Dreamcast. Sometimes it is packaged in Sofdec files along with MPEG video data. Sometimes it is packaged inside audio-only files. It is also seen packaged in Sega FILM files on some Sega Saturn games. The container format specifies the playback frequency of the audio data and whether the audio is monaural or stereo. ADX is organized in blocks of 18 bytes:
bytes 0-1 scale (encoded as little endian) bytes 2-17 ADPCM nibbles
If the audio data is stereo, left blocks and right blocks with the above format are interleaved. Each coded ADX channel has two state variables, sample1 and sample2, which are both initialized to 0 at the start of playback. The 16 data bytes in each ADX block are decoded top nibble (bits 7-4) first, then bottom nibble). For each nibble:
sample0 = (BaseVolume * (signed)nibble * scale + 0x7298 * sample1 - 0x3350 * sample2) / 16384 sample0 = SaturateS16(sample0) next PCM sample = sample0 sample2 = sample1 sample1 = sample0
Notes:
- SaturateS16() saturates the sample to a signed 16-bit range (-32768..32767)
- BaseVolume = 0x4000 = 16384
- nibble is treated as a 2's complement signed number
- 16384 = 214, which means that the division operation can be replaced with a right shift by 14 bits
- the states of sample1 and sample2 for a particular channel are maintained across blocks; i.e., the values of sample1 and sample2 after decoding the last nibble of block n are used to decode the first nibble of block n+1