Id RoQ DPCM: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
(Add to audio codecs category.)
No edit summary
 
(One intermediate revision by one other user not shown)
Line 9: Line 9:


  if (current DPCM byte < 128)
  if (current DPCM byte < 128)
   next PCM sample = last PCM sample + (current DPCM byte) * (current DPCM byte)
   next PCM sample = last PCM sample + (128-current DPCM byte) * (128-current DPCM byte)
  else
  else
   next PCM sample = last PCM sample - ((current DPCM byte) * (current DPCM byte))  
   next PCM sample = last PCM sample - ((current DPCM byte) * (current DPCM byte))  
Line 15: Line 15:
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.
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.


[[Category:Audio Codecs]]
[[Category:DPCM Audio Codecs]]
[[Category:DPCM Audio Codecs]]
[[Category:Audio Codecs]]
[[Category:Game Formats]]

Latest revision as of 17:14, 5 February 2006

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 + (128-current DPCM byte) * (128-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.