⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pitch_a.asm

📁 G.729协议压缩的语音传输程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
                .mmregs
                .include  "ld8a.inc"
                .ref      Inv_sqrt
                .ref      Cor_h_X
                .ref      Pred_lt_3
                .global  _Pitch_ol_fast
                .bss  scaled_signal,L_FRAME+PIT_MAX
                .bss  Dn,L_SUBFR
                .bss  exc_tmp,L_SUBFR
                
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Compute the open loop pitch lag. (fast version)
;Word16 Pitch_ol_fast(  /* 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           */
;) 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_Pitch_ol_fast:
   pshm  st0
   pshm  st1
   pshm  ar0
   pshm  ar1
   pshm  ar2
   pshm  ar3
   pshm  ar4
   pshm  ar5
   pshm  ar6
   pshm  ar7
   
   frame  -22    ;*sp(0)--i,*sp(1)--j,*sp(2)--max1, *sp(3)--max2
                 ;*sp(4)--max3,*sp(5)--max_h,*sp(6)--max_l,
                 ;*sp(7)--ener_h,*sp(8)--ener_l,*sp(9)--T1,
                 ;*sp(10)--T2,*sp(11)--T3,*sp(12)--p,*sp(13)--p1
                 ;*sp(14)(15)--max,*sp(16)(17)--sum,*sp(18)(19)--L_temp
                 ;*sp(20)--scal_sig,*sp(21)--signal
                 ;*sp(33)--pit_max,*sp(34)--L_frame
   ssbx  ovm
   ssbx  sxm
   ssbx  frct
   stl   a,*sp(21) ;save pointer of signal 
   
   mvdk  *sp(33),ar0
   stm   #scaled_signal,ar3   
   ld    *ar3+0,a           ;ar3--scal_sig = &scaled_signal[pit_max]
   mvkd  ar3,*sp(20)
 ;Verification for risk of overflow
   ;compute repeat counte times
   ld    *sp(33),16,a    ;compute repeat counter i,for(i= -pit_max; i< L_frame; i+=2)
   add   *sp(34),16,a    ;pit_max+L_frame
   sub   #1,a            ;pit_max+L_frame-1
   sth   a,*sp(1)        ;for(i=-pit_max; i<L_frame; i++)
   ld    a,-1,a          ;(pit_max+L_frame-1)/2
   sth   a,*sp(0)        ;save to i
   
   mvdk  *sp(21),ar2     ;ar2--signal
   ld    *ar2-0,a        ;ar2--signal[-pit_max]
   
   stm   #2,ar0    ;increase of 2
   
   rsbx  ovb       ;   Overflow = 0
   ld    #0,b      ;   sum = 0   
   
   rpt   *sp(0)    ;for(i= -pit_max; i< L_frame; i+=2)
   squra *ar2+0,b   ;sum = L_mac(sum, signal[i], signal[i])
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ; * Scaling of input signal.                               *
  ; *                                                        *
  ; *   if Overflow        -> scal_sig[i] = signal[i]>>3     *
  ; *   else if sum < 1^20 -> scal_sig[i] = signal[i]<<3     *
  ; *   else               -> scal_sig[i] = signal[i]        *  
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
   mvdk  *sp(33),ar0     
   mvdk  *sp(21),ar2     ;ar2--signal
   ld    *ar2-0,a        ;ar2--signal[-pit_max]  

   bc    pitch_olnflow,bnov
   
   mvdk  *sp(1),brc
   ssbx  braf
   rptb  pitch_ol_rep1-1
   ld    *ar2+,16,a
   sth   a,-3,*ar3+
pitch_ol_rep1:
   b     pitch_olexit 
pitch_olnflow:
   sub   #1000h,8,b
   bc    pitch_olgreat,bgeq
   mvdk  *sp(1),brc
   ssbx  braf
   rptb  pitch_ol_rep2-1
   ld    *ar2+,16,a
   sth   a,3,*ar3+
pitch_ol_rep2:   
   b     pitch_olexit
pitch_olgreat:
   rpt   *sp(1)
   mvdd  *ar2+,*ar3+
pitch_olexit:
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;   *  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 maxima of each section by favoring small lag.      *
  ;    *                                                                    *
  ;    *  First section:  lag delay = 20 to 39                              *
  ;    *  Second section: lag delay = 40 to 79                              *
  ;    *  Third section:  lag delay = 80 to 143                             *
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;
  ;First section
  ;;;;;;;;;;;;;;;;;;;;
  st     #20,*sp(9)     ;T1  = 20
  
  ld     *sp(34),a      ;compute repeat times
  sub    #1,a         
  ld     a,-1,a         ;for (j=0; j<L_frame; j+=2)
  stl    a,*sp(1)       ;j=repeat times  
  
  ld     *sp(20),a
  sub    #20,a
  stl    a,*sp(13)       ;p1=&scal_sig[-i]
  stm    #2,ar0         ;increase of  2
  
  st     #20,*sp(0)     ;for (i = 20; i < 40; i++)

  ld     #8000h,16,b    ;max = MIN_32
pitch_olfirst_rep:
  mvdk   *sp(20),ar4    ;ar4--scal_sig
  mvdk   *sp(13),ar5     ;ar5--&scal_sig[-i]
  ld     #0,a           ;sum = 0

  mvdk   *sp(1),brc      ;for (j=0; j<L_frame; j+=2)
  ssbx   braf
  rptb   pitch_olfirst-1
  ld     *ar4+0,t
  mac    *ar5+0,a
