Duck DK4 IMA ADPCM
- Audio ID: 0x0061
- Company: Duck/On2
- Samples: http://samples.mplayerhq.hu/A-codecs/DK4/ (salsa.avi is stereo and virtuafighter2*.avi are mono)
Some Sega Saturn game CDs contain AVI files which store audio using the Duck DK4 IMA ADPCM algorithm. DK4 data can be decoded using the same algorithm and tables as are used to decode IMA ADPCM data. The name apparently comes from the fact that 4 ADPCM nibbles decode to 4 16-bit PCM samples, in contrast to Duck's Duck DK3 IMA ADPCM DK3 IMA ADPCM algorithm, in which 3 ADPCM nibbles decode to 4 16-bit PCM samples.
The length of a single block of DK4 data is encoded in the nBlockAlign field of an AVI file's WAVEFORMATEX header. The chunk encoding format is very similar to Microsoft IMA ADPCM. If the DK4 data is monaural, an individual chunk of data begins with the following preamble:
bytes 0-1: initial predictor (in little-endian format) byte 2: initial index byte 3: unknown, usually 0 and is probably reserved
The initial predictor is placed directly into the output as the first PCM sample. The remaining bytes in the chunk are the IMA nibbles. Each byte is decoded top nibble first (bits 7-4), then bottom nibble as follows:
byte0 byte1 byte2 byte3 ... n0n1 n2n3 n4n5 n6n7 ...
If the DK4 data is stereo, a chunk begins with two preambles, one for the left audio channel and one for the right audio channel:
bytes 0-1: initial predictor (in little-endian format) for left channel byte 2: initial index for left channel byte 3: unknown, usually 0 and is probably reserved bytes 4-5: initial predictor (in little-endian format) for right channel byte 6: initial index (for right channel) byte 7: unknown, usually 0 and is probably reserved
The initial left and right channel predictors are placed directly into the output as the first PCM samples for each channel. The remaining bytes in the chunk are the IMA nibbles. For each byte, the top nibble (bits 7-4) corresponds to the left channel and the bottom nibble corresponds to the right channel:
byte0 byte1 byte2 byte3 ... L0R0 L1R1 L2R2 L3R3 ...