Expanding 8 bit logarithmic data or companding linear data to a byte will result in a certain amount of program cycles and data words. The programmer can choose between a table look-up technique, faster and memory consuming, and a computational technique, slower and and memory saving.
Two sample program follow. The target processor is Motorola DSP56000.
The first one is based on table look-up technique. The PCM byte to be decoded is used to address a table in which the corresponding linear value has been stored. As the 256 element table has been organized in natural order, the even bit has inverted from the program (fig. 3).
Fig. 3 - (a) Table look-up A-law conversion flowchart. (b) Table look-up A-law conversion assembler code for Motorola DSP56000.
a)
b)
page 75, 72, 0, 10
opt nomd, nomex
;
; ALGLINl.ASM
;
; A-law to linear conversion using a table of data
; the 8 bit log data to be decoded
; is in the ssi txrx register highbyte (bit23-bitl5)
; r3 points to the 13 bit linear data
;
; timing in cycles: 12 (-> 1.17 micro s)
; required memory space: - 256 data memory word
; - 11 program memory words
;
start equ $40 ;program starting address
tab equ O ;table starting address
shift equ $80 ;used for 16 bit asr
mask equ $ff ;pcm byte mask
invl equ $000055 ;invert even bit of 8 lsb
txrx equ $ffef ;SSI rx register address
;
maclib '\dsp56000.mac\' ;MS-DOS macro dir.
;
aloglin tab ;call macro
;
org p:start
;
movep x:txrx,xO ;read pcm byte in x
move #>shift,yO ;prepare 16 bit asr
mpy xO,yO,a #>mask,xl ;shift 16 bit in a
and xl,a #>inv,yl ;mask 8 lsb in al
eor yl,a ;invert even bit
clr a al,r3 ;set the table ptr
nop ;wait one cycle
move x:(r3),a ;a=decoded value
end
Fig. 4 (a) Algorithmic A-law conversion flowchart. (b) Algorithmic A-law conversion assembler code for Motorola DSP56000.
a)
b)
page 75,72,0,10
;ALGLIN2.ASM
; A-law to linear conversion algorithm
; -assumes the log B bit data to be decoded
; present in the high byte of the ssi
; txrx register(bit23-bitl5)
; -result is given in the B accumulator on 13 bit
;worst case timing in cycles: 34 (-> 3.32 micro s.)
;required memory space:- 1 data memory ~ord
; -28 program memory words
;WARNING: The memory location pointed by rO will be used
start equ $40 ;program starting address
shift equ $08 ;used in 4 bit asr
shftl equ $000008 ;used in 20 bit asr
ofset equ $10 ;for test S2SlSO=l
bias equ $010800 ;;33 hex shifted msb=bit 11
one equ $000800 ;; 1 shifted msb=bit 11
maskb equ $00fOOO ;;mask segment in b
mpq equ $70 ;;mask for q3q2qlqO
mp equ $7f ;;mas~ for sign
inv equ $55 ;;invert bit 2,4,6,8
org p:start
clr a #inv,yl;clear a2:al:a
movep x:txrx,al ;pcm byte in a
; invert bits 2,4,6,8
eor yl,a #<mp,yO ;invert bit
; save polarity and mask it ;2,4,6,8
and yO,a al,x:(rO) ;al=Osq
; strip s in a and q in b
move al,xO ;prepare a 4 bit
move #<shift,yl ;right shift in b
mpy xO,yl,b #maskb,yO ;4 bit asr in b
and yO,b #<mpq,yl ;b=q3q2qlqO shifted
and yl,a #<ofset,xl ;a=segment
jne <again ;jmp if not seg. O
; segment O
move #one,yO ;in seg. O bias=l
jmp <againl ;skip seg. 1 test
again sub xl,a #bias,yO ;bias=lOOOlh,test
jgt <shfta ;jmp if not seg. 1
; segment 1
againl add yO,b ;add bias and goto
jmp <sgna ;sign without shift
; other segments
shfta move a,xO #>shftl,yl
mpy xO,yl,a ;20 bit left shift
add yO,b ;add bias in b
rep al ;seg. num.=shift counter
lsl b ;shift b+bias
; add polarity
sgna jset #23,x:(rO),pos
neg b ;negate result if negative
pos nop
end
Lin=[(2*Q+bias)*2]^(S-1)
where:
- Lin=12 bit linear data (without sign bit)
- bias=1 for S = 0
- bias=33hex for S = 1,7
- S=S2S1S0
- Q=Q3Q2Q1Q0
[ Index | Previous Paragraph | Next Paragraph ]