## Which variant of ADPCM decoding algorithm is it?

#####

Hi, I have been trying to decode audio files from a video game and was wondering what decoding algorithm it was using. At first glance it looks like a variation of the IMA ADPCM 4-bit to 16-bit decoder since it is using the same exact step size table and index table, but the algorithm does a bit more...

It is reading 4 bytes when decoding a mono file and 6 bytes when decoding a stereo file, for each block, which looks like every block has a little descriptor at its beginning.

Here is the code for decoding a mono channel, to make it simple.

int adpcmDecodeMonoBlock(char *inBuffer, short *outBuffer, int sizeBlock)

{

/* looks like each first 4 bytes of a block contain a ADPCM description */

int sample = *inBuffer;

char index = inBuffer[2];

char *v6 = inBuffer + 3;

int step = step_table[index];

int i = 0;

for (; i < sizeBlock; i++)

{

int delta;

if (i & 1) delta = (*v6++ >> 4) & 0xF; else delta = *v6 & 0xF;

/* compute index */

index += index_table[delta]; /* delta is 4-bit, hence the 16-sized index array */

if (index < 0) index = 0;

else if (index > 88) index = 88;

int s = 0;

if ((delta & 7) & 4) s = 4 * step;

if ((delta & 7) & 2) s += 2 * step;

if ((delta & 7) & 1) s += step;

if (delta & 8) sample -= s >> 2; else sample += s >> 2;

/* keep in 'short' type boundaries */

if (sample > 32767) sample = 32767;

else if (sample < -32768) sample = -32768;

step = step_table[index];

*outBuffer++ = sample;

}

return i; /* return the number of samples read */

}

So my question is, which variant of ADPCM is it?