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


;================================================================ 
;  File Name 
;  ---------- 
;  PIT_OL_F.ASM 
; 
;  Brief Description of the Code: 
;  ------------------------------ 
;  Compute the open loop pitch lag 
; 
;  Ref 
;  ------ 
;  PITCH_A.C 
;================================================================ 
;  Pitch_ol_fast 
;---------------------------------------------------------------- 
;  Word16 Pitch_ol(       /* output: open loop pitch lag                        */ 
;     Word16 signal[],    /* input : signal used to compute the open loop pitch */ 
;                         /*     signal[-pit_max] to signal[-1] should be known */ 
;     Word16   pit_max,   /* input : maximum pitch lag                          */ 
;     Word16   L_frame    /* input : length of frame to compute pitch           */ 
;  ) 
;---------------------------------------------------------------- 
;  Constants : PIT_MAX = pit_max 
;              PIT_MIN = pit_min 
;              L_FRAME = L_frame 
; 
;  Pointers  : ptr_wsp -> signal 
; 
; 
;  Buffer    : Addr_pitch_ol_buf[240] 
; 
;  Output    : A = lag 
; 
;  Modified Registers : AR2, AR3 
;---------------------------------------------------------------- 
		.mmregs 
        .include ..\include\const.h 
        .include ..\include\struct.h 
        .include ..\include\ld8amem.h 
 
        .text 
        .def     Pitch_ol_fast 
 
        .ref     mov_warn 
        .ref     energy 
        .ref     mov_war3 
        .ref     test_around_lag_max_3 
        .ref     test_multiple 
 
param_lag_max   .tag     Str_Lag_max 
 
        .asg     "AR1", pSigRef 
        .asg     "AR2", pSignal 
        .asg     "AR3", pScal_sig 
 
        .asg     "Addr_lag_max_buf",         max 
        .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 max1, max2.... 
;---------------------------------------------------------------- 
 
Pitch_ol_fast: 
 
        MVDM    signal, pSigRef               ; pSigRef -> wsp[0] 
        STM     #scal_sig, pScal_sig 
        MAR     *+pSigRef(-PIT_MAX)           ; pSigRef -> &signal[-PIT_MAX] 
        MVMM    pSigRef, pSignal              ;          =  old_wsp[0] 
 
        LD      #PIT_MAX+L_FRAME-1, 0, A 
        ROR     A  
		STL	A, AR6 
        MAR     *AR6- 
		LD	#0, 0, A 
L0: 
        SQURA   *pSignal, A                  ; A <-- *pSigRef**2 
        MAR	*+pSignal(2)                 ; step is 2 
        BANZ    L0,*AR6- 
 
;-------------------------------------------------------- 
; Scaling of input signal. 
; 
;   if Overflow        -> scal_sig[i] = signal[i]>>3 
;   else if t0 < 1^20  -> scal_sig[i] = signal[i]<<3 
;   else               -> scal_sig[i] = signal[i] 
;-------------------------------------------------------- 
 
        RSBX      OVA 
   ;----------------------- 
 
        SUB     #20h, 15, A, B 
        SAT     A 
        LD      #3, ASM 
        XC      1, C 
                LD      #0, ASM 
        XC      1, AOV 
                LD      #-3, ASM 
 
        MVMM    pSigRef, pSignal 
 
        LD      *pSignal+, 16, A 
        RPT     #PIT_MAX+L_FRAME-1 
                ST      A, *pScal_sig+  ||  LD      *pSignal+, A 
 
;-------------------------------------------------------------- 
;  The pitch lag search is divided in three sections. 
;  Each section cannot have a pitch multiple. 
;  We find a maximum for each section. 
;  We compare the maximum of each section by favoring small lag. 
; 
;  First section:  lag delay = pit_min     to  2*pit_min-1 
;  Second section: lag delay = 2*pit_min   to  4*pit_min-1 
;  Third section:  lag delay = 4*pit_min   to  pit_max 
;--------------------------------------------------------------- 
 
;=============== 
;First section 
;=============== 
 
        LD      #param_lag_max, DP 
        STM     #param_lag_max, AR3 
        ST      #20, p_max1 
        ST      #PIT_MIN<<1, param_lag_max.lag_max 
        ST      #PIT_MIN, param_lag_max.lag_min 
        CALLD    mov_warn 
        ST      #max1, param_lag_max.ptr_cor_max 
        MVMD    AR1, p_max1 
        CALL    energy 
 
;=============== 
;Second section 
;=============== 
 
        LD      #param_lag_max, DP 
        ST      #40, p_max2 
        ST      #PIT_MIN<<2, param_lag_max.lag_max 
        ST      #PIT_MIN<<1, param_lag_max.lag_min 
        CALLD    mov_warn 
        ST      #max2, param_lag_max.ptr_cor_max 
        MVMD    AR1, p_max2 
        CALL    energy 
 
;============== 
;Third section 
;============== 
 
        LD      #param_lag_max, DP 
        ST      #80, p_max3 
        ST      #PIT_MAX, param_lag_max.lag_max 
        ST      #PIT_MIN<<2, param_lag_max.lag_min 
        CALLD   mov_war3 
        ST      #max3, param_lag_max.ptr_cor_max 
        CAll    test_around_lag_max_3 
        MVMD    AR1, p_max3 
        CALL    energy 
;=================== 
; Test for multiple 
;=================== 
        CALL    test_multiple 
 
;================================ 
;Compare the 3 sections maxima. 
;================================ 
; if(sub(max1,max2)<0){max1=max2;T1=T2} 
; if(sub(max1,max3)<0)T1=T3 
; return T1 
        LD      #0, DP 
 
        LD      *(max1), 16, A 
        SUB     *(max2), 16, A 
        NOP 
        BC      K1, AGEQ 
                DELAY   *(max2) 
                DELAY   *(p_max2) 
 
K1:     LD      *(max1), 16, A 
        SUB     *(max3), 16, A 
        NOP 
        NOP 
        BC      K2, AGEQ 
                LD      *(p_max3), B 
                STL     B, *(p_max1) 
 
K2:      LD      *(p_max1), A 
 
        RET