Материал: spra118

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

SPRA118

A fixed-point multiplication would be inadequate (too much precision for high levels, not enough for low levels). The floating-point format permits better management of the dynamic gaps. Here, the resolution is limited to 6 bits (6 bits mantissa), but the dynamic is greater (0 is coded as 32 (1/2) for mantissa and 0 for exponent). As a consequence, if a variable has a zero value, the floating-point product with the corresponding coefficient would not always be zero, which is always the case with a fixed-point multiplication.

It is described now how floating-point format can be challenged by the C54x for the G.726 recommendation.

3.2.1Floating-Point Format Storage

Floating-point number characteristics are as follows: sign, exponent, mantissa. These features are defined by:

|number| = denormalized mantissa * 2exponent, and sign(number) = sign

If number = 0, this equality is not verified (0 value is coded in floating-point format, as it was actually ½). The following inequalities are verified:

½ v denormalized mantissa t 1. Mantissa is normalized with 6 bits representation, so:

32 v mantissa t 64, where mantissa represents the 6 most significant bits of the fixed-point number, except for zero. As for exponent, you have:

2exponent – 1 v |number| t 2exponent. In practice, the number of the most significant bit plus one (when LSB number is zero).

To make the access faster, use three (successive) words, instead of one, to code a floating-point number: one word for the exponent (Q0 with 4 significant bits), one word for the mantissa (Q6 with 6 significant bits), and one more for the sign (Q0 with 0 significant bits). The sign is coded as an arithmetic sign, and is 0 for positive and null values, –1 for negative values (see section 3.10).

3.2.2Floating-Point Conversion

When loaded into the accumulator, the sign of a word (as defined in section 3.10 ) is the value of the high part of accumulator. The sign is thus extracted, due to the STH instruction. Then, compute the magnitude with the ABS instruction. Now the instructions EXP and NORM are useful for computing exponent and mantissa. EXP calculates the number of non-significant bits relative to the first 32 bits of the accumulator, and stores the result in the temporary register TREG. The wanted value of exponent is thus:

exponent = 31 – TREG for a word different from zero.

When associated with DSUBT that subtracts TREG from a variable that is here set to 31, you directly obtain the value of the exponent (note that DSUBT actually uses a long-word; the high part of this word must be at an even address, while the low part is set to 31).

This method does not apply if the input word to convert is 0. EXP set TREG to zero in this case.

Note also that DSUBT needs one cycle latency to use the TREG value computed by EXP. This feature has been underlined with the evaluation module; however, this latency was unnecessary for the simulator.

G.726 Adaptive Differential Pulse Code Modulation (ADPCM) on the TMS320C54x DSP

23

SPRA118

Mantissa is calculated by means of the NORM instruction that uses the TREG value (31 – exponent) to normalize the word in accumulator (TREG value left-shift). Then, a 9-bit right-shift gives the wanted 6-bit mantissa in the high part of the accumulator (bits 16 to 21).

The following code gives the floating-point conversion for the reconstructed signal sr(k). It takes 12 cycles to execute. One instruction (in bold characters) has been added to satisfy 40 Kbps (possibility of overflow on SR).

***********************************************************************************

*

Convert fixed-point number to floating-point format

*

*

 

*

*

INPUT:

*

* SD

= SR(k): Reconstructed signal in two-complement format

*

* AR6

= Address of SR(k–2) sign

*

*

 

*

*

OUTPUT:

*

* SRFLOAT (*AR6)= SR((k+1)–1) exponent, mantissa and sign

*

*

 

*

*

CYCLES: 13

*

***********************************************************************************

LD

SD, B

; Load reconstructed signal

ABS

B, A

; A = |SR|

 

AND

C32767, A

; exp <=15, for RATE=40, SR=8000 is overflow

EXP

A

; TREG = 31

– EXP(|SR|)

STH

B, *AR6–

; Store sign of SR (0 if >= 0, –1 if negative)

NORM

A

; A = (|SR|

mantissa) << 9

DSUBT

C31–1, B

; BL = 31 –

TREG = EXP(|SR|)

XC

