ADPCM Decoding
Figure 2 shows a block diagram of the ADPCM decoding process. An ADPCM sample is presented to the decoder. The decoder computes the difference between the previous linear output estimate and the anticipated one. This difference is added to the previous estimate to produce the linear output estimate. The input ADPCM sample is also presented to the step size calculator to compute the step size estimate.
Figure 2
The decoder accepts ADPCM code values, L(n), and step size values. It calculates a reproduced differential value, and accumulates an estimated waveform value, X. Here is a pseudocode algorithm:
d(n) = (ss(n)*B2)+(ss(n)/2*B1)+(ss(n)/4*B0)+(ss(n)/8)
if (B3 = 1)
then d(n) = d(n) * (-1)
_ _
X(n) = X(n-1) + d(n)
Note: For the calculation of ss(n), see Calculation of Step Size.
Calculation of Step Size
For both the encoding and decoding process, the ADPCM algorithm adjusts the quantizer step size based on the most recent ADPCM value. The step size for the next sample, n+1, is calculated with the following equation:
ss(n+1) = ss(n) * 1.1M(L(n))
This equation can be implemented efficiently as a two-stage lookup table. First the magnitude of the ADPCM code is used as an index to look up an adjustment factor as shown in Table 1) . Then that adjustment factor is used to move an index pointer in Table 2. The index pointer then points to the new step size. Values greater than 3 will increase the step size. Values less than 4 decrease the step size.
Table 1 - M(L(n)) Values
Код:
L(n) Value M(L(n))
1111 or 0111 +8
1110 or 0110 +6
1101 or 0101 +4
1100 or 0100 +2
1011 or 0011 -1
1010 or 0010 -1
1001 or 0001 -1
1000 or 0000 -1
Table 2 - Calculated Step Sizes
Код:
No. Step Size No. Step Size No. Step Size No. Step Size
1 16 13 50 25 157 37 494
2 17 14 55 26 173 38 544
3 19 15 60 27 190 39 598
4 21 16 66 28 209 40 658
5 23 17 73 29 230 41 724
6 25 18 80 30 253 42 796
7 28 19 88 31 279 43 876
8 31 20 97 32 307 44 963
9 34 21 107 33 337 45 1060
10 37 22 118 34 371 46 1166
11 41 23 130 35 408 47 1282
12 45 24 143 36 449 48 1411
49 1552
This method of adapting the scale factor with changes in the waveform is optimized for voice signals, not square waves or other non-sinusoidal waveforms.
Initial Conditions
When the ADPCM algorithm is reset the step size ss(n) is set to the minimum value (16) and the estimated waveform value X is set to zero (half scale). Playback of 48 samples (24 bytes) of plus and minus zero (10002 and 00002) will reset the algorithm. Twenty four bytes of 08 Hex or 80 Hex will satisfy this requirement. It is necessary to alternate positive and negative zero values because the encoding formula always adds 1/8 of the quantization size. If all values were positive or negative, a DC component would be added that would create a false reference level.