📄 quantize.asm
字号:
;/*
; * quantize()
; *
; * Given a raw sample, 'd', of the difference signal and a
; * quantization step size scale factor, 'y', this routine returns the
; * ADPCM codeword to which that sample gets quantized. The step
; * size scale factor division operation is done in the log base 2 domain
; * as a subtraction.
; */
;int
;quantize(
; int d, /* Raw difference signal sample */
; int y, /* Step size multiplier */
; short *table, /* quantization table */
; int size) /* table size of short integers */
;{
; short dqm; /* Magnitude of 'd' */
; short exp; /* Integer part of base 2 log of 'd' */
; short mant; /* Fractional part of base 2 log */
; short dl; /* Log of magnitude of 'd' */
; short dln; /* Step size scale factor normalized log */
; int i;
;
; /*
; * LOG
; *
; * Compute base 2 log of 'd', and store in 'dl'.
; */
; dqm = abs(d);
; exp = quan(dqm >> 1, power2, 15);
; mant = ( dqm >> (exp-7) ) & 0x7F; /* Fractional portion. */
; dl = (exp << 7) + mant;
;---------------------------------
.title "quantize.asm"
.include "g723_global.asm"
.include "g723tab.asm"
.include "g723_stat.asm"
.mmregs
temp_dqm .set 0
temp_yy .set 1
.text
;AR3=table, A=y, *AR6=d
quantize
frame #-2
ld *AR6, B
stl A, *SP(temp_yy)
abs B ;B=dqm
stl B, *SP(temp_dqm)
sfta B, -1
pshm AR3
stm #power2, AR3
call quan ;B = dqm >> 1
;AR3=power2
;返回值exp=B
popm AR3
sub #7, B, A
neg A
stlm A, T
ld *SP(temp_dqm), A
norm A
and #0x7f, A ;A=mant
add B, 7, A ;A=dl
;-------------------------------------------------
; /*
; * SUBTB
; *
; * "Divide" by step size multiplier.
; */
; dln = dl - (y >> 2);
;-------------------------------------------------
ld *SP(temp_yy), B
sub B, -2, A ;A=dln
;-------------------------------------------------
; * QUAN
; *
; * Obtain codword i for 'd'.
; */
; i = quan(dln, table, size);
; if (d < 0) /* take 1's complement of i */
; return ((size << 1) + 1 - i);
; else if (i == 0) /* take 1's complement of 0 */
; return ((size << 1) + 1); /* new in 1988 */
; else
; return (i);
;-------------------------------------------------
ld A, B
call quan ;B=dln, table=AR3
;返回值 i=B
ld *AR6, A
bc ret_i, AGEQ
ld #15, 1, A
add #1, A
sub B, A
frame #2
ret
ret_i
bc ret_end, BNEQ
ld #15, 1, A
add #1, A
;sub B, A
frame #2
ret
ret_end
ld B, A
frame #2
ret
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -