www.pudn.com > g729Decoder.rar > DSPFUNC.asm


;========================================================================== 
;  File Name 
;  ---------- 
;  DSPFUNC.ASM 
; 
;  Brief Description of the Code: 
;  ------------------------------ 
;  This file contains DSP functions use in G.729. 
; 
;  Ref 
;  ------ 
;  DSPFUNC.C 
;========================================================================== 
;------------------------------------------------------------------------------------- 
        .MMREGS 
 
        .def        Pow2_14 
        .def        Log2 
        .def        Inv_sqrt 
 
;--------------------------------------------------------------------------- 
;   Function Name : Pow2() 
; 
;     L_x = pow(2.0, exponent.fraction) 
;--------------------------------------------------------------------------- 
;  Algorithm: 
; 
;   The function Pow2(L_x) is approximated by a table and linear 
;   interpolation. 
; 
;   1- i = bit10-b15 of fraction,   0 <= i <= 31 
;   2- a = bit0-b9   of fraction 
;   3- L_x = Pow2Table[i]<<16 - (Pow2Table[i] - Pow2Table[i+1]) * a * 2 
;   4- L_x = L_x >> (30-exponent)     (with rounding) 
;      if(exponent = 14) 
;      then  L_x = Lx >> (30 - 14) = Lx << -16 
;--------------------------------------------------------------------------- 
; 
;  Function Name : long Pow2_14(int fraction) 
; 
;      A = pow(2.0, 14.fraction) 
;--------------------------------------------------------------------------- 
;  Input:   B = fraction in Q15  (0 <= fraction <= 7fff) 
; 
;  Output : A = pow(2.0, 14.fraction) 
; 
;  Modified register : AR4 
;--------------------------------------------------------------------------- 
                .ref    Pow2Table 
 
exponent        .set    14 
shift           .set    - ( 30 - exponent ) 
round_bit       .set    0x4000 
 
Pow2_14: 
        LD      B, -10, A 
        XOR     A, 10, B 
        ADD     #Pow2Table, A 
        STLM    A, AR4 
        LD      B, 5, B 
        STLM    B, T 
        LD      *AR4+, 16, B 
        SUB     *AR4, 16, B, A 
        MPYA    A 
        ADD     #round_bit, 1, B 
        RETD 
        SUB     A, B 
        LD      B, shift, A 
 
;--------------------------------------------------------------------------- 
; 
;   Function Name : Log2() 
; 
;       Compute log2(L_x). 
;       L_x is positive. 
; 
;       if L_x is negative or zero, result is 0. 
;--------------------------------------------------------------------------- 
;  Algorithm: 
; 
;   The function Log2(L_x) is approximated by a table and linear 
;   interpolation. 
; 
;   1- Normalization of L_x. 
;   2- exponent = 30-exponent 
;   3- i = bit25-b31 of L_x,    32 <= i <= 63  ->because of normalization. 
;   4- a = bit10-b24 
;   5- i -=32 
;   6- fraction = Log2Table[i]<<16 - (Log2Table[i] - Log2Table[i+1]) * a * 2 
;--------------------------------------------------------------------------- 
;  Input:   A = L_x(32) > 0 
; 
;           AR5 -> | exponent |  at even address 
;                  |----------| 
;                  | fraction | 
; 
;  Output:  exponent, fraction 
; 
;           AR5 -> | exponent |  at even address 
;                  |----------| 
;                  | fraction | 
; 
;  Used and unchanged registers : AR5 
;  Modified registers           : AR4 
;--------------------------------------------------------------------------- 
                .ref    Log2Table 
 
Log2: 
        BCD     Exit_Log2, ALEQ 
        LD      #30, B 
        EXP     A 
        ST      T, *AR5 
        SUB     *AR5, B             ; exponent = 30-exponent 
        STL     B, *AR5+ 
 
        NORM    A, B 
        LD      B, -10, B 
        LD      B, -15, A 
        XOR     A, 15, B 
        SUB     #32, A 
        ADD     #Log2Table, A 
        STLM    A, AR4 
        STLM    B, T 
        NOP 
 
        LD      *AR4+, 16, B 
        SUB     *AR4, 16, B, A 
        MPYA    A 
        SUB     A, B 
        RETD 
        STL     B, -16, *AR5- 
 
Exit_Log2 
        STL     B, -16, *AR5+ 
        RETD 
        STL     B, -16, *AR5- 
 
;--------------------------------------------------------------------------- 
; 
;   Function Name : Inv_sqrt 
; 
;       Compute 1/sqrt(L_x). 
;       L_x is positive. 
; 
;       if L_x is negative or zero, result is 1 (3fff ffff). 
;--------------------------------------------------------------------------- 
;  Algorithm: 
; 
;   The function 1/sqrt(L_x) is approximated by a table and linear 
;   interpolation. 
; 
;   1- Normalization of L_x. 
;   2- If (30-exponent) is even then shift right once. 
;   3- exponent = (30-exponent)/2  +1 
;   4- i = bit25-b31 of L_x,    16 <= i <= 63  ->because of normalization. 
;   5- a = bit10-b24 
;   6- i -=16 
;   7- L_y = InvSqrtTable[i]<<16 - (InvSqrtTable[i] - InvSqrtTable[i+1]) * a * 2 
;   8- L_y >>= exponent 
;--------------------------------------------------------------------------- 
;  Input: A = L_x(32) > 0 
; 
;  Output : A(32) = 1 / sqrt(L_x) , DP = 0 
;--------------------------------------------------------------------------- 
                .ref    InvSqrtTable 
one_hi          .set    0x3fff      ; Q30 
one_lo          .set    0xffff      ; 
 
Inv_sqrt: 
        BCD     Exit_Inv_sqrt, ALEQ 
        LD      #30, B 
        EXP     A 
        LD      #0, DP 
        SUB     T, B                ; exp = 30 - exp 
        NORM    A, A 
 
        SFTA    B, -1, B 
        ADD     #1, B 
        XC      1, NC 
        LD      A, -1, A 
        NEG     B 
        NOP 
        LD      BL, ASM             ; ASM = - exp 
 
        LD      A, -10, B 
        LD      B, -15, A 
        XOR     A, 15, B 
        SUB     #16, A 
        ADD     #InvSqrtTable, A 
        STL     A, AR5 
        STL     B, T 
        NOP 
 
        LD      *AR5+, 16, B 
        SUB     *AR5, 16, B, A 
        MPYA    A 
        RETD 
        SUB     A, B 
        LD      B, ASM, A 
 
Exit_Inv_sqrt 
        LD      #one_hi, 16, A 
        RETD 
        STM     #one_lo, AL