pitch_olfirst:
  max    b                   ;L_temp = L_sub(sum, max)
  ld     *sp(9),a            ;if (L_temp > 0) { max = sum; T1 = i;   }
  nop
  xc     1,nc
  ld     *sp(0),a
  stl    a,*sp(9)
  
  addm   #-1,*sp(13)
  addm   #1,*sp(0)
  ld     *sp(0),16,a
  sub    #40,16,a
  bc     pitch_olfirst_rep,alt
  sth    b,*sp(5)           ;L_Extract(max, &max_h, &max_l)
  sub    *sp(5),16,b
  ld     b,-1,b
  stl    b,*sp(6)
  ;compute energy of maximum
  ld     *sp(20),a
  sub    *sp(9),a
  stlm   a,ar4       ;p = &scal_sig[-T1]
  
  ld     #1,b        ;sum = 1
  
  rpt   *sp(1)         ;for(i=0; i<L_frame; i+=2, p+=2)
  squra  *ar4+0,b
  ;max1 = max/sqrt(energy)
  ;This result will always be on 16 bits 
  ld    b,a
  call  Inv_sqrt    ;sum = Inv_sqrt(sum), result in Q30
  sth   a,*sp(7)     ;L_Extract(sum, &ener_h, &ener_l)
  sub   *sp(7),16,a
  ld    a,-1,a
  stl   a,*sp(8)
  
  ld    *sp(5),t     ;sum  = Mpy_32(max_h, max_l, ener_h, ener_l)
  mpy   *sp(7),b
    
  mpy     *sp(8),a
  add     a,-15,b
    
  ld      *sp(6),t
  mpy     *sp(7),a
  add     a,-15,b
  
  stl     b,*sp(2)
  ;;;;;;;;;;;;;;;;;;;;;
  ;Second section
  ;;;;;;;;;;;;;;;;;;;;;
  st     #40,*sp(10)     ;T2  = 40
  
  ld     *sp(20),a
  sub    #40,a
  stl    a,*sp(13)       ;p1=&scal_sig[-i]
  stm    #2,ar0         ;increase of  2
  
  st     #40,*sp(0)     ;for (i = 40; i < 80; i++)

  ld     #8000h,16,b    ;max = MIN_32
pitch_olsecond_rep:
  mvdk   *sp(20),ar4    ;ar4--scal_sig
  mvdk   *sp(13),ar5     ;ar5--&scal_sig[-i]
  ld     #0,a           ;sum = 0

  mvdk   *sp(1),brc      ;for (j=0; j<L_frame; j+=2)
  ssbx   braf
  rptb   pitch_olsecond-1
  ld     *ar4+0,t
  mac    *ar5+0,a
pitch_olsecond:
  max    b                   ;L_temp = L_sub(sum, max)
  ld     *sp(10),a            ;if (L_temp > 0) { max = sum; T2 = i;   }
  nop
  xc     1,nc
  ld     *sp(0),a
  stl    a,*sp(10)
  
  addm   #-1,*sp(13)
  addm   #1,*sp(0)
  ld     *sp(0),16,a
  sub    #80,16,a
  bc     pitch_olsecond_rep,alt
  sth    b,*sp(5)           ;L_Extract(max, &max_h, &max_l)
  sub    *sp(5),16,b
  ld     b,-1,b
  stl    b,*sp(6)
  ;compute energy of maximum
  ld     *sp(20),a
  sub    *sp(10),a
  stlm   a,ar4       ;p = &scal_sig[-T2]
  
  ld     #1,b        ;sum = 1
  
  rpt   *sp(1)         ;for(i=0; i<L_frame; i+=2, p+=2)
  squra  *ar4+0,b
  ;max1 = max/sqrt(energy)
  ;This result will always be on 16 bits 
  ld    b,a
  call  Inv_sqrt    ;sum = Inv_sqrt(sum), result in Q30
  sth   a,*sp(7)     ;L_Extract(sum, &ener_h, &ener_l)
  sub   *sp(7),16,a
  ld    a,-1,a
  stl   a,*sp(8)
  
  ld    *sp(5),t     ;sum  = Mpy_32(max_h, max_l, ener_h, ener_l)
  mpy   *sp(7),b
    
  mpy     *sp(8),a
  add     a,-15,b
    
  ld      *sp(6),t
  mpy     *sp(7),a
  add     a,-15,b
  
  stl     b,*sp(3)   ;max2 = extract_l(sum)
  ;;;;;;;;;;;;;;;;;;;;;
  ;Third section
  ;;;;;;;;;;;;;;;;;;;;;
  st     #80,*sp(11)     ;T3  = 80
  
  ld     *sp(20),a
  sub    #80,a
  stl    a,*sp(13)       ;p1=&scal_sig[-i]
  stm    #2,ar0         ;increase of  2
  
  st     #80,*sp(0)     ;for (i = 80; i < 143; i+2)

  ld     #8000h,16,b    ;max = MIN_32
pitch_olthird_rep:
  mvdk   *sp(20),ar4    ;ar4--scal_sig
  mvdk   *sp(13),ar5     ;ar5--&scal_sig[-i]
  ld     #0,a           ;sum = 0

  mvdk   *sp(1),brc      ;for (j=0; j<L_frame; j+=2)
  ssbx   braf
  rptb   pitch_olthird-1
  ld     *ar4+0,t
  mac    *ar5+0,a
pitch_olthird:
  max    b                   ;L_temp = L_sub(sum, max)
  ld     *sp(11),a            ;if (L_temp > 0) { max = sum; T3 = i;   }
  nop
  xc     1,nc
  ld     *sp(0),a
  stl    a,*sp(11)
  
  addm   #-2,*sp(13)
  addm   #2,*sp(0)
  ld     *sp(0),16,a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -