您的当前位置:首页正文

adpcm

2021-05-13 来源:好走旅游网
Dialogic ADPCM Algorithm

Abstract

This application note describes the implementation of Adaptive Differential Pulse CodeModulation (ADPCM) as used in Dialogic Voice Processing Applications.The following topics are covered.• File format for voice data files.• ADPCM encoding algorithm.• ADPCM decoding algorithm.• Step size determination.• Initial and reset conditions.

Copyright © 1988, Dialogic CorporationAll Rights Reserved.00-1366-001

All names, products, and services mentioned herein are the trademarks or registered trademarks of their respectiveorganizations and are the sole property of their respective owners. DIALOGIC (including the Dialogic logo), DTI/124,SpringBoard, and Signal Computing System Architecture (SCSA) are registered trademarks of Dialogic Corporation.A detailed trademark listing can be found at http://www.dialogic.com/legal.htm.Warranty Disclaimer

Dialogic expressly disclaims all warranties with regard to this application note, including, but not limited to, theimplied warranties of merchantability and fitness for a particular purpose. Dialogic does not warrant, guarantee, ormake any representation regarding the use or the results of the use of this application note in terms of correctness,accuracy, or reliability. The contents of this application note are subject to change without notice. Dialogic willpublish updates and revisions of this document as needed. This document supersedes all previous versions.Limitation of Liability

You agree that Dialogic shall not be liable to you under this agreement for any damages, including without limitationany lost profits or lost savings, or any consequential, incidental, or punitive damages arising out of the use or inabilityto use this application note and related documents, or for any claim by another party. You agree to hold Dialogicharmless for all claims and damages arising from any third party as a result of their use or inability to use any productthat you develop based on this application note and the products and/or services documented herein.

2

VOX file format specification:

VOX files are flat binary files containing digitized voice data samples. Each byte contains twosamples. There is a direct relationship between any positional offset within the file and time,expressed in the following formula:

T(i) = 2i * I/SR

where: T(i) is the time offset in seconds from the beginning of the file of byte number \"i\" withinthe file. SR is the sampling rate in samples per second.The encoding within each byte is as follows:

Bit

7

6

5

4

3

2

1

0

Sample NSample N+1The encoding within each sample is Adaptive Differential Pulse Code Modulation (ADPCM).This is a differential coding scheme in which each sample approximates the difference betweenthe present input value and the previous one. The weighting of the magnitude portion of thedifference is adaptive (non-linear). That is, it can change after each sample.

Bit

3Sign2

1

0

MagnitudeSign: Positive (0) or negative (1) sample.Magnitude: Change (0 to 7) from previous sample.

ADPCM Encoding

Figure 1 shows a block diagram of the ADPCM encoding process. A linear input sample X(n) iscompared to the previous estimate of that input X(n-l). The difference, d(n), along with the

present step size, ss(n), are presented to the encoder logic. This logic, described below, producesan ADPCM output sample. This output sample is also used to update the step size calculationss(n+l), and is presented to the decoder to compute the linear estimate of the input sample.

3

Step SizeCalculationadjusted step size ss(n+1)Z-1step size ss(n)X(n) Linear input sample12 bits+-d(n)differenceEncoderL(n) ADPCM output sample4 bitsDecoderX(n)X(n-1) estimate oflast input sampleZ-1Figure 1

The encoder accepts the differential value, d(n), from the comparator and the step size, andcalculates a 4-bit ADPCM code. The following is a representation of this calculation inpseudocode.

let B3 = B2 = B1 = B0 = 0if (d(n) < 0) then B3 = 1d(n) = ABS(d(n))if (d(n) >= ss(n))

then B2 = 1 and d(n) = d(n) - ss(n)if (d(n) >= ss(n) / 2)

then B1 = 1 and d(n) = d(n) - ss(n) / 2if (d(n) >= ss(n) / 4) then B0 = 1

L(n) = (10002 * B3) + (1002 * B2) + (102 * B1) + B0Note: For the calculation of ss(n), see \"Calculation of Step Size.\"

4

ADPCM Decoding

Figure 2 shows a block diagram of the ADPCM decoding process. An ADPCM sample ispresented to the decoder. The decoder computes the difference between the previous linearoutput estimate and the anticipated one. This difference is added to the previous estimate toproduce the linear output estimate. The input ADPCM sample is also presented to the step sizecalculator to compute the step size estimate.

Step SizeCalculationadjusted step sizess(n+1)Z-1Z-1step size ss(n)X(n-1)L(n) ADPCM input sample4 bitsDecoderd(n)difference+X(n) Linear output sample12 bitsFigure 2

The decoder accepts ADPCM code values, L(n), and step size values. It calculates a reproduceddifferential value, and accumulates an estimated waveform value, X. Here is a pseudocodealgorithm:

d(n) = (ss(n)*B2)+(ss(n)/2*B1)+(ss(n)/4*BO)+(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.\"

5

Calculation of Step Size

For both the encoding and decoding process, the ADPCM algorithm adjusts the quantizer stepsize based on the most recent ADPCM value. The step size for the next sample, n+l, is calculatedwith 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 ofthe ADPCM code is used as an index to look up an adjustment factor as shown in Table 1. Thenthat adjustment factor is used to move an index pointer in Table 2. The index pointer then pointsto the new step size. Values greater than 3 will increase the step size. Values less than 4 decreasethe step size.

Table 1. M(L(n)) Values

L(n) Value1111 or 01111110 01101101 01011100 01001011 00111010 00101001 00011000 0000

M(L(n))

+8+6+4+2-1-1-1-1

Table 2. Calculated Step Sizes

No.123456789101112

Step Size

161719212325283134374145

No.131415161718192021222324

Step Size

5055606673808897107118130143

No.252627282930313233343536

Step Size

157173190209230253279307337371408449

No.37383940414243444546474849

Step Size

49454459865872479687696310601166128214111552

This method of adapting the scale factor with changes in the waveform is optimized for voicesignals, not square waves or other non-sinusoidal waveforms.

6

Initial Conditions

When the ADPCM algorithm is reset, the step size ss(n) is set to the minimum value (16) and theestimated waveform value X is set to zero (half scale). Playback of 48 samples (24 bytes) of plusand minus zero (10002 and 00002) will reset the algorithm. Twenty-four bytes of 08 Hex or 80Hex will satisfy this requirement. It is necessary to alternate positive and negative zero valuesbecause the encoding formula always adds 1/8 of the quantization size. If all values were positiveor negative, a DC component would be added that would create a false reference level.

7

因篇幅问题不能全部显示,请点此查看更多更全内容