home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / lpc.asm < prev    next >
Encoding:
Assembly Source File  |  1992-06-12  |  5.8 KB  |  220 lines

  1.     page    132,63,1,1
  2.     opt    rc
  3.     title    'LPC Vocoder'
  4.  
  5. ;***************************************************************
  6. ;* LPC.ASM -- 2400 bit/s LPC Vocoder main control loop           *
  7. ;*                                   *
  8. ;* Provides main control loop of the LPC codec. Wait (in order *
  9. ;* to reduce power consumption) for a one frame to be sampled. *
  10. ;* Then analyze it, send to the host computer (via serial line)*
  11. ;* check if block from the host computer has been received, and*
  12. ;* if there are any, then synthesize it.               *
  13. ;*                                   *
  14. ;* This module reserves registers as follows:               *
  15. ;*  r7 - input/output sample pointer                   *
  16. ;*                                   *
  17. ;* Copyright (C) 1992 by Alef Null. All rights reserved.       *
  18. ;* Author(s): Jarkko Vuori, OH2LNS                   *
  19. ;* Modification(s):                           *
  20. ;***************************************************************
  21.  
  22.     nolist
  23.     include 'ioequlc'
  24.     list
  25.  
  26.     section LPC
  27.  
  28.     xdef    ssi_ini,lpc_i,m_loop
  29.     xref    m_cra,m_crb,m_tde,m_sr,m_tx
  30.     xref    lpc_ana,lpc_syn
  31.  
  32.     org    p:
  33.  
  34.     nolist
  35.     include 'macros'
  36.     list
  37.  
  38.  
  39. ;****************************
  40. ;*    SSI initialization    *
  41. ;****************************
  42. ssi_ini
  43. ; initialize SSI,
  44.     IF    !DEBUG
  45.     movep            #$4000,x:m_cra        ; 16 bit word
  46.     movep            #$7200,x:m_crb        ; syncronous,word frame,ext clk
  47.     ELSE
  48.     movep            #$6008,x:m_cra        ; 24 bit word (because simulator won't read fractinal values correctly in 16 bit mode)
  49.     movep            #$7620,x:m_crb        ; syncronous,word frame,ext clk
  50.     ENDIF
  51.  
  52.     rts
  53.  
  54.  
  55. ;****************************
  56. ;*      ADC & LPC        *
  57. ;*    initialization        *
  58. ;****************************
  59. lpc_i
  60. ; program the A/D & D/A converter chip (TLC32044, master clock is 5.184MHz)
  61. ; enable A/D high-pass filter, disable loopback, disable AUX IN,
  62. ; select syncronous mode, select input span 1.5Vpp, insert sinx/x correction
  63. ; lowpass cutoff frequency at    3600Hz -> TA  =  9 (SCF = 288kHz)
  64. ; sampling frequency is     8000Hz -> TB  = 36
  65. ; unit sampling correction time  0.4uS -> TA' =  2
  66.     pgmtlc    %10101001,9,2,36
  67.  
  68. ; initialize input and output sample buffer pointers
  69.     move            #samples,r7
  70.     move            #3*M-1,m7
  71.     move            r7,x:samptr
  72.  
  73. ; initialize flags and parameters
  74.     move            #(1<<loopb),a1
  75.     clr    a        a1,x:<flags
  76.     move            a,x:<p_d
  77.  
  78.     rts
  79.  
  80.  
  81. ;****************************
  82. ;*      Main Loop        *
  83. ;****************************
  84. loop    wait
  85. m_loop
  86.  
  87. ; check if one frame converted
  88.     move            x:samptr,a
  89.     move            r7,x0
  90.     sub    x0,a        #>M,x0
  91.     cmpm    x0,a
  92.     jlo    <loop
  93.  
  94. ; then analyze it, encode parameters and send them to output
  95.     jsr    <lpc_ana
  96.     jsr    <lpc_encode
  97.     jsr    <put_blk
  98.  
  99. ; receive parameters for synthesizer
  100.     jsr    <get_blk
  101.     jcc    <_okblk
  102.     clr    a                    ; reset output if no new block received
  103.     move    a,x:lpcin
  104.     move    a,x:lpcin+1
  105.  
  106. ; decode those parameters and synthesize voice
  107. _okblk    jclr    #loopb,x:<flags,_normb
  108.     move            x:lpcout,a1
  109.     move            a1,x:lpcin
  110.     move            x:lpcout+1,a1
  111.     move            a1,x:lpcin+1
  112.  
  113. _normb    jsr    <lpc_decode
  114.     jsr    <lpc_syn
  115.  
  116. ; finally update current frame pointer
  117.     move            x:samptr,r0
  118.     move            #M,n0
  119.     move            #3*M-1,m0
  120.     nop
  121.     move            (r0)+n0
  122.     move            r0,x:samptr
  123.  
  124.     jmp    <loop
  125.  
  126.  
  127. ;****************************
  128. ;*     DATA - AREA        *
  129. ;****************************
  130.  
  131.     xdef    flags,p_d
  132.     xdef    p_code,g_code,k_code
  133.     xdef    p_s,g_s,k_s
  134.     xdef    samptr
  135.  
  136.     org    x:
  137.  
  138. ; Global parameters
  139. flags    ds    1                    ; global Vocoder flags
  140. p_d    ds    1                    ; pitch adjustment
  141.  
  142. ; Parameters for LPC analysis
  143. p_code    ds    1                    ; pitch estimate
  144. g_code    ds    1                    ; gain estimate
  145. k_code    ds    P                    ; estimated reflection coefficients
  146.  
  147. ; Parameters for LPC sythesis
  148. p_s    ds    1                    ; current pitch period
  149. g_s    ds    1                    ; gain for current output frame
  150. k_s    ds    P                    ; current reflection coefficients
  151.  
  152. ; Global internal variables
  153. samptr    ds    1                    ; start of current input/output frame pointer
  154.  
  155.     endsec
  156.  
  157.  
  158.     section Samples
  159.  
  160.     xdef    samples,temp,lotaps,hamming,glottal
  161.  
  162.     nolist
  163.     include 'macros'
  164.     list
  165.  
  166.  
  167.     org    x:
  168.  
  169. samples ds    3*M                    ; input sample buffer
  170.     ds    512-3*M
  171.  
  172. temp    ds    N
  173.  
  174. ; Hamming window
  175. hamming
  176. dum    set    0
  177.     dup    N
  178.     dc    0.54-0.46*@cos(6.283185*@cvf(dum)/@cvf(N))
  179. dum    set    dum+1
  180.     endm
  181.  
  182.  
  183.     org    y:
  184.  
  185.     ds    3*M                    ; output sample buffer
  186.     ds    512-3*M
  187.  
  188. ; 900 Hz lowpass filter generated using Parks-McClellan algorithm
  189. ;   sampling rate   8000 Hz
  190. ;   passband edge    840 Hz
  191. ;   stop band edge   960 Hz
  192. ;   filter lenght     79 taps
  193. lotaps    dc     1.619394e-02,5.805688e-03,3.155693e-03,-1.500173e-03,-6.545769e-03
  194.     dc    -9.963868e-03,-1.022255e-02,-7.061145e-03,-1.754771e-03,3.332559e-03
  195.     dc     5.765334e-03,4.199639e-03,-8.617942e-04,-7.138900e-03,-1.151400e-02
  196.     dc    -1.147496e-02,-6.426490e-03,1.780802e-03,9.467491e-03,1.274443e-02
  197.     dc     9.432186e-03,3.507424e-04,-1.070496e-02,-1.840716e-02,-1.827196e-02
  198.     dc    -9.051937e-03,6.112294e-03,2.066623e-02,2.704929e-02,2.031219e-02
  199.     dc     9.089151e-04,-2.437167e-02,-4.415325e-02,-4.639930e-02,-2.320264e-02
  200.     dc     2.545267e-02,9.059131e-02,1.564397e-01,2.052803e-01,2.232958e-01    ; center tap
  201.     dc     2.052803e-01,1.564397e-01,9.059131e-02,2.545267e-02,-2.320264e-02
  202.     dc    -4.639930e-02,-4.415325e-02,-2.437167e-02,9.089151e-04,2.031219e-02
  203.     dc     2.704929e-02,2.066623e-02,6.112294e-03,-9.051937e-03,-1.827196e-02
  204.     dc    -1.840716e-02,-1.070496e-02,3.507424e-04,9.432186e-03,1.274443e-02
  205.     dc     9.467491e-03,1.780802e-03,-6.426490e-03,-1.147496e-02,-1.151400e-02
  206.     dc    -7.138900e-03,-8.617942e-04,4.199639e-03,5.765334e-03,3.332559e-03
  207.     dc    -1.754771e-03,-7.061145e-03,-1.022255e-02,-9.963868e-03,-6.545769e-03
  208.     dc    -1.500173e-03,3.155693e-03,5.805688e-03,1.619394e-02
  209.  
  210. ; DoD stadard glottal pulse excitation
  211. ; Normalized for unity gain
  212. glottal dc    .249,-.262,.363,-.362,.100,.367,.079,.078,.010,-.277
  213.     dc    -.082,.376,.288,-.065,-.020,.138,-.062,-.315,-.247,-.078
  214.     dc    -.082,-.123,-.039,.065,.064,.019,.016,.032,.018,-.015
  215.     dc    -.029,-.021,-.018,-.027,-.031,-.022,-.012,-.010,-.010,-.004
  216.  
  217.     endsec
  218.  
  219.     end
  220.