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


;===================================================== 
;  File Name 
;  ---------- 
;  PIT_FR3.ASM 
; 
;  Brief Description of the Code: 
;  ------------------------------ 
;  Find the pitch period with 1/3 subsample resolution. 
; 
;  Ref 
;  ------ 
;  PITCH_A.C 
;====================================================== 
; Word16 Pitch_fr3_fast(  /* (o) : pitch period.             */ 
;   Word16 exc[],    /* (i) : excitation buffer         */ 
;   Word16 xn[],     /* (i) : target vector             */ 
;   Word16 h[],      /* (i)Q12 : impulse response of filters.*/ 
;   Word16 L_subfr,  /* (i) : Length of subframe         */ 
;   Word16 t0_min,   /* (i) : minimum value in the searched range.*/ 
;   Word16 t0_max,   /* (i) : maximum value in the searched range.*/ 
;   Word16 i_subfr,  /* (i) : indicator for first subframe.*/ 
;   Word16 *pit_frac /* (o) : chosen fraction.             */ 
; ) 
;------------------------------------------------------- 
;  Constants :  Addr_T0 -> T0 = output of Pitch_fr3 
;               Addr_T0_frac -> pit_frac 
;               Addr_T0_min  -> t0_min 
;               Addr_T0_max  -> t0_max 
;               Addr_i_subfr -> i_subfr 
; 
;               Addr_xn1 -> xn 
;               Addr_h1  -> h1 
; 
;               L_SUBFR = L_subfr 
; 
;  Pointers  :  ptr_exc_subfrm -> exc 
;---------------------------------------------------- 
;  Local memory : Addr_pitch_fr3_buf 
;---------------------------------------------------- 
;  The following variables must be in same data page : 
;               Addr_T0 -> T0 
;               Addr_T0_frac -> pit_frac 
;               Addr_T0_min  -> t0_min 
;               Addr_T0_max  -> t0_max 
;               Addr_i_subfr -> i_subfr 
;------------------------------------------------------ 
;  T0=Pitch_fr3(&exc[i_subfr],xn,h1,L_SUBFR,T0_min, 
;                           T0_max,i_subfr,&T0_frac); 
;------------------------------------------------------ 
;  Modified Registers : AR0, AR1, AR2, AR3, BRC 
;------------------------------------------------------ 
		.mmregs 
        .include ..\include\const.h 
        .include ..\include\struct.h 
        .include ..\include\ld8amem.h 
 
        .text 
        .def     Pitch_fr3_fast 
 
        .ref     Norm_Corr 
        .ref     Corr_h_x 
        .ref     Interpol_3 
        .ref     Dot_product 
        .ref     Pred_lt_3 
 
param_norm_corr .tag     Str_Norm_Corr 
 
        .asg     "AR1", pCorr_norm 
 
        .asg     "Addr_pitch_fr3_buf", corr_v 
        .asg     "Addr_pitch_fr3_buf+40", max		;32bit 
        .asg     "Addr_pitch_fr3_buf+42", lag 
        .asg     "Addr_pitch_fr3_buf+43", corr 
        .asg     "Addr_pitch_fr3_buf+44", frac 
        .asg     "Addr_pitch_fr3_buf+45", index 
        .asg     "Addr_pitch_fr3_buf+46", exc_tmp 
 
Pitch_fr3_fast: 
 
        LD      #param_norm_corr, DP 
        MVKD    #ptr_exc, param_norm_corr.ptr_exc 
        ST      #Addr_xn1, param_norm_corr.ptr_xn 
        ST      #Addr_h1, param_norm_corr.ptr_h 
        MVKD    #Addr_T0_min, param_norm_corr.t_min 
        MVKD    #Addr_T0_max, param_norm_corr.t_max 
 
;------------------------------------------------------------ 
; Compute correlation of target vector with impulse response 
;------------------------------------------------------------ 
        CALLD    Corr_h_x 
		STM #Addr_xn1,AR5         
 
;----------------------------- 
; Find maximum integer delay. 
;----------------------------- 
        LD      #param_norm_corr, DP 
        LD      param_norm_corr.t_max, B 
        SUB     param_norm_corr.t_min, B 
        MVDM    param_norm_corr.t_min, AR0 ; t = T0_min 
        STLM    B, BRC 
        MVMM    AR0,AR1            ; to = T0_min 
 
        RPTBD   EndFindMax - 1 
        LD      #0x8000, 16, B            ; max = MIN_32 
 
                MVDM    param_norm_corr.ptr_exc, AR4   ; AR4 -> exc[0] 
                STM     #Addr_Dn, AR3 
                MAR     *AR4-0          ; AR4 -> exc[-t] 
                CALLD   Dot_product    ; corr = Dot_Product()       
				STM	#L_SUBFR-1,AR6 
 
                MAX     B               ; max(corr,max) 
                NOP 
                NOP 
                XC      1, NC 
                        MVMM    AR0, AR1        ; t -> t0 
                MAR     *AR0+                   ; t++ 
