lpcdec.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. $Log$
  3. Revision 1.15 2004/06/26 03:50:14 markster
  4. Merge source cleanups (bug #1911)
  5. Revision 1.14 2003/02/12 13:59:15 matteo
  6. mer feb 12 14:56:57 CET 2003
  7. Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  8. mer feb 12 14:56:57 CET 2003
  9. Revision 1.2 2000/01/05 08:20:39 markster
  10. Some OSS fixes and a few lpc changes to make it actually work
  11. * Revision 1.2 1996/08/20 20:30:11 jaf
  12. * Removed all static local variables that were SAVE'd in the Fortran
  13. * code, and put them in struct lpc10_encoder_state that is passed as an
  14. * argument.
  15. *
  16. * Removed init function, since all initialization is now done in
  17. * init_lpc10_encoder_state().
  18. *
  19. * Changed name of function from lpcenc_ to lpc10_encode, simply to make
  20. * all lpc10 functions have more consistent naming with each other.
  21. *
  22. * Revision 1.1 1996/08/19 22:31:48 jaf
  23. * Initial revision
  24. *
  25. */
  26. /* -- translated by f2c (version 19951025).
  27. You must link the resulting object file with the libraries:
  28. -lf2c -lm (in that order)
  29. */
  30. #include "f2c.h"
  31. #ifdef P_R_O_T_O_T_Y_P_E_S
  32. extern int lpcdec_(integer *bits, real *speech);
  33. extern int initlpcdec_(void);
  34. /* comlen contrl_ 12 */
  35. /*:ref: chanrd_ 14 5 4 4 4 4 4 */
  36. /*:ref: decode_ 14 7 4 4 4 4 4 6 6 */
  37. /*:ref: synths_ 14 6 4 4 6 6 6 4 */
  38. /*:ref: initdecode_ 14 0 */
  39. /*:ref: initsynths_ 14 0 */
  40. #endif
  41. /* Common Block Declarations */
  42. extern struct {
  43. integer order, lframe;
  44. logical corrp;
  45. } contrl_;
  46. #define contrl_1 contrl_
  47. /* Table of constant values */
  48. static integer c__10 = 10;
  49. /* ***************************************************************** */
  50. /* $Log$
  51. * Revision 1.15 2004/06/26 03:50:14 markster
  52. * Merge source cleanups (bug #1911)
  53. *
  54. * Revision 1.14 2003/02/12 13:59:15 matteo
  55. * mer feb 12 14:56:57 CET 2003
  56. *
  57. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  58. * mer feb 12 14:56:57 CET 2003
  59. *
  60. * Revision 1.2 2000/01/05 08:20:39 markster
  61. * Some OSS fixes and a few lpc changes to make it actually work
  62. *
  63. * Revision 1.2 1996/08/20 20:30:11 jaf
  64. * Removed all static local variables that were SAVE'd in the Fortran
  65. * code, and put them in struct lpc10_encoder_state that is passed as an
  66. * argument.
  67. *
  68. * Removed init function, since all initialization is now done in
  69. * init_lpc10_encoder_state().
  70. *
  71. * Changed name of function from lpcenc_ to lpc10_encode, simply to make
  72. * all lpc10 functions have more consistent naming with each other.
  73. *
  74. * Revision 1.1 1996/08/19 22:31:48 jaf
  75. * Initial revision
  76. * */
  77. /* Revision 1.1 1996/03/28 00:03:00 jaf */
  78. /* Initial revision */
  79. /* ***************************************************************** */
  80. /* Decode 54 bits to one frame of 180 speech samples. */
  81. /* Input: */
  82. /* BITS - 54 encoded bits, stored 1 per array element. */
  83. /* Indices 1 through 53 read (SYNC bit ignored). */
  84. /* Output: */
  85. /* SPEECH - Speech encoded as real values in the range [-1,+1]. */
  86. /* Indices 1 through 180 written. */
  87. /* This subroutine maintains local state from one call to the next. If */
  88. /* you want to switch to using a new audio stream for this filter, or */
  89. /* reinitialize its state for any other reason, call the ENTRY */
  90. /* INITLPCDEC. */
  91. /* Subroutine */ int lpc10_decode(integer *bits, real *speech,
  92. struct lpc10_decoder_state *st)
  93. {
  94. integer irms, voice[2], pitch, ipitv;
  95. extern /* Subroutine */ int decode_(integer *, integer *, integer *,
  96. integer *, integer *, real *, real *, struct lpc10_decoder_state *);
  97. real rc[10];
  98. extern /* Subroutine */ int chanrd_(integer *, integer *, integer *,
  99. integer *, integer *), synths_(integer *,
  100. integer *, real *, real *, real *, integer *,
  101. struct lpc10_decoder_state *);
  102. integer irc[10], len;
  103. real rms;
  104. /* $Log$
  105. * Revision 1.15 2004/06/26 03:50:14 markster
  106. * Merge source cleanups (bug #1911)
  107. *
  108. * Revision 1.14 2003/02/12 13:59:15 matteo
  109. * mer feb 12 14:56:57 CET 2003
  110. *
  111. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  112. * mer feb 12 14:56:57 CET 2003
  113. *
  114. * Revision 1.2 2000/01/05 08:20:39 markster
  115. * Some OSS fixes and a few lpc changes to make it actually work
  116. *
  117. * Revision 1.2 1996/08/20 20:30:11 jaf
  118. * Removed all static local variables that were SAVE'd in the Fortran
  119. * code, and put them in struct lpc10_encoder_state that is passed as an
  120. * argument.
  121. *
  122. * Removed init function, since all initialization is now done in
  123. * init_lpc10_encoder_state().
  124. *
  125. * Changed name of function from lpcenc_ to lpc10_encode, simply to make
  126. * all lpc10 functions have more consistent naming with each other.
  127. *
  128. * Revision 1.1 1996/08/19 22:31:48 jaf
  129. * Initial revision
  130. * */
  131. /* Revision 1.3 1996/03/29 22:03:47 jaf */
  132. /* Removed definitions for any constants that were no longer used. */
  133. /* Revision 1.2 1996/03/26 19:34:33 jaf */
  134. /* Added comments indicating which constants are not needed in an */
  135. /* application that uses the LPC-10 coder. */
  136. /* Revision 1.1 1996/02/07 14:43:51 jaf */
  137. /* Initial revision */
  138. /* LPC Configuration parameters: */
  139. /* Frame size, Prediction order, Pitch period */
  140. /* Arguments */
  141. /* $Log$
  142. * Revision 1.15 2004/06/26 03:50:14 markster
  143. * Merge source cleanups (bug #1911)
  144. *
  145. * Revision 1.14 2003/02/12 13:59:15 matteo
  146. * mer feb 12 14:56:57 CET 2003
  147. *
  148. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  149. * mer feb 12 14:56:57 CET 2003
  150. *
  151. * Revision 1.2 2000/01/05 08:20:39 markster
  152. * Some OSS fixes and a few lpc changes to make it actually work
  153. *
  154. * Revision 1.2 1996/08/20 20:30:11 jaf
  155. * Removed all static local variables that were SAVE'd in the Fortran
  156. * code, and put them in struct lpc10_encoder_state that is passed as an
  157. * argument.
  158. *
  159. * Removed init function, since all initialization is now done in
  160. * init_lpc10_encoder_state().
  161. *
  162. * Changed name of function from lpcenc_ to lpc10_encode, simply to make
  163. * all lpc10 functions have more consistent naming with each other.
  164. *
  165. * Revision 1.1 1996/08/19 22:31:48 jaf
  166. * Initial revision
  167. * */
  168. /* Revision 1.3 1996/03/29 22:05:55 jaf */
  169. /* Commented out the common block variables that are not needed by the */
  170. /* embedded version. */
  171. /* Revision 1.2 1996/03/26 19:34:50 jaf */
  172. /* Added comments indicating which constants are not needed in an */
  173. /* application that uses the LPC-10 coder. */
  174. /* Revision 1.1 1996/02/07 14:44:09 jaf */
  175. /* Initial revision */
  176. /* LPC Processing control variables: */
  177. /* *** Read-only: initialized in setup */
  178. /* Files for Speech, Parameter, and Bitstream Input & Output, */
  179. /* and message and debug outputs. */
  180. /* Here are the only files which use these variables: */
  181. /* lpcsim.f setup.f trans.f error.f vqsetup.f */
  182. /* Many files which use fdebug are not listed, since it is only used in */
  183. /* those other files conditionally, to print trace statements. */
  184. /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  185. /* LPC order, Frame size, Quantization rate, Bits per frame, */
  186. /* Error correction */
  187. /* Subroutine SETUP is the only place where order is assigned a value, */
  188. /* and that value is 10. It could increase efficiency 1% or so to */
  189. /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
  190. */
  191. /* a variable in a COMMON block, since it is used in many places in the */
  192. /* core of the coding and decoding routines. Actually, I take that back.
  193. */
  194. /* At least when compiling with f2c, the upper bound of DO loops is */
  195. /* stored in a local variable before the DO loop begins, and then that is
  196. */
  197. /* compared against on each iteration. */
  198. /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
  199. /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
  200. /* is used in only a few places, and never in the core coding and */
  201. /* decoding routines, so it could be eliminated entirely. */
  202. /* nbits is similar to quant, and is given a value of 54 in SETUP. */
  203. /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
  204. /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
  205. /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
  206. */
  207. /* a constant or a variable, since it is only examined once per frame. */
  208. /* Leaving it as a variable that is set to .TRUE. seems like a good */
  209. /* idea, since it does enable some error-correction capability for */
  210. /* unvoiced frames, with no change in the coding rate, and no noticeable
  211. */
  212. /* quality difference in the decoded speech. */
  213. /* integer quant, nbits */
  214. /* *** Read/write: variables for debugging, not needed for LPC algorithm
  215. */
  216. /* Current frame, Unstable frames, Output clip count, Max onset buffer,
  217. */
  218. /* Debug listing detail level, Line count on listing page */
  219. /* nframe is not needed for an embedded LPC10 at all. */
  220. /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
  221. /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
  222. /* an application, I would recommend removing the call to ERROR in RCCHK,
  223. */
  224. /* and remove ERROR and nunsfm completely. */
  225. /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
  226. */
  227. /* sread.f. When LPC10 is embedded into an application, one might want */
  228. /* to cause it to be incremented in a routine that takes the output of */
  229. /* SYNTHS and sends it to an audio device. It could be optionally */
  230. /* displayed, for those that might want to know what it is. */
  231. /* maxosp is never initialized to 0 in SETUP, although it probably should
  232. */
  233. /* be, and it is updated in subroutine ANALYS. I doubt that its value */
  234. /* would be of much interest to an application in which LPC10 is */
  235. /* embedded. */
  236. /* listl and lincnt are not needed for an embedded LPC10 at all. */
  237. /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
  238. /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  239. /* common /contrl/ quant, nbits */
  240. /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
  241. /* Local variables that need not be saved */
  242. /* Uncoded speech parameters */
  243. /* Coded speech parameters */
  244. /* Others */
  245. /* Local state */
  246. /* None */
  247. /* Parameter adjustments */
  248. if (bits) {
  249. --bits;
  250. }
  251. if (speech) {
  252. --speech;
  253. }
  254. /* Function Body */
  255. chanrd_(&c__10, &ipitv, &irms, irc, &bits[1]);
  256. decode_(&ipitv, &irms, irc, voice, &pitch, &rms, rc, st);
  257. synths_(voice, &pitch, &rms, rc, &speech[1], &len, st);
  258. return 0;
  259. } /* lpcdec_ */