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


;=============================================================== 
;  File Name 
;  ---------- 
;  ENERGY.ASM 
; 
;  Brief Description of the Code: 
;  ------------------------------ 
;  Find the lag that has maximum correlation with scal_sig[] 
;  Compute energy of maximum 
; 
;  Ref 
;  ------ 
;  PITCH_A.C 
;=============================================================== 
;  energy 
;--------------------------------------------------------------- 
;  arguments: 
; 
;    signal[]   :Signal used to compute the open loop pitch. 
;    L_frame    :Length of frame to compute pitch. 
;    lag_max    :Maximum lag 
;    lag_min    :Minimum lag 
;    *cor_max   ;Maximum of normalized correlation of lag found. 
; 
;  Return lag found. 
;--------------------------------------------------------------- 
;  Str_Lag_max        .struct 
;  ptr_signal         .word   1 
;  lag_max            .word   1 
;  lag_min            .word   1 
;  ptr_cor_max        .word   1 
;  Str_Lag_max_Len    .endstruct 
;--------------------------------------------------------------- 
;  Buffer : Addr_lag_max_buf[2] at even boundary 
;--------------------------------------------------------------- 
;  Output : AR5 = max 
;  Modified Registers: AR4, AR5 
;--------------------------------------------------------------- 
		.MMREGS 
		.include ..\include\const.h 
		.include ..\include\struct.h 
		.include ..\include\ld8amem.h 
 
                .def     energy 
		.ref     Inv_sqrt               ; dspfunc.asm 
 
param_lag_max   .tag     Str_Lag_max 
 
		.asg     "Addr_lag_max_buf", max 
                .asg     "Addr_lag_max_buf+2", inv_energy   
 
                .asg     "ptr_wsp",                  signal 
                .asg     "Addr_pitch_ol_buf",        scal_sig 
                .asg     "scal_sig+PIT_MAX+L_FRAME", max3 
                .asg     "max3+1",                   max2 
                .asg     "max2+1",                   max1 
                .asg     "max1+1",                   p_max3 
                .asg     "p_max3+1",                 p_max2 
                .asg     "p_max2+1",                 p_max1 
 
;------------------------------------------------------------- 
;  note : param_lag_max is set at Addr_pitch_ol_buf + 230, 
;         which is same data page as Addr_lag_max_buf 
;------------------------------------------------------------- 
 
        .asg     "AR1", p_max 
		.asg     "AR4", pTemp 
		.asg     "AR5", pMax 
 
		.asg     "AR4", pSig 
		.asg     "AR5", pSig1 
 
energy: 
 
        STM     #scal_sig+PIT_MAX, pSig ; pSig -> scal_sig[0] 
        MVMM    p_max, AR0 
        NOP 
        MAR     *pSig-0                 ; pSig -> scal_sig[-p_max] 
 
        LD      #L_FRAME, 0, A 
        ROR     A 
        SUB     #1, 0, A 
        STLM    A, AR6 
        LD      #1, 0, A              ; to avoid division by zero 
 
L0:             SQURA    *pSig, A 
                MAR      *+pSig(2) 
                BANZ     L0, *AR6- 
 
        LD      #0, DP 
        CALLD   Inv_sqrt             ; A = ener 
        STM     #AL, pTemp 
                NOP 
        STM     #inv_energy, pTemp   ; pTemp -> inv_energy_h 
 
        STL     A, -16, *pTemp 
        NOP 
        LD      *pTemp+, 15, B 
        LD      A, -1, A 
        SUB     B, A 
        STL     A, *pTemp 
 
 
        STM     #inv_energy, pTemp      ; pTemp -> inv_energy_h 
        STM     #max+1, pMax            ; pMax -> max_l 
        LD      #0, B 
        LD      #0, A 
        MACSU   *pMax-,  *pTemp+, B     ; B += max_l * inv_energy_h 
        LD      B, -16, B 
        LD      B, 1, B 
        MACSU   *pTemp-, *pMax,   A     ; B += max_h * inv_energy_l 
        LD      A, -16, A 
        LD      A, 1, A 
        ADD     A, B 
        MAC     *pTemp, *pMax, B 
                
        MVDM    param_lag_max.ptr_cor_max, AR5 
        NOP 
        NOP 
        STL     B, *AR5 
        RET