cbsearch.F
上传用户:szhypcb168
上传日期:2007-01-06
资源大小:2187k
文件大小:5k
源码类别:

语音压缩

开发平台:

Unix_Linux

  1. C==========================================================================
  2. C
  3. C ROUTINE
  4. C               cbsearch
  5. C
  6. C FUNCTION
  7. C               find optimal MSPE excitation code word
  8. C
  9. C SYNOPSIS
  10. C               subroutine cbsearch(s, l, v)
  11. C
  12. C   formal 
  13. C
  14. C                       data    I/O
  15. C       name            type    type    function
  16. C       -------------------------------------------------------------------
  17. C       s(l)            real    i       data segment
  18. C       l               int     i       length of vectors
  19. C       v(l)            real    o       optimum excitation segment found
  20. C
  21. C   global 
  22. C                       data    I/O
  23. C       name            type    type    function
  24. C       -------------------------------------------------------------------
  25. C  /ccsub/       see description include file
  26. C x(maxcode) real i code book
  27. #ifdef SUNGRAPH
  28. C  /sungraph_var/
  29. #endif
  30. C
  31. C==========================================================================
  32. C
  33. C DESCRIPTION
  34. C
  35. C  Code book search is performed by closed-loop analysis using conventional
  36. C  minimum squared prediction error (MSPE) criteria of the perceptually
  37. C  weighted error signal.  The code book is overlaped to allow recursive
  38. C  computational savings in routine cgain:
  39. C
  40. C index code book
  41. C +-----------------------+
  42. C 1 | 2M-1         2(M-1)+L |
  43. C 2 | 2(M-2)+1     2(M-2)+L |
  44. C : | :            : |
  45. C N-1 | .            . |
  46. C N | .            . |
  47. C : | 3            62 |
  48. C : | 1            60 |
  49. C +-----------------------+
  50. C
  51. C where: M = maximum code book size
  52. C        N = actual code book search size (any value between 1 & M)
  53. C        L = code word length
  54. C
  55. C each code word is:  2(M-index)+1 -> 2(M-index)+L
  56. C  
  57. C==========================================================================
  58. C
  59. C CALLED BY
  60. C
  61. C       csub
  62. C
  63. C CALLS
  64. C
  65. C cgain, [gainencode], mexcite3
  66. C
  67. C==========================================================================
  68. C
  69. C REFERENCES
  70. C
  71. C Tremain, Thomas E., Joseph P. Campbell, Jr and Vanoy C. Welch,
  72. C "A 4.8 kbps Code Excited Linear Predictive Coder," Proceedings
  73. C of the Mobile Satellite Conference, 3-5 May 1988, pp. 491-496.
  74. C
  75. C Campbell, Joseph P. Jr., Vanoy C. Welch and Thomas E. Tremain,
  76. C "An Expandable Error-Protected 4800 bps CELP Coder (U.S. Federal
  77. C Standard 4800 bps Voice Coder)," Proceedings of ICASSP, 1989.
  78. C (and Proceedings of Speech Tech, 1989.)
  79. C
  80. C**************************************************************************
  81. C*-
  82. subroutine cbsearch(s, l, v)
  83. implicit undefined(a-z)
  84. integer l
  85. real s(l), v(l)
  86. include 'ccsub.com'
  87. convex #include "ccsub.com"
  88. #ifdef SUNGRAPH
  89. include 'sungraph_var.com'
  90. convex #include "sungraph_var.com"
  91. real dbcon
  92. #endif
  93. integer i, codeword, len
  94. real emax, cgain, gainencode, quangain, oldgain
  95. c
  96. c *length of truncated impulse response
  97. parameter (len = 30)
  98. #ifdef SUNGRAPH
  99. c *save impulse response in file 'codebook'
  100. c *(same as impulse response in file 'pitch')
  101. call save_sg(cb_ir_vid,h,l,'save cb_ir_vid')
  102. #endif
  103. c
  104. c *find gain and -error term for each codeword
  105. c *and search for best code word (max -error term)
  106. c *(codewords are overlapped by shifts of -2
  107. c * along the code vector x)
  108. c *NOTE: gain(i) & err(i) can be replaced by scalars
  109. codeword= 2*maxncsize-1
  110. cbindex = 1
  111. gain(1) = cgain(x(codeword), l, .true., len, err(1))
  112. emax    = err(1)
  113. codeword= codeword-2
  114. do 10 i = 2, ncsize
  115.    gain(i)  = cgain(x(codeword), l, .false., len, err(i))
  116.    codeword = codeword-2
  117.    if (err(i) .gt. emax) then
  118.       emax    = err(i)
  119.       cbindex = i
  120.    end if
  121. 10 continue
  122. c if (err(cbindex).lt.0.0)print *,' CB match<0',frame,err(cbindex)
  123. c
  124. c *pointer to best code word
  125. codeword = 2*(maxncsize-cbindex)+1
  126. c
  127. c *OPTIONAL (may be useful for integer DSPs)
  128. c *given best code word, recompute its gain to
  129. c *correct any errors accumulated in recursions
  130. gain(cbindex) = cgain(x(codeword), l, .true., l, err(cbindex))
  131. c
  132. c *write cbgain.data file for quantizer design
  133. c *Open loop quant REQUIRED!
  134. copt write (20,*) gain(cbindex)
  135. #ifdef SUNGRAPH
  136. c *save code book gain in file 'codebook'
  137. c *if closed-loop quant, this is QUANTIZED gain
  138. call save_sg(cb_gain_vid,gain(cbindex),1,'save cb_gain_vid')
  139. c
  140. c *save code book error in file 'codebook'
  141. call save_sg(cb_match_vid,err,ncsize,'save cb_error_vid')
  142. #endif
  143. oldgain = gain(cbindex)
  144. c
  145. c *constrained excitation
  146. if (mxsw) call mexcite3(gain(cbindex))
  147. c
  148. c *gain quantization, UNNECESSARY for closed-loop quant
  149. if (cbgtype .ne. 'none') then
  150.    if (cbgbits .eq. 5) then
  151.       gain(cbindex) = gainencode(gain(cbindex),cbgbits,cbgtype,gindex)
  152.    end if
  153. else
  154.    print *,' cbsearch:  not quantizing cbgain'
  155. end if
  156. c
  157. c *scale selected code word vector -> excitation array
  158. c *call VDECODE?
  159. do 70 i = 0, l-1
  160.    v(i+1) = gain(cbindex)*x(i+codeword)
  161. 70 continue
  162. #ifdef SUNGRAPH
  163. c *save quantized code book gain in file 'codebook'
  164. if (oldgain .ne. 0) then
  165.    dbcon=20.*log10(abs(oldgain/gain(cbindex)))
  166. end if
  167. quangain=gain(cbindex)
  168. call save_sg(cb_qgain_vid,quangain,1,'save cb_qgain_vid')
  169. call save_sg(dbcon_vid,dbcon,1,'save dbcon_vid')
  170. c
  171. c *save code book excitation in file 'codebook'
  172. call save_sg(cb_exc_vid,v,l,'save cb_exc_vid')
  173. #endif
  174. return
  175. end