lpcini.c 12 KB

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