2, AEQ

; if SR = 0

 

LD

C16384, 16, A

; then normalize A to obtain mantissa(SR)=32

LD

#0, B

; and set B

to zero to obtain EXP(|SR|) = 0

STH

A, –9, *AR6–

; Store |SR| mantissa (6 bits)

STL

B, *AR6+0%

; Stores EXP of |SR| (4 bits)

3.2.3Floating-Point Multiplication

This routine has a crucial importance in CCITT ADPCM timing. The sixth-order FIR filter and the second-order IIR filter are concerned so that eight floating-point multiplications have to be performed. With 25 clock cycles per routine, it totals 200 clock cycles, equivalent to one-third of the global coding process.

The routine also includes floating-point conversion of predictor coefficients (truncated in Q12 format). The principle of this conversion is the same as explained above. Mantissas of the two operands (Q6 format) are multiplied to form the product mantissa (Q12), which is then truncated in Q8 format. Exponents of the two operands are added to form the exponent of the product. The result is immediately converted into two-complement format, including an 11-bit right-shift, for scaling it in Q1 format, and sign calculation. In fact, accumulation of these products is executed in fixed-point format.

24 G.726 Adaptive Differential Pulse Code Modulation (ADPCM) on the TMS320C54x DSP

SPRA118

Each partial product is limited to 16 bits, which means that the contribution of each one to forming the signal estimate is limited to half of the greatest possible value for the reconstructed signal sr(k). This property is also true for the global signal estimate. However, signal estimate value could reach twice the greatest input PCM value.

The code bellow shows one of the eight floating-point multiplications.

***********************************************************************************

* Compute a2(k) * sr(k–2) in floating-point format

*

*

 

 

*

*

INPUT:

 

*

* SRFLOAT (*AR6)

= SR(k–2) exponent, mantissa and sign

*

* A2

 

= A2(k–1)

*

* AR6

 

= SR(k–2) address

*

*

 

 

*

*

 

OUTPUT:

*

* B

 

= WA2(k) = A2(k) * SR(k–2)

*

* AR6

 

= SR(k–1) address

*

*

 

 

*

*

CYCLES: 24

 

*

***********************************************************************************

LD

A2, –2, B

; truncate A2 (Q12 2’comp: S,0,...–12)

 

ABS

B, A

; A = |A2|,

(|A2>>2| in fact)

 

EXP

A

; If A > 0,

TREG = 31 – EXP(|A2|)

 

STH

B, SIGN

; SIGN = sign(A2) (0 if >= 0, –1 if negative)

 

DSUBT

C15–1, B

; BL = 15 –

TREG = EXP(|An|) – 16

 

NORM

A

; AH =(|A2|

mantissa) << 9

 

XC

2, AEQ

; If A = 0,

TREG = 0 and AH = 0 then

 

LD

C16384, 16, A ; normalize

A mantissa = 32 << 9 for A = 0

 

LD

M16, B

; and set B

to –16, to obtain B = EXP – 16

 

ADD

*AR6+, B

; B = EXP(SR2) + EXP(A2) – 16 = WA2EXP – 16,

 

STL

B, *AR3

; save WA2EXP – 16 in *AR3

 

SFTA

A, –9

; AH = A2MANT = mantissa of A2 (6 bits)

 

MPYA

*AR6+

; B = A2MANT*SR2MANT (SR2MANT = SR2 mantissa)

 

ADD

C48, B

; Add 48 for preparing rounding

 

LD

*AR3, T

; T = WA2EXP – 16

 

LDU

*AR6+%, A

; A = sign(SR2)

 

XOR

SIGN, A

; A = sign(SR2) * * sign(A2)

 

SFTA

B, –4

; B = mantissa of product = WA2MANT (Q8)

 

NORM

B

; WA2MANT<<(EXP–16)=WA2 magnitude (WA2MAG)<<3

 

SFTA

B, –3

; Complete scaling (–8 –3 = –11) for WA2MAG

 

AND

C32767, B

; Avoid 16-

or 17-bit results for WA2EXP > 26

 

 

