home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / dsp4src / recoder.asm < prev    next >
Encoding:
Assembly Source File  |  1993-03-04  |  5.0 KB  |  197 lines

  1.     page    132,63,1,1
  2.     opt    rc
  3.     title    'LPC Vocoder'
  4.  
  5. ;***************************************************************
  6. ;* RECODER.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. ; Mies katsoo tuossa,
  23. ; on nainen sieltä poissa.
  24. ; Itku katseen samentaa
  25. ; ja särky ohimoissa.
  26. ;
  27. ; Korvissa soi jo kohisten.
  28. ; Kuin takaa järjen rajan
  29. ; nyt mieleen tunkee, täyttää sen
  30. ; vain meri koko ajan.
  31. ;
  32. ; On poissa hän, on lähtenyt
  33. ; pois yhteisiltä teiltä.
  34. ; Vain kipu syöpyy luuhun nyt
  35. ; ja nielee kaiken hältä.
  36. ;
  37. ;    Jacques Berg
  38.  
  39.  
  40.     section Recoder
  41.  
  42.     xref    lpc_ana,lpc_syn
  43.  
  44.     org    p:
  45.  
  46.     nolist
  47.     include 'macros'
  48.     include 'leonid'
  49.     list
  50.  
  51. ; initialize input and output sample buffer pointers
  52.     move            #samples+2,r7
  53.     move            #(3*M)*4-1,m7
  54.  
  55.     move            #samples,r6
  56.     move            #M*4,n6
  57.     move            #(3*M)*4-1,m6
  58.  
  59. ; initialize codec
  60. ; fs = 8 kHz, line input, headphones and line output, max gain and zero attenuation
  61.     ctrlcd    1,r6,3*M,MIC,22.5,22.5,LINEO|HEADP,0.0,0.0
  62.     opencd    8
  63.  
  64. ; initialize flags and parameters
  65.     clr    a
  66.     move            a,x:<flags
  67.     move            a,x:<p_d
  68.     move            #speech,a1
  69.     move            a1,x:<speptr
  70.  
  71.  
  72. ;****************************
  73. ;*      Main Loop        *
  74. ;****************************
  75. loop    waitblk r6,3*M,M
  76.  
  77.     move            x:<speptr,r0
  78.     move            #-1,m0
  79.  
  80. ; check if end of speech
  81.     move            r0,a
  82.     move            #>endspe,x0
  83.     cmp    x0,a
  84.     jne    <go_ahead
  85.     stop                        ; we get reset this way
  86.  
  87. ; load speech data
  88. go_ahead
  89.     move            p:(r0)+,a1
  90.     move            a1,x:lpcin
  91.     move            p:(r0)+,a1
  92.     move            a1,x:lpcin+1
  93.     move            r0,x:<speptr
  94.  
  95. ; decode and synthesize it
  96.     jsr    <lpc_decode
  97.     jsr    <lpc_syn
  98.  
  99. ; finally update current frame pointer
  100.     move            (r6)+n6
  101.  
  102.     jmp    <loop
  103.  
  104.  
  105. ;****************************
  106. ;*     DATA - AREA        *
  107. ;****************************
  108.  
  109.     xdef    flags,p_d
  110.     xdef    p_code,g_code,k_code
  111.     xdef    p_s,g_s,k_s
  112.  
  113.     org    x:
  114.  
  115. ; Global parameters
  116. flags    ds    1                    ; global Vocoder flags
  117. p_d    ds    1                    ; pitch adjustment
  118.  
  119. ; Parameters for LPC analysis
  120. p_code    ds    1                    ; pitch estimate
  121. g_code    ds    1                    ; gain estimate
  122. k_code    ds    P                    ; estimated reflection coefficients
  123.  
  124. ; Parameters for LPC sythesis
  125. p_s    ds    1                    ; current pitch period
  126. g_s    ds    1                    ; gain for current output frame
  127. k_s    ds    P                    ; current reflection coefficients
  128.  
  129. ; Speech data pointer
  130. speptr    ds    1
  131.  
  132.     endsec
  133.  
  134.  
  135.     section Samples
  136.  
  137.     xdef    samples,temp,lotaps,hamming,glottal
  138.  
  139.     nolist
  140.     include 'macros'
  141.     list
  142.  
  143.  
  144.     org    x:
  145.  
  146. samples ds    3*M                    ; input sample buffer
  147.     ds    512-3*M
  148.  
  149. temp    ds    N
  150.  
  151. ; Hamming window
  152. hamming
  153. dum    set    0
  154.     dup    N
  155.     dc    0.54-0.46*@cos(6.283185*@cvf(dum)/@cvf(N))
  156. dum    set    dum+1
  157.     endm
  158.  
  159.  
  160.     org    y:
  161.  
  162.     ds    3*M                    ; output sample buffer
  163.     ds    512-3*M
  164.  
  165. ; 900 Hz lowpass filter generated using Parks-McClellan algorithm
  166. ;   sampling rate   8000 Hz
  167. ;   passband edge    840 Hz
  168. ;   stop band edge   960 Hz
  169. ;   filter lenght     79 taps
  170. lotaps    dc     1.619394e-02,5.805688e-03,3.155693e-03,-1.500173e-03,-6.545769e-03
  171.     dc    -9.963868e-03,-1.022255e-02,-7.061145e-03,-1.754771e-03,3.332559e-03
  172.     dc     5.765334e-03,4.199639e-03,-8.617942e-04,-7.138900e-03,-1.151400e-02
  173.     dc    -1.147496e-02,-6.426490e-03,1.780802e-03,9.467491e-03,1.274443e-02
  174.     dc     9.432186e-03,3.507424e-04,-1.070496e-02,-1.840716e-02,-1.827196e-02
  175.     dc    -9.051937e-03,6.112294e-03,2.066623e-02,2.704929e-02,2.031219e-02
  176.     dc     9.089151e-04,-2.437167e-02,-4.415325e-02,-4.639930e-02,-2.320264e-02
  177.     dc     2.545267e-02,9.059131e-02,1.564397e-01,2.052803e-01,2.232958e-01    ; center tap
  178.     dc     2.052803e-01,1.564397e-01,9.059131e-02,2.545267e-02,-2.320264e-02
  179.     dc    -4.639930e-02,-4.415325e-02,-2.437167e-02,9.089151e-04,2.031219e-02
  180.     dc     2.704929e-02,2.066623e-02,6.112294e-03,-9.051937e-03,-1.827196e-02
  181.     dc    -1.840716e-02,-1.070496e-02,3.507424e-04,9.432186e-03,1.274443e-02
  182.     dc     9.467491e-03,1.780802e-03,-6.426490e-03,-1.147496e-02,-1.151400e-02
  183.     dc    -7.138900e-03,-8.617942e-04,4.199639e-03,5.765334e-03,3.332559e-03
  184.     dc    -1.754771e-03,-7.061145e-03,-1.022255e-02,-9.963868e-03,-6.545769e-03
  185.     dc    -1.500173e-03,3.155693e-03,5.805688e-03,1.619394e-02
  186.  
  187. ; DoD stadard glottal pulse excitation
  188. ; Normalized for unity gain
  189. glottal dc    .249,-.262,.363,-.362,.100,.367,.079,.078,.010,-.277
  190.     dc    -.082,.376,.288,-.065,-.020,.138,-.062,-.315,-.247,-.078
  191.     dc    -.082,-.123,-.039,.065,.064,.019,.016,.032,.018,-.015
  192.     dc    -.029,-.021,-.018,-.027,-.031,-.022,-.012,-.010,-.010,-.004
  193.  
  194.     endsec
  195.  
  196.     end
  197.