Id RoQ DPCM

From MultimediaWiki
Revision as of 12:42, 4 February 2006 by Multimedia Mike (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

RoQ multimedia files store audio in a DPCM format. A chunk of RoQ DPCM data is laid out as (all multi-byte numbers are little-endian):

bytes 0-1    chunk ID: 0x1020 for mono data, 0x1021 for stereo data
bytes 2-5    chunk size, not including 8-byte preamble
bytes 6-7    initial predictor(s)
bytes 8..n   DPCM bytes 

If the block is mono data, each byte represents the square root of the difference between the last PCM sample and the current PCM sample. To decode the audio, follow this process:

if (current DPCM byte < 128)
  next PCM sample = last PCM sample + (current DPCM byte) * (current DPCM byte)
else
  next PCM sample = last PCM sample - ((current DPCM byte) * (current DPCM byte)) 

Trivially, this process can be optimized by precalculating the squares of all 256 possible DPCM bytes. If the audio data is stereo, the 16-bit predictor encodes both the initial right and left predictors. After decoding the little-endian 16-bit predictor number, the upper 8 bits (bits 15-8) are the upper 8 bits of the initial left channel predictor. The lower 8 bits are the upper 8 bits of the initial right channel predictor. The DPCM bytes are decoded in the same manner as for mono data except that left and right DPCM bytes are interleaved.