analys.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*
  2. $Log$
  3. Revision 1.16 2004/06/26 03:50:14 markster
  4. Merge source cleanups (bug #1911)
  5. Revision 1.15 2003/09/19 01:20:22 markster
  6. Code cleanups (bug #66)
  7. Revision 1.2 2003/09/19 01:20:22 markster
  8. Code cleanups (bug #66)
  9. Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  10. mer feb 12 14:56:57 CET 2003
  11. Revision 1.2 2000/01/05 08:20:39 markster
  12. Some OSS fixes and a few lpc changes to make it actually work
  13. * Revision 1.2 1996/08/20 20:16:01 jaf
  14. * Removed all static local variables that were SAVE'd in the Fortran
  15. * code, and put them in struct lpc10_encoder_state that is passed as an
  16. * argument.
  17. *
  18. * Removed init function, since all initialization is now done in
  19. * init_lpc10_encoder_state().
  20. *
  21. * Revision 1.1 1996/08/19 22:29:08 jaf
  22. * Initial revision
  23. *
  24. */
  25. #include "f2c.h"
  26. #ifdef P_R_O_T_O_T_Y_P_E_S
  27. extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_encoder_state *st);
  28. /* comlen contrl_ 12 */
  29. /*:ref: preemp_ 14 5 6 6 4 6 6 */
  30. /*:ref: onset_ 14 7 6 4 4 4 4 4 4 */
  31. /*:ref: placev_ 14 11 4 4 4 4 4 4 4 4 4 4 4 */
  32. /*:ref: lpfilt_ 14 4 6 6 4 4 */
  33. /*:ref: ivfilt_ 14 5 6 6 4 4 6 */
  34. /*:ref: tbdm_ 14 8 6 4 4 4 6 4 4 4 */
  35. /*:ref: voicin_ 14 12 4 6 6 4 4 6 6 4 6 4 4 4 */
  36. /*:ref: dyptrk_ 14 6 6 4 4 4 4 4 */
  37. /*:ref: placea_ 14 9 4 4 4 4 4 4 4 4 4 */
  38. /*:ref: dcbias_ 14 3 4 6 6 */
  39. /*:ref: energy_ 14 3 4 6 6 */
  40. /*:ref: mload_ 14 6 4 4 4 6 6 6 */
  41. /*:ref: invert_ 14 4 4 6 6 6 */
  42. /*:ref: rcchk_ 14 3 4 6 6 */
  43. /*:ref: initonset_ 14 0 */
  44. /*:ref: initvoicin_ 14 0 */
  45. /*:ref: initdyptrk_ 14 0 */
  46. /* Rerunning f2c -P may change prototypes or declarations. */
  47. #endif
  48. /* -- translated by f2c (version 19951025).
  49. You must link the resulting object file with the libraries:
  50. -lf2c -lm (in that order)
  51. */
  52. /* Common Block Declarations */
  53. extern struct {
  54. integer order, lframe;
  55. logical corrp;
  56. } contrl_;
  57. #define contrl_1 contrl_
  58. /* Table of constant values */
  59. static integer c__10 = 10;
  60. static integer c__181 = 181;
  61. static integer c__720 = 720;
  62. static integer c__3 = 3;
  63. static integer c__90 = 90;
  64. static integer c__156 = 156;
  65. static integer c__307 = 307;
  66. static integer c__462 = 462;
  67. static integer c__312 = 312;
  68. static integer c__60 = 60;
  69. static integer c__1 = 1;
  70. /* ****************************************************************** */
  71. /* ANALYS Version 55 */
  72. /* $Log$
  73. * Revision 1.16 2004/06/26 03:50:14 markster
  74. * Merge source cleanups (bug #1911)
  75. *
  76. * Revision 1.15 2003/09/19 01:20:22 markster
  77. * Code cleanups (bug #66)
  78. *
  79. * Revision 1.2 2003/09/19 01:20:22 markster
  80. * Code cleanups (bug #66)
  81. *
  82. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  83. * mer feb 12 14:56:57 CET 2003
  84. *
  85. * Revision 1.2 2000/01/05 08:20:39 markster
  86. * Some OSS fixes and a few lpc changes to make it actually work
  87. *
  88. * Revision 1.2 1996/08/20 20:16:01 jaf
  89. * Removed all static local variables that were SAVE'd in the Fortran
  90. * code, and put them in struct lpc10_encoder_state that is passed as an
  91. * argument.
  92. *
  93. * Removed init function, since all initialization is now done in
  94. * init_lpc10_encoder_state().
  95. *
  96. * Revision 1.1 1996/08/19 22:29:08 jaf
  97. * Initial revision
  98. * */
  99. /* Revision 1.9 1996/05/23 19:41:07 jaf */
  100. /* Commented out some unnecessary lines that were reading uninitialized */
  101. /* values. */
  102. /* Revision 1.8 1996/03/27 23:57:55 jaf */
  103. /* Added some comments about which indices of the local buffers INBUF, */
  104. /* LPBUF, etc., get read or modified by some of the subroutine calls. I */
  105. /* just did this while trying to figure out the discrepancy between the */
  106. /* embedded code compiled with all local variables implicitly saved, and */
  107. /* without. */
  108. /* I added some debugging write statements in hopes of finding a problem. */
  109. /* None of them ever printed anything while running with the long input */
  110. /* speech file dam9.spd provided in the distribution. */
  111. /* Revision 1.7 1996/03/27 18:06:20 jaf */
  112. /* Commented out access to MAXOSP, which is just a debugging variable */
  113. /* that was defined in the COMMON block CONTRL in contrl.fh. */
  114. /* Revision 1.6 1996/03/26 19:31:33 jaf */
  115. /* Commented out trace statements. */
  116. /* Revision 1.5 1996/03/21 15:19:35 jaf */
  117. /* Added comments for ENTRY PITDEC. */
  118. /* Revision 1.4 1996/03/19 20:54:27 jaf */
  119. /* Added a line to INITANALYS. See comments there. */
  120. /* Revision 1.3 1996/03/19 20:52:49 jaf */
  121. /* Rearranged the order of the local variables quite a bit, to separate */
  122. /* them into groups of "constants", "locals that don't need to be saved */
  123. /* from one call to the next", and "local that do need to be saved from */
  124. /* one call to the next". */
  125. /* Several locals in the last set should have been given initial values, */
  126. /* but weren't. I gave them all initial values of 0. */
  127. /* Added a separate ENTRY INITANALYS that initializes all local state */
  128. /* that should be, and also calls the corresponding entries of the */
  129. /* subroutines called by ANALYS that also have local state. */
  130. /* There used to be DATA statements in ANALYS. I got rid of most of */
  131. /* them, and added a local logical variable FIRST that calls the entry */
  132. /* INITANALYS on the first call to ANALYS. This is just so that one need */
  133. /* not remember to call INITANALYS first in order for the state to be */
  134. /* initialized. */
  135. /* Revision 1.2 1996/03/11 23:29:32 jaf */
  136. /* Added several comments with my own personal questions about the */
  137. /* Fortran 77 meaning of the parameters passed to the subroutine PREEMP. */
  138. /* Revision 1.1 1996/02/07 14:42:29 jaf */
  139. /* Initial revision */
  140. /* ****************************************************************** */
  141. /* SUBROUTINE ANALYS */
  142. /* Input: */
  143. /* SPEECH */
  144. /* Indices 1 through LFRAME read. */
  145. /* Output: */
  146. /* VOICE */
  147. /* Indices 1 through 2 written. */
  148. /* PITCH */
  149. /* Written in subroutine DYPTRK, and then perhaps read and written */
  150. /* some more. */
  151. /* RMS */
  152. /* Written. */
  153. /* RC */
  154. /* Indices 1 through ORDER written (ORDER defined in contrl.fh). */
  155. /* This subroutine maintains local state from one call to the next. If */
  156. /* you want to switch to using a new audio stream for this filter, or */
  157. /* reinitialize its state for any other reason, call the ENTRY */
  158. /* INITANALYS. */
  159. /* ENTRY PITDEC */
  160. /* Input: */
  161. /* PITCH - Encoded pitch index */
  162. /* Output: */
  163. /* PTAU - Decoded pitch period */
  164. /* This entry has no local state. It accesses a "constant" array */
  165. /* declared in ANALYS. */
  166. /* Subroutine */ int analys_(real *speech, integer *voice, integer
  167. *pitch, real *rms, real *rc, struct lpc10_encoder_state *st)
  168. {
  169. /* Initialized data */
  170. static integer tau[60] = { 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
  171. 35,36,37,38,39,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,
  172. 74,76,78,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,
  173. 140,144,148,152,156 };
  174. static integer buflim[4] = { 181,720,25,720 };
  175. static real precoef = .9375f;
  176. /* System generated locals */
  177. integer i__1;
  178. /* Local variables */
  179. real amdf[60];
  180. integer half;
  181. real abuf[156];
  182. real *bias;
  183. extern /* Subroutine */ int tbdm_(real *, integer *, integer *, integer *,
  184. real *, integer *, integer *, integer *);
  185. integer *awin;
  186. integer midx, ewin[6] /* was [2][3] */;
  187. real ivrc[2], temp;
  188. real *zpre;
  189. integer *vwin;
  190. integer i__, j, lanal;
  191. extern /* Subroutine */ int rcchk_(integer *, real *, real *), mload_(
  192. integer *, integer *, integer *, real *, real *, real *);
  193. real *inbuf, *pebuf;
  194. real *lpbuf, *ivbuf;
  195. real *rcbuf;
  196. integer *osbuf;
  197. extern /* Subroutine */ int onset_(real *, integer *, integer *, integer *
  198. , integer *, integer *, integer *, struct lpc10_encoder_state *);
  199. integer *osptr;
  200. extern int dcbias_(integer *, real *, real *);
  201. integer ipitch;
  202. integer *obound;
  203. extern /* Subroutine */ int preemp_(real *, real *, integer *, real *,
  204. real *), voicin_(integer *, real *, real *, integer *, integer *,
  205. real *, real *, integer *, real *, integer *, integer *, integer *,
  206. struct lpc10_encoder_state *);
  207. integer *voibuf;
  208. integer mintau;
  209. real *rmsbuf;
  210. extern /* Subroutine */ int lpfilt_(real *, real *, integer *, integer *),
  211. ivfilt_(real *, real *, integer *, integer *, real *), energy_(
  212. integer *, real *, real *), invert_(integer *, real *, real *,
  213. real *);
  214. integer minptr, maxptr;
  215. extern /* Subroutine */ int dyptrk_(real *, integer *, integer *, integer
  216. *, integer *, integer *, struct lpc10_encoder_state *);
  217. real phi[100] /* was [10][10] */, psi[10];
  218. /* $Log$
  219. * Revision 1.16 2004/06/26 03:50:14 markster
  220. * Merge source cleanups (bug #1911)
  221. *
  222. * Revision 1.15 2003/09/19 01:20:22 markster
  223. * Code cleanups (bug #66)
  224. *
  225. * Revision 1.2 2003/09/19 01:20:22 markster
  226. * Code cleanups (bug #66)
  227. *
  228. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  229. * mer feb 12 14:56:57 CET 2003
  230. *
  231. * Revision 1.2 2000/01/05 08:20:39 markster
  232. * Some OSS fixes and a few lpc changes to make it actually work
  233. *
  234. * Revision 1.2 1996/08/20 20:16:01 jaf
  235. * Removed all static local variables that were SAVE'd in the Fortran
  236. * code, and put them in struct lpc10_encoder_state that is passed as an
  237. * argument.
  238. *
  239. * Removed init function, since all initialization is now done in
  240. * init_lpc10_encoder_state().
  241. *
  242. * Revision 1.1 1996/08/19 22:29:08 jaf
  243. * Initial revision
  244. * */
  245. /* Revision 1.3 1996/03/29 22:03:47 jaf */
  246. /* Removed definitions for any constants that were no longer used. */
  247. /* Revision 1.2 1996/03/26 19:34:33 jaf */
  248. /* Added comments indicating which constants are not needed in an */
  249. /* application that uses the LPC-10 coder. */
  250. /* Revision 1.1 1996/02/07 14:43:51 jaf */
  251. /* Initial revision */
  252. /* LPC Configuration parameters: */
  253. /* Frame size, Prediction order, Pitch period */
  254. /* Arguments to ANALYS */
  255. /* $Log$
  256. * Revision 1.16 2004/06/26 03:50:14 markster
  257. * Merge source cleanups (bug #1911)
  258. *
  259. * Revision 1.15 2003/09/19 01:20:22 markster
  260. * Code cleanups (bug #66)
  261. *
  262. * Revision 1.2 2003/09/19 01:20:22 markster
  263. * Code cleanups (bug #66)
  264. *
  265. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  266. * mer feb 12 14:56:57 CET 2003
  267. *
  268. * Revision 1.2 2000/01/05 08:20:39 markster
  269. * Some OSS fixes and a few lpc changes to make it actually work
  270. *
  271. * Revision 1.2 1996/08/20 20:16:01 jaf
  272. * Removed all static local variables that were SAVE'd in the Fortran
  273. * code, and put them in struct lpc10_encoder_state that is passed as an
  274. * argument.
  275. *
  276. * Removed init function, since all initialization is now done in
  277. * init_lpc10_encoder_state().
  278. *
  279. * Revision 1.1 1996/08/19 22:29:08 jaf
  280. * Initial revision
  281. * */
  282. /* Revision 1.3 1996/03/29 22:05:55 jaf */
  283. /* Commented out the common block variables that are not needed by the */
  284. /* embedded version. */
  285. /* Revision 1.2 1996/03/26 19:34:50 jaf */
  286. /* Added comments indicating which constants are not needed in an */
  287. /* application that uses the LPC-10 coder. */
  288. /* Revision 1.1 1996/02/07 14:44:09 jaf */
  289. /* Initial revision */
  290. /* LPC Processing control variables: */
  291. /* *** Read-only: initialized in setup */
  292. /* Files for Speech, Parameter, and Bitstream Input & Output, */
  293. /* and message and debug outputs. */
  294. /* Here are the only files which use these variables: */
  295. /* lpcsim.f setup.f trans.f error.f vqsetup.f */
  296. /* Many files which use fdebug are not listed, since it is only used in */
  297. /* those other files conditionally, to print trace statements. */
  298. /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  299. /* LPC order, Frame size, Quantization rate, Bits per frame, */
  300. /* Error correction */
  301. /* Subroutine SETUP is the only place where order is assigned a value, */
  302. /* and that value is 10. It could increase efficiency 1% or so to */
  303. /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
  304. */
  305. /* a variable in a COMMON block, since it is used in many places in the */
  306. /* core of the coding and decoding routines. Actually, I take that back.
  307. */
  308. /* At least when compiling with f2c, the upper bound of DO loops is */
  309. /* stored in a local variable before the DO loop begins, and then that is
  310. */
  311. /* compared against on each iteration. */
  312. /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
  313. /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
  314. /* is used in only a few places, and never in the core coding and */
  315. /* decoding routines, so it could be eliminated entirely. */
  316. /* nbits is similar to quant, and is given a value of 54 in SETUP. */
  317. /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
  318. /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
  319. /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
  320. */
  321. /* a constant or a variable, since it is only examined once per frame. */
  322. /* Leaving it as a variable that is set to .TRUE. seems like a good */
  323. /* idea, since it does enable some error-correction capability for */
  324. /* unvoiced frames, with no change in the coding rate, and no noticeable
  325. */
  326. /* quality difference in the decoded speech. */
  327. /* integer quant, nbits */
  328. /* *** Read/write: variables for debugging, not needed for LPC algorithm
  329. */
  330. /* Current frame, Unstable frames, Output clip count, Max onset buffer,
  331. */
  332. /* Debug listing detail level, Line count on listing page */
  333. /* nframe is not needed for an embedded LPC10 at all. */
  334. /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
  335. /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
  336. /* an application, I would recommend removing the call to ERROR in RCCHK,
  337. */
  338. /* and remove ERROR and nunsfm completely. */
  339. /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
  340. */
  341. /* sread.f. When LPC10 is embedded into an application, one might want */
  342. /* to cause it to be incremented in a routine that takes the output of */
  343. /* SYNTHS and sends it to an audio device. It could be optionally */
  344. /* displayed, for those that might want to know what it is. */
  345. /* maxosp is never initialized to 0 in SETUP, although it probably should
  346. */
  347. /* be, and it is updated in subroutine ANALYS. I doubt that its value */
  348. /* would be of much interest to an application in which LPC10 is */
  349. /* embedded. */
  350. /* listl and lincnt are not needed for an embedded LPC10 at all. */
  351. /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
  352. /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  353. /* common /contrl/ quant, nbits */
  354. /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
  355. /* Arguments to entry PITDEC (below) */
  356. /* Parameters/constants */
  357. /* Constants */
  358. /* NF = Number of frames */
  359. /* AF = Frame in which analysis is done */
  360. /* OSLEN = Length of the onset buffer */
  361. /* LTAU = Number of pitch lags */
  362. /* SBUFL, SBUFH = Start and end index of speech buffers */
  363. /* LBUFL, LBUFH = Start and end index of LPF speech buffer */
  364. /* MINWIN, MAXWIN = Min and Max length of voicing (and analysis) windows
  365. */
  366. /* PWLEN, PWINH, PWINL = Length, upper and lower limits of pitch window
  367. */
  368. /* DVWINL, DVWINH = Default lower and upper limits of voicing window */
  369. /* The tables TAU and BUFLIM, and the variable PRECOEF, are not */
  370. /* Fortran PARAMETER's, but they are initialized with DATA */
  371. /* statements, and never modified. Thus, they need not have SAVE */
  372. /* statements for them to keep their values from one invocation to
  373. */
  374. /* the next. */
  375. /* Local variables that need not be saved */
  376. /* Local state */
  377. /* Data Buffers */
  378. /* INBUF Raw speech (with DC bias removed each frame) */
  379. /* PEBUF Preemphasized speech */
  380. /* LPBUF Low pass speech buffer */
  381. /* IVBUF Inverse filtered speech */
  382. /* OSBUF Indexes of onsets in speech buffers */
  383. /* VWIN Voicing window indices */
  384. /* AWIN Analysis window indices */
  385. /* EWIN Energy window indices */
  386. /* VOIBUF Voicing decisions on windows in VWIN */
  387. /* RMSBUF RMS energy */
  388. /* RCBUF Reflection Coefficients */
  389. /* Pitch is handled separately from the above parameters. */
  390. /* The following variables deal with pitch: */
  391. /* MIDX Encoded initial pitch estimate for analysis frame */
  392. /* IPITCH Initial pitch computed for frame AF (decoded from MIDX) */
  393. /* PITCH The encoded pitch value (index into TAU) for the present */
  394. /* frame (delayed and smoothed by Dyptrack) */
  395. /* Parameter adjustments */
  396. if (speech) {
  397. --speech;
  398. }
  399. if (voice) {
  400. --voice;
  401. }
  402. if (rc) {
  403. --rc;
  404. }
  405. /* Function Body */
  406. /* Calculations are done on future frame due to requirements */
  407. /* of the pitch tracker. Delay RMS and RC's 2 frames to give */
  408. /* current frame parameters on return. */
  409. /* Update all buffers */
  410. inbuf = &(st->inbuf[0]);
  411. pebuf = &(st->pebuf[0]);
  412. lpbuf = &(st->lpbuf[0]);
  413. ivbuf = &(st->ivbuf[0]);
  414. bias = &(st->bias);
  415. osbuf = &(st->osbuf[0]);
  416. osptr = &(st->osptr);
  417. obound = &(st->obound[0]);
  418. vwin = &(st->vwin[0]);
  419. awin = &(st->awin[0]);
  420. voibuf = &(st->voibuf[0]);
  421. rmsbuf = &(st->rmsbuf[0]);
  422. rcbuf = &(st->rcbuf[0]);
  423. zpre = &(st->zpre);
  424. i__1 = 720 - contrl_1.lframe;
  425. for (i__ = 181; i__ <= i__1; ++i__) {
  426. inbuf[i__ - 181] = inbuf[contrl_1.lframe + i__ - 181];
  427. pebuf[i__ - 181] = pebuf[contrl_1.lframe + i__ - 181];
  428. }
  429. i__1 = 540 - contrl_1.lframe;
  430. for (i__ = 229; i__ <= i__1; ++i__) {
  431. ivbuf[i__ - 229] = ivbuf[contrl_1.lframe + i__ - 229];
  432. }
  433. i__1 = 720 - contrl_1.lframe;
  434. for (i__ = 25; i__ <= i__1; ++i__) {
  435. lpbuf[i__ - 25] = lpbuf[contrl_1.lframe + i__ - 25];
  436. }
  437. j = 1;
  438. i__1 = (*osptr) - 1;
  439. for (i__ = 1; i__ <= i__1; ++i__) {
  440. if (osbuf[i__ - 1] > contrl_1.lframe) {
  441. osbuf[j - 1] = osbuf[i__ - 1] - contrl_1.lframe;
  442. ++j;
  443. }
  444. }
  445. *osptr = j;
  446. voibuf[0] = voibuf[2];
  447. voibuf[1] = voibuf[3];
  448. for (i__ = 1; i__ <= 2; ++i__) {
  449. vwin[(i__ << 1) - 2] = vwin[((i__ + 1) << 1) - 2] - contrl_1.lframe;
  450. vwin[(i__ << 1) - 1] = vwin[((i__ + 1) << 1) - 1] - contrl_1.lframe;
  451. awin[(i__ << 1) - 2] = awin[((i__ + 1) << 1) - 2] - contrl_1.lframe;
  452. awin[(i__ << 1) - 1] = awin[((i__ + 1) << 1) - 1] - contrl_1.lframe;
  453. /* EWIN(*,J) is unused for J .NE. AF, so the following shift is
  454. */
  455. /* unnecessary. It also causes error messages when the C versio
  456. n */
  457. /* of the code created from this by f2c is run with Purify. It
  458. */
  459. /* correctly complains that uninitialized memory is being read.
  460. */
  461. /* EWIN(1,I) = EWIN(1,I+1) - LFRAME */
  462. /* EWIN(2,I) = EWIN(2,I+1) - LFRAME */
  463. obound[i__ - 1] = obound[i__];
  464. voibuf[i__ * 2] = voibuf[(i__ + 1) * 2];
  465. voibuf[(i__ << 1) + 1] = voibuf[((i__ + 1) << 1) + 1];
  466. rmsbuf[i__ - 1] = rmsbuf[i__];
  467. i__1 = contrl_1.order;
  468. for (j = 1; j <= i__1; ++j) {
  469. rcbuf[j + i__ * 10 - 11] = rcbuf[j + (i__ + 1) * 10 - 11];
  470. }
  471. }
  472. /* Copy input speech, scale to sign+12 bit integers */
  473. /* Remove long term DC bias. */
  474. /* If the average value in the frame was over 1/4096 (after current
  475. */
  476. /* BIAS correction), then subtract that much more from samples in */
  477. /* next frame. If the average value in the frame was under */
  478. /* -1/4096, add 1/4096 more to samples in next frame. In all other
  479. */
  480. /* cases, keep BIAS the same. */
  481. temp = 0.f;
  482. i__1 = contrl_1.lframe;
  483. for (i__ = 1; i__ <= i__1; ++i__) {
  484. inbuf[720 - contrl_1.lframe + i__ - 181] = speech[i__] * 4096.f -
  485. (*bias);
  486. temp += inbuf[720 - contrl_1.lframe + i__ - 181];
  487. }
  488. if (temp > (real) contrl_1.lframe) {
  489. *bias += 1;
  490. }
  491. if (temp < (real) (-contrl_1.lframe)) {
  492. *bias += -1;
  493. }
  494. /* Place Voicing Window */
  495. i__ = 721 - contrl_1.lframe;
  496. preemp_(&inbuf[i__ - 181], &pebuf[i__ - 181], &contrl_1.lframe, &precoef,
  497. zpre);
  498. onset_(pebuf, osbuf, osptr, &c__10, &c__181, &c__720, &contrl_1.lframe, st);
  499. /* MAXOSP is just a debugging variable. */
  500. /* MAXOSP = MAX( MAXOSP, OSPTR ) */
  501. placev_(osbuf, osptr, &c__10, &obound[2], vwin, &c__3, &contrl_1.lframe,
  502. &c__90, &c__156, &c__307, &c__462);
  503. /* The Pitch Extraction algorithm estimates the pitch for a frame
  504. */
  505. /* of speech by locating the minimum of the average magnitude difference
  506. */
  507. /* function (AMDF). The AMDF operates on low-pass, inverse filtered */
  508. /* speech. (The low-pass filter is an 800 Hz, 19 tap, equiripple, FIR
  509. */
  510. /* filter and the inverse filter is a 2nd-order LPC filter.) The pitch
  511. */
  512. /* estimate is later refined by dynamic programming (DYPTRK). However,
  513. */
  514. /* since some of DYPTRK's parameters are a function of the voicing */
  515. /* decisions, a voicing decision must precede the final pitch estimation.
  516. */
  517. /* See subroutines LPFILT, IVFILT, and TBDM. */
  518. /* LPFILT reads indices LBUFH-LFRAME-29 = 511 through LBUFH = 720 */
  519. /* of INBUF, and writes indices LBUFH+1-LFRAME = 541 through LBUFH
  520. */
  521. /* = 720 of LPBUF. */
  522. lpfilt_(&inbuf[228], &lpbuf[384], &c__312, &contrl_1.lframe);
  523. /* IVFILT reads indices (PWINH-LFRAME-7) = 353 through PWINH = 540
  524. */
  525. /* of LPBUF, and writes indices (PWINH-LFRAME+1) = 361 through */
  526. /* PWINH = 540 of IVBUF. */
  527. ivfilt_(&lpbuf[204], ivbuf, &c__312, &contrl_1.lframe, ivrc);
  528. /* TBDM reads indices PWINL = 229 through */
  529. /* (PWINL-1)+MAXWIN+(TAU(LTAU)-TAU(1))/2 = 452 of IVBUF, and writes
  530. */
  531. /* indices 1 through LTAU = 60 of AMDF. */
  532. tbdm_(ivbuf, &c__156, tau, &c__60, amdf, &minptr, &maxptr, &mintau);
  533. /* Voicing decisions are made for each half frame of input speech.
  534. */
  535. /* An initial voicing classification is made for each half of the */
  536. /* analysis frame, and the voicing decisions for the present frame */
  537. /* are finalized. See subroutine VOICIN. */
  538. /* The voicing detector (VOICIN) classifies the input signal as */
  539. /* unvoiced (including silence) or voiced using the AMDF windowed */
  540. /* maximum-to-minimum ratio, the zero crossing rate, energy measures, */
  541. /* reflection coefficients, and prediction gains. */
  542. /* The pitch and voicing rules apply smoothing and isolated */
  543. /* corrections to the pitch and voicing estimates and, in the process,
  544. */
  545. /* introduce two frames of delay into the corrected pitch estimates and
  546. */
  547. /* voicing decisions. */
  548. for (half = 1; half <= 2; ++half) {
  549. voicin_(&vwin[4], inbuf, lpbuf, buflim, &half, &amdf[minptr - 1], &
  550. amdf[maxptr - 1], &mintau, ivrc, obound, voibuf, &c__3, st);
  551. }
  552. /* Find the minimum cost pitch decision over several frames */
  553. /* given the current voicing decision and the AMDF array */
  554. dyptrk_(amdf, &c__60, &minptr, &voibuf[7], pitch, &midx, st);
  555. ipitch = tau[midx - 1];
  556. /* Place spectrum analysis and energy windows */
  557. placea_(&ipitch, voibuf, &obound[2], &c__3, vwin, awin, ewin, &
  558. contrl_1.lframe, &c__156);
  559. /* Remove short term DC bias over the analysis window, Put result in ABUF
  560. */
  561. lanal = awin[5] + 1 - awin[4];
  562. dcbias_(&lanal, &pebuf[awin[4] - 181], abuf);
  563. /* ABUF(1:LANAL) is now defined. It is equal to */
  564. /* PEBUF(AWIN(1,AF):AWIN(2,AF)) corrected for short term DC bias. */
  565. /* Compute RMS over integer number of pitch periods within the */
  566. /* analysis window. */
  567. /* Note that in a hardware implementation this computation may be */
  568. /* simplified by using diagonal elements of PHI computed by MLOAD. */
  569. i__1 = ewin[5] - ewin[4] + 1;
  570. energy_(&i__1, &abuf[ewin[4] - awin[4]], &rmsbuf[2]);
  571. /* Matrix load and invert, check RC's for stability */
  572. mload_(&contrl_1.order, &c__1, &lanal, abuf, phi, psi);
  573. invert_(&contrl_1.order, phi, psi, &rcbuf[20]);
  574. rcchk_(&contrl_1.order, &rcbuf[10], &rcbuf[20]);
  575. /* Set return parameters */
  576. voice[1] = voibuf[2];
  577. voice[2] = voibuf[3];
  578. *rms = rmsbuf[0];
  579. i__1 = contrl_1.order;
  580. for (i__ = 1; i__ <= i__1; ++i__) {
  581. rc[i__] = rcbuf[i__ - 1];
  582. }
  583. return 0;
  584. } /* analys_ */