G.726 Adaptive Differential Pulse Code Modulation (ADPCM) on the TMS320C54x DSP

25

SPRA118

4.1Algorithm Tables (Program Space)

This section has 849 words and contains six tables. The variables of the involved variables have their format described in Table 30. These tables are:

1.RAM initialization table, INIRAM. This table contains reset values of internal processing variables, and constant values that are transferred in RAM when applying the coder reset routine, _G726ENC_TI_reset or _G726DEC_TI_reset.

2.|I| tables for all rates. Each table contains successively:

a.The lowest level of input quantizer interval, QS|I| (first value of column two, Table 12 through Table 15).

b.The output level of the inverse quantizer, DQLN|I| (column three, Table 16 through Table 19).

c.The rate-of-change weighting function, F|I|, (Table 20 through Table 23).

d.The scale-factor multipliers, W|I| (Table 24 through Table 27).

3.Quantizer tables for all rates. Each table gives the output word that corresponds to a certain level of quantization. For the encoder, it gives the ADPCM word I (in two’s complement, column three of Table 12 through Table 15), and for the decoder (in re-encoding routine for synchronous adjustment), it gives the word ID (in absolute value, column four of Table 12 through Table 15), which has to be compared with the original ADPCM code.

4.Inverse quantizer tables for all rates. Each table gives, from a I ADPCM code, the output level of the quantizer which corresponds to the quantized difference signal (normalized and in logarithmic format, column three, Table 16 through Table 19). It also gives the sign of this quantized difference (column two, Table 16 through Table 19). This sign, which is also the sign of I, is the sign of the original difference signal before being normalized and going into logarithmic domain. Lastly, it gives the word the magnitude of I (column four of Table 16 through Table 19), which has to be compared with ID (see Table 12 through Table 15).

5.A-law and m-law tables for PCM expanding. This inverse quantizer table gives the linear PCM level corresponding to a logarithmic PCM code (see section 3.1.2).

6.PCM laws and coder rate selection tables. These tables permit the initialization of the coder, based on linear PCM, A-law PCM, or m-law PCM choice, and 16, 24, 32, or 40 Kbps coding choice. The relevant variables are those of Table 9.

Table 12. Quantizer Definition for 40-Kbps ADPCM

DS/DSX

DLN/DLNX

I

ID

0

553, ..., 2047

01111

31

0

528, ..., 552

01110

30

0

502, ..., 527

01101

29

0

475, ..., 501

01100

28

0

445, ..., 474

01011

27

 

 

 

 

NOTE: The I values are transmitted with bit 1.

G.726 Adaptive Differential Pulse Code Modulation (ADPCM) on the TMS320C54x DSP

39

SPRA118

Table 12. Quantizer Definition for 40-Kbps ADPCM (Continued)

DS/DSX

DLN/DLNX

I

ID

0

413, ..., 444

01010

26

0

378, ..., 412

01001

25

0

339, ..., 377

01000

24

0

298, ..., 338

00111

23

0

250, ..., 297

00110

22

0

198, ..., 249

00101

21

0

139, ..., 197

00100

20

0

68, ..., 138

00011

19

0

–16, ..., 67

00010

18

0

–22, ..., –17

00001

17

0

–2048, ..., –23

11111

15

1

–2048, ..., –23

11111

15

1

–22, ..., –17

11110

14

1

–16, ..., 67

11101

13

1

68, ..., 138

11100

12

1

139, ..., 197

11011

11

1

198, ..., 249

11010

10

1

250, ..., 297

11001

9

1

298, ..., 338

11000

8

1

339, ..., 377

10111

7

1

378, ..., 412

10110

6

1

413, ..., 444

10101

5

1

445, ..., 474

10100

4

1

475, ..., 501

10011

3

1

502, ..., 527

10010

2

1

528, ..., 552

10001

1

1

553, ..., 2047

10000

0

 

 

 

 

NOTE: The I values are transmitted with bit 1.

40 G.726 Adaptive Differential Pulse Code Modulation (ADPCM) on the TMS320C54x DSP

Источник: https://studfile.net/preview/16497444/