EndFindMax: 
 
        DST     B, *(max) 
        LD      #Addr_T0, DP 
        MVMD    AR1, Addr_T0 
 
 
;----------------------- 
; Test fractions. 
;----------------------- 
        LD      #Addr_T0_frac, DP 
        ST      #0, Addr_T0_frac     ;frac = 0 
        LD      #param_norm_corr, DP 
        LD      param_norm_corr.ptr_exc, A 
        LD      #ptr_exc_subfrm, DP 
        STL	A, ptr_exc_subfrm 
        CALL    Pred_lt_3 
 
        LD      #param_norm_corr, DP 
        MVDM    param_norm_corr.ptr_exc, AR4   ;AR4 -> exc[0] 
        STM     #Addr_Dn, AR3                  ;AR3 -> Dn 
        CALLD   Dot_product          ;corr = Dot_Product() 
		STM	#L_SUBFR-1,AR6 
 
		DST	A,*(max)	 
        LD      #Addr_pit_frac, DP 
        ST      #0, Addr_pit_frac    ; *pit_frac=0   *pit_frac = T0_frac 
 
;----------------------------------------------------------------- 
; If first subframe and lag>84 do not serch fractional pitch 
;----------------------------------------------------------------- 
 
        LD      #Addr_i_subfr, DP 
        LD      Addr_i_subfr, A 
        BC      NotFirstSubfrlag, ANEQ 
                 
        LD      #Addr_T0, DP 
        LD      Addr_T0, A 
        SUB     #84, A 
		BC	NotFirstSubfrlag,ALEQ 
                RET                  ;return t0 
 
NotFirstSubfrlag: 
 
;------------------------------------- 
; copy(exc, exc_tmp, L_subfr) 
;------------------------------------- 
        LD      #param_norm_corr, DP 
        MVDM    param_norm_corr.ptr_exc, AR4   ;AR4 -> exc[0] 
        STM     #exc_tmp, AR5 
        RPT     #L_SUBFR - 1 
                MVDD    *AR4+, *AR5+ 
 
;------------------------------------- 
; Fraction -1/3 
;------------------------------------- 
        LD      #Addr_T0_frac, DP 
        ST      #-1, Addr_T0_frac     ;frac = -1 
        CALL    Pred_lt_3 
 
        LD      #param_norm_corr, DP 
        MVDM    param_norm_corr.ptr_exc, AR4   ;AR4 -> exc[0] 
        STM     #Addr_Dn, AR3                  ;AR3 -> Dn 
        CALLD   Dot_product                    ;corr = Dot_Product() 
		STM	#L_SUBFR-1,AR6 
 
        DLD      *(max), B 
        LD      #Addr_pit_frac, DP 
        MAX     B 
        NOP 
        NOP 
        BC      EndFraction1, C 
                ST      #-1, Addr_pit_frac      ;*pit_frac=-1 
                DST     B, *(max) 
 
       ;------------------------------------- 
       ; copy(exc, exc_tmp, L_subfr) 
       ;------------------------------------- 
                LD      #param_norm_corr, DP 
                MVDM    param_norm_corr.ptr_exc, AR4   ;AR4 -> exc[0] 
                STM     #exc_tmp, AR5 
                RPT     #L_SUBFR - 1 
                        MVDD    *AR4+, *AR5+ 
EndFraction1: 
;------------------------------------- 
; Fraction +1/3 
;------------------------------------- 
        LD      #Addr_T0_frac, DP 
        ST      #1, Addr_T0_frac     ;frac = 1 
        CALL    Pred_lt_3 
 
        LD      #param_norm_corr, DP 
        MVDM    param_norm_corr.ptr_exc, AR4   ;AR4 -> exc[0] 
        STM     #Addr_Dn, AR3                  ;AR3 -> Dn 
        CALLD   Dot_product                    ;corr = Dot_Product() 
		STM	#L_SUBFR-1,AR6 
 
        DLD      *(max), B 
        LD      #Addr_pit_frac, DP 
        MAX     B 
        NOP 
        NOP 
        BC      EndFraction2, C 
                ST      #1, Addr_pit_frac      ;*pit_frac=1 
                DST     B, *(max) 
EndFraction2: 
        BC      EndPitchFr3, NC 
        ;------------------------------------- 
        ; copy(exc_tmp, exc, L_subfr) 
        ;------------------------------------- 
                LD      #param_norm_corr, DP 
                MVDM    param_norm_corr.ptr_exc, AR5   ;AR5 -> exc[0] 
                STM     #exc_tmp, AR4 
                RPT     #L_SUBFR - 1 
                        MVDD    *AR4+, *AR5+ 
 
EndPitchFr3: 
 
		LD	*(Addr_pit_frac), A 
		STL	A, *(Addr_T0_frac) 
		 
        RET                     ;return t0