### Notice

If you are using a Hotmail or Outlook email address, please change it now, as Microsoft is rejecting all email from our service outright.
Topic: Which variant of ADPCM decoding algorithm is it? (Read 287 times)
0 Members and 1 Guest are viewing this topic.

## Which variant of ADPCM decoding algorithm is it?

##### 2020-10-02 12:19:25
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.
Code: [Select]
`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?

## Re: Which variant of ADPCM decoding algorithm is it?

##### Reply #1 – 2020-10-02 22:28:30
That looks like the QuickTime variant.

## Re: Which variant of ADPCM decoding algorithm is it?

##### Reply #2 – 2020-10-03 14:52:09
That looks like the QuickTime variant.
Thank you for answering, but I do not think so. The stereo version of the game's algorithm decodes channels in an interleaved way, which is not the case of the QuickTime ADPCM (source here).
In other words, the game's algorithm decodes left and right channel samples in every block (2 channels included in 1 block), unlike the QuickTime ADPCM variant which decodes one channel per block (2 channels = 2 separate consecutive blocks).