lpcini.c
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:11k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /*
  2. $Log: lpcini.c,v $
  3. Revision 1.1.1.1  2002/07/28 05:23:35  freeman_yong
  4. lpc10 codec
  5.  * Revision 1.2  1996/08/20  20:35:41  jaf
  6.  * Added functions for allocating and initializing lpc10_encoder_state
  7.  * and lpc10_decoder_state structures.
  8.  *
  9.  * Revision 1.1  1996/08/19  22:31:40  jaf
  10.  * Initial revision
  11.  *
  12. */
  13. #ifdef P_R_O_T_O_T_Y_P_E_S
  14. extern int lpcini_(void);
  15. /* comlen contrl_ 12 */
  16. /*:ref: initlpcenc_ 14 0 */
  17. /*:ref: initlpcdec_ 14 0 */
  18. #endif
  19. /*  -- translated by f2c (version 19951025).
  20.    You must link the resulting object file with the libraries:
  21. -lf2c -lm   (in that order)
  22. */
  23. #include "f2c.h"
  24. #include <malloc.h>
  25. /* Common Block Declarations */
  26. struct {
  27.     integer order, lframe;
  28.     logical corrp;
  29. } contrl_;
  30. #define contrl_1 contrl_
  31. /* ***************************************************************** */
  32. /* $Log: lpcini.c,v $
  33. /* Revision 1.1.1.1  2002/07/28 05:23:35  freeman_yong
  34. /* lpc10 codec
  35. /*
  36.  * Revision 1.2  1996/08/20  20:35:41  jaf
  37.  * Added functions for allocating and initializing lpc10_encoder_state
  38.  * and lpc10_decoder_state structures.
  39.  *
  40.  * Revision 1.1  1996/08/19  22:31:40  jaf
  41.  * Initial revision
  42.  * */
  43. /* Revision 1.1  1996/03/28  00:04:05  jaf */
  44. /* Initial revision */
  45. /* ***************************************************************** */
  46. /* Initialize COMMON block variables used by LPC-10 encoder and decoder, */
  47. /* and call initialization routines for both of them. */
  48. /* Subroutine */ int lpcini_(void)
  49. {
  50. /* $Log: lpcini.c,v $
  51. /* Revision 1.1.1.1  2002/07/28 05:23:35  freeman_yong
  52. /* lpc10 codec
  53. /*
  54.  * Revision 1.2  1996/08/20  20:35:41  jaf
  55.  * Added functions for allocating and initializing lpc10_encoder_state
  56.  * and lpc10_decoder_state structures.
  57.  *
  58.  * Revision 1.1  1996/08/19  22:31:40  jaf
  59.  * Initial revision
  60.  * */
  61. /* Revision 1.3  1996/03/29  22:03:47  jaf */
  62. /* Removed definitions for any constants that were no longer used. */
  63. /* Revision 1.2  1996/03/26  19:34:33  jaf */
  64. /* Added comments indicating which constants are not needed in an */
  65. /* application that uses the LPC-10 coder. */
  66. /* Revision 1.1  1996/02/07  14:43:51  jaf */
  67. /* Initial revision */
  68. /*   LPC Configuration parameters: */
  69. /* Frame size, Prediction order, Pitch period */
  70. /* $Log: lpcini.c,v $
  71. /* Revision 1.1.1.1  2002/07/28 05:23:35  freeman_yong
  72. /* lpc10 codec
  73. /*
  74.  * Revision 1.2  1996/08/20  20:35:41  jaf
  75.  * Added functions for allocating and initializing lpc10_encoder_state
  76.  * and lpc10_decoder_state structures.
  77.  *
  78.  * Revision 1.1  1996/08/19  22:31:40  jaf
  79.  * Initial revision
  80.  * */
  81. /* Revision 1.3  1996/03/29  22:05:55  jaf */
  82. /* Commented out the common block variables that are not needed by the */
  83. /* embedded version. */
  84. /* Revision 1.2  1996/03/26  19:34:50  jaf */
  85. /* Added comments indicating which constants are not needed in an */
  86. /* application that uses the LPC-10 coder. */
  87. /* Revision 1.1  1996/02/07  14:44:09  jaf */
  88. /* Initial revision */
  89. /*   LPC Processing control variables: */
  90. /* *** Read-only: initialized in setup */
  91. /*  Files for Speech, Parameter, and Bitstream Input & Output, */
  92. /*    and message and debug outputs. */
  93. /* Here are the only files which use these variables: */
  94. /* lpcsim.f setup.f trans.f error.f vqsetup.f */
  95. /* Many files which use fdebug are not listed, since it is only used in */
  96. /* those other files conditionally, to print trace statements. */
  97. /*  integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  98. /*  LPC order, Frame size, Quantization rate, Bits per frame, */
  99. /*    Error correction */
  100. /* Subroutine SETUP is the only place where order is assigned a value, */
  101. /* and that value is 10.  It could increase efficiency 1% or so to */
  102. /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as 
  103. */
  104. /* a variable in a COMMON block, since it is used in many places in the */
  105. /* core of the coding and decoding routines.  Actually, I take that back. 
  106. */
  107. /* At least when compiling with f2c, the upper bound of DO loops is */
  108. /* stored in a local variable before the DO loop begins, and then that is 
  109. */
  110. /* compared against on each iteration. */
  111. /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
  112. /* Similarly for quant, which is given a value of 2400 in SETUP.  quant */
  113. /* is used in only a few places, and never in the core coding and */
  114. /* decoding routines, so it could be eliminated entirely. */
  115. /* nbits is similar to quant, and is given a value of 54 in SETUP. */
  116. /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
  117. /* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */
  118. /* coder significantly whether it is .TRUE. or .FALSE., or whether it is 
  119. */
  120. /* a constant or a variable, since it is only examined once per frame. */
  121. /* Leaving it as a variable that is set to .TRUE.  seems like a good */
  122. /* idea, since it does enable some error-correction capability for */
  123. /* unvoiced frames, with no change in the coding rate, and no noticeable 
  124. */
  125. /* quality difference in the decoded speech. */
  126. /*  integer quant, nbits */
  127. /* *** Read/write: variables for debugging, not needed for LPC algorithm 
  128. */
  129. /*  Current frame, Unstable frames, Output clip count, Max onset buffer, 
  130. */
  131. /*    Debug listing detail level, Line count on listing page */
  132. /* nframe is not needed for an embedded LPC10 at all. */
  133. /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
  134. /* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
  135. /* an application, I would recommend removing the call to ERROR in RCCHK, 
  136. */
  137. /* and remove ERROR and nunsfm completely. */
  138. /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in 
  139. */
  140. /* sread.f.  When LPC10 is embedded into an application, one might want */
  141. /* to cause it to be incremented in a routine that takes the output of */
  142. /* SYNTHS and sends it to an audio device.  It could be optionally */
  143. /* displayed, for those that might want to know what it is. */
  144. /* maxosp is never initialized to 0 in SETUP, although it probably should 
  145. */
  146. /* be, and it is updated in subroutine ANALYS.  I doubt that its value */
  147. /* would be of much interest to an application in which LPC10 is */
  148. /* embedded. */
  149. /* listl and lincnt are not needed for an embedded LPC10 at all. */
  150. /*  integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
  151. /*  common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  152. /*  common /contrl/ quant, nbits */
  153. /*  common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
  154.     contrl_1.order = 10;
  155.     contrl_1.lframe = 180;
  156.     contrl_1.corrp = TRUE_;
  157.     return 0;
  158. } /* lpcini_ */
  159. /* Allocate memory for, and initialize, the state that needs to be
  160.    kept from encoding one frame to the next for a single
  161.    LPC-10-compressed audio stream.  Return 0 if malloc fails,
  162.    otherwise return pointer to new structure. */
  163. struct lpc10_encoder_state *
  164. create_lpc10_encoder_state()
  165. {
  166.     struct lpc10_encoder_state *st;
  167.     st = (struct lpc10_encoder_state *)
  168. malloc((unsigned) sizeof (struct lpc10_encoder_state));
  169.     if (st != 0) {
  170. init_lpc10_encoder_state(st);
  171.     }
  172.     return (st);
  173. }
  174. void init_lpc10_encoder_state(struct lpc10_encoder_state *st)
  175. {
  176.     int i;
  177.     lpcini_();
  178.     /* State used only by function hp100 */
  179.     st->z11 = 0.0f;
  180.     st->z21 = 0.0f;
  181.     st->z12 = 0.0f;
  182.     st->z22 = 0.0f;
  183.     
  184.     /* State used by function analys */
  185.     for (i = 0; i < 540; i++) {
  186. st->inbuf[i] = 0.0f;
  187. st->pebuf[i] = 0.0f;
  188.     }
  189.     for (i = 0; i < 696; i++) {
  190. st->lpbuf[i] = 0.0f;
  191.     }
  192.     for (i = 0; i < 312; i++) {
  193. st->ivbuf[i] = 0.0f;
  194.     }
  195.     st->bias = 0.0f;
  196.     /* integer osbuf[10];  /* no initial value necessary */
  197.     st->osptr = 1;
  198.     for (i = 0; i < 3; i++) {
  199. st->obound[i] = 0;
  200.     }
  201.     st->vwin[4] = 307;
  202.     st->vwin[5] = 462;
  203.     st->awin[4] = 307;
  204.     st->awin[5] = 462;
  205.     for (i = 0; i < 8; i++) {
  206. st->voibuf[i] = 0;
  207.     }
  208.     for (i = 0; i < 3; i++) {
  209. st->rmsbuf[i] = 0.0f;
  210.     }
  211.     for (i = 0; i < 30; i++) {
  212. st->rcbuf[i] = 0.0f;
  213.     }
  214.     st->zpre = 0.0f;
  215.     /* State used by function onset */
  216.     st->n = 0.0f;
  217.     st->d__ = 1.0f;
  218.     /* real fpc;   /* no initial value necessary */
  219.     for (i = 0; i < 16; i++) {
  220. st->l2buf[i] = 0.0f;
  221.     }
  222.     st->l2sum1 = 0.0f;
  223.     st->l2ptr1 = 1;
  224.     st->l2ptr2 = 9;
  225.     /* integer lasti;    /* no initial value necessary */
  226.     st->hyst = FALSE_;
  227.     /* State used by function voicin */
  228.     st->dither = 20.0f;
  229.     st->maxmin = 0.0f;
  230.     for (i = 0; i < 6; i++) {
  231. st->voice[i] = 0.0f;
  232.     }
  233.     st->lbve = 3000;
  234.     st->fbve = 3000;
  235.     st->fbue = 187;
  236.     st->ofbue = 187;
  237.     st->sfbue = 187;
  238.     st->lbue = 93;
  239.     st->olbue = 93;
  240.     st->slbue = 93;
  241.     st->snr = (real) (st->fbve / st->fbue << 6);
  242.     /* State used by function dyptrk */
  243.     for (i = 0; i < 60; i++) {
  244. st->s[i] = 0.0f;
  245.     }
  246.     for (i = 0; i < 120; i++) {
  247. st->p[i] = 0;
  248.     }
  249.     st->ipoint = 0;
  250.     st->alphax = 0.0f;
  251.     /* State used by function chanwr */
  252.     st->isync = 0;
  253. }
  254. /* Allocate memory for, and initialize, the state that needs to be
  255.    kept from decoding one frame to the next for a single
  256.    LPC-10-compressed audio stream.  Return 0 if malloc fails,
  257.    otherwise return pointer to new structure. */
  258. struct lpc10_decoder_state *
  259. create_lpc10_decoder_state()
  260. {
  261.     struct lpc10_decoder_state *st;
  262.     st = (struct lpc10_decoder_state *)
  263. malloc((unsigned) sizeof (struct lpc10_decoder_state));
  264.     if (st != 0) {
  265. init_lpc10_decoder_state(st);
  266.     }
  267.     return (st);
  268. }
  269. void init_lpc10_decoder_state(struct lpc10_decoder_state *st)
  270. {
  271.     int i;
  272.     lpcini_();
  273.     /* State used by function decode */
  274.     st->iptold = 60;
  275.     st->first = TRUE_;
  276.     st->ivp2h = 0;
  277.     st->iovoic = 0;
  278.     st->iavgp = 60;
  279.     st->erate = 0;
  280.     for (i = 0; i < 30; i++) {
  281. st->drc[i] = 0;
  282.     }
  283.     for (i = 0; i < 3; i++) {
  284. st->dpit[i] = 0;
  285. st->drms[i] = 0;
  286.     }
  287.     /* State used by function synths */
  288.     for (i = 0; i < 360; i++) {
  289. st->buf[i] = 0.0f;
  290.     }
  291.     st->buflen = 180;
  292.     /* State used by function pitsyn */
  293.     /* ivoico;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
  294.     /* ipito;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
  295.     st->rmso = 1.0f;
  296.     /* rco[10];   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
  297.     /* integer jsamp;   /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
  298.     st->first_pitsyn = TRUE_;
  299.     /* State used by function bsynz */
  300.     st->ipo = 0;
  301.     for (i = 0; i < 166; i++) {
  302. st->exc[i] = 0.0f;
  303. st->exc2[i] = 0.0f;
  304.     }
  305.     st->lpi1 = 0.0f;
  306.     st->lpi2 = 0.0f;
  307.     st->lpi3 = 0.0f;
  308.     st->hpi1 = 0.0f;
  309.     st->hpi2 = 0.0f;
  310.     st->hpi3 = 0.0f;
  311.     st->rmso_bsynz = 0.0f;
  312.     /* State used by function random */
  313.     st->j = 2;
  314.     st->k = 5;
  315.     st->y[0] = (shortint) -21161;
  316.     st->y[1] = (shortint) -8478;
  317.     st->y[2] = (shortint) 30892;
  318.     st->y[3] = (shortint) -10216;
  319.     st->y[4] = (shortint) 16950;
  320.     /* State used by function deemp */
  321.     st->dei1 = 0.0f;
  322.     st->dei2 = 0.0f;
  323.     st->deo1 = 0.0f;
  324.     st->deo2 = 0.0f;
  325.     st->deo3 = 0.0f;
  326. }