decode.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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:22:39 jaf
  14. * Removed all static local variables that were SAVE'd in the Fortran
  15. * code, and put them in struct lpc10_decoder_state that is passed as an
  16. * argument.
  17. *
  18. * Removed init function, since all initialization is now done in
  19. * init_lpc10_decoder_state().
  20. *
  21. * Revision 1.1 1996/08/19 22:32:38 jaf
  22. * Initial revision
  23. *
  24. */
  25. /* -- translated by f2c (version 19951025).
  26. You must link the resulting object file with the libraries:
  27. -lf2c -lm (in that order)
  28. */
  29. #include "f2c.h"
  30. #ifdef P_R_O_T_O_T_Y_P_E_S
  31. extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);
  32. /* comlen contrl_ 12 */
  33. /*:ref: ham84_ 14 3 4 4 4 */
  34. /*:ref: median_ 4 3 4 4 4 */
  35. #endif
  36. /* Common Block Declarations */
  37. extern struct {
  38. integer order, lframe;
  39. logical corrp;
  40. } contrl_;
  41. #define contrl_1 contrl_
  42. /* Table of constant values */
  43. static integer c__2 = 2;
  44. /* ***************************************************************** */
  45. /* DECODE Version 54 */
  46. /* $Log$
  47. * Revision 1.16 2004/06/26 03:50:14 markster
  48. * Merge source cleanups (bug #1911)
  49. *
  50. * Revision 1.15 2003/09/19 01:20:22 markster
  51. * Code cleanups (bug #66)
  52. *
  53. * Revision 1.2 2003/09/19 01:20:22 markster
  54. * Code cleanups (bug #66)
  55. *
  56. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  57. * mer feb 12 14:56:57 CET 2003
  58. *
  59. * Revision 1.2 2000/01/05 08:20:39 markster
  60. * Some OSS fixes and a few lpc changes to make it actually work
  61. *
  62. * Revision 1.2 1996/08/20 20:22:39 jaf
  63. * Removed all static local variables that were SAVE'd in the Fortran
  64. * code, and put them in struct lpc10_decoder_state that is passed as an
  65. * argument.
  66. *
  67. * Removed init function, since all initialization is now done in
  68. * init_lpc10_decoder_state().
  69. *
  70. * Revision 1.1 1996/08/19 22:32:38 jaf
  71. * Initial revision
  72. * */
  73. /* Revision 1.5 1996/05/23 20:06:03 jaf */
  74. /* Assigned PITCH a "default" value on the first call, since otherwise it */
  75. /* would be left uninitialized. */
  76. /* Revision 1.4 1996/03/26 19:35:18 jaf */
  77. /* Commented out trace statements. */
  78. /* Revision 1.3 1996/03/21 21:10:50 jaf */
  79. /* Added entry INITDECODE to reinitialize the local state of subroutine */
  80. /* DECODE. */
  81. /* Revision 1.2 1996/03/21 21:04:50 jaf */
  82. /* Determined which local variables should be saved from one invocation */
  83. /* to the next, and guessed initial values for some that should have been */
  84. /* saved, but weren't given initial values. Many of the arrays are */
  85. /* "constants", and many local variables are only used if the "global" */
  86. /* variable CORRP is .TRUE. */
  87. /* Added comments explaining which indices of array arguments are read or */
  88. /* written. */
  89. /* Revision 1.1 1996/02/12 03:21:10 jaf */
  90. /* Initial revision */
  91. /* ***************************************************************** */
  92. /* This subroutine provides error correction and decoding */
  93. /* for all LPC parameters */
  94. /* Input: */
  95. /* IPITV - Index value of pitch */
  96. /* IRMS - Coded Energy */
  97. /* CORRP - Error correction: */
  98. /* If FALSE, parameters are decoded directly with no delay. If TRUE, */
  99. /* most important parameter bits are protected by Hamming code and */
  100. /* median smoothed. This requires an additional frame of delay. */
  101. /* Input/Output: */
  102. /* IRC - Coded Reflection Coefficients */
  103. /* Indices 1 through ORDER always read, then written. */
  104. /* Output: */
  105. /* VOICE - Half frame voicing decisions */
  106. /* Indices 1 through 2 written. */
  107. /* PITCH - Decoded pitch */
  108. /* RMS - Energy */
  109. /* RC - Reflection coefficients */
  110. /* Indices 1 through ORDER written. */
  111. /* NOTE: Zero RC's should be done more directly, but this would affect */
  112. /* coded parameter printout. */
  113. /* This subroutine maintains local state from one call to the next. If */
  114. /* you want to switch to using a new audio stream for this filter, or */
  115. /* reinitialize its state for any other reason, call the ENTRY */
  116. /* INITDECODE. */
  117. /* Subroutine */ int decode_(integer *ipitv, integer *irms,
  118. integer *irc, integer *voice, integer *pitch, real *rms, real *rc,
  119. struct lpc10_decoder_state *st)
  120. {
  121. /* Initialized data */
  122. logical *first;
  123. static integer ethrs = 2048;
  124. static integer ethrs1 = 128;
  125. static integer ethrs2 = 1024;
  126. static integer ethrs3 = 2048;
  127. static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,
  128. 25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,
  129. 24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,
  130. 3641 };
  131. static real corth[32] /* was [4][8] */ = { 32767.f,10.f,5.f,0.f,
  132. 32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,
  133. 11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,
  134. 3.2f,0.f };
  135. static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,
  136. 20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,
  137. 3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,
  138. 100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,
  139. 3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,
  140. 3,3,3,3,1,3,3,3,1,3,1,1,1 };
  141. static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
  142. 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
  143. 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
  144. 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
  145. static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,
  146. 96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,
  147. 127 };
  148. static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,
  149. .3828f };
  150. integer *ivp2h;
  151. static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }
  152. ;
  153. static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };
  154. static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };
  155. static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };
  156. static integer bit[5] = { 2,4,8,16,32 };
  157. integer *iovoic;
  158. integer *iavgp;
  159. integer *iptold;
  160. integer *erate;
  161. integer *drc;
  162. integer *dpit;
  163. integer *drms;
  164. /* System generated locals */
  165. integer i__1, i__2;
  166. /* Builtin functions */
  167. integer pow_ii(integer *, integer *);
  168. /* Local variables */
  169. extern /* Subroutine */ int ham84_(integer *, integer *, integer *);
  170. integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;
  171. extern integer median_(integer *, integer *, integer *);
  172. integer ishift, errcnt, lsb;
  173. /* $Log$
  174. * Revision 1.16 2004/06/26 03:50:14 markster
  175. * Merge source cleanups (bug #1911)
  176. *
  177. * Revision 1.15 2003/09/19 01:20:22 markster
  178. * Code cleanups (bug #66)
  179. *
  180. * Revision 1.2 2003/09/19 01:20:22 markster
  181. * Code cleanups (bug #66)
  182. *
  183. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  184. * mer feb 12 14:56:57 CET 2003
  185. *
  186. * Revision 1.2 2000/01/05 08:20:39 markster
  187. * Some OSS fixes and a few lpc changes to make it actually work
  188. *
  189. * Revision 1.2 1996/08/20 20:22:39 jaf
  190. * Removed all static local variables that were SAVE'd in the Fortran
  191. * code, and put them in struct lpc10_decoder_state that is passed as an
  192. * argument.
  193. *
  194. * Removed init function, since all initialization is now done in
  195. * init_lpc10_decoder_state().
  196. *
  197. * Revision 1.1 1996/08/19 22:32:38 jaf
  198. * Initial revision
  199. * */
  200. /* Revision 1.3 1996/03/29 22:03:47 jaf */
  201. /* Removed definitions for any constants that were no longer used. */
  202. /* Revision 1.2 1996/03/26 19:34:33 jaf */
  203. /* Added comments indicating which constants are not needed in an */
  204. /* application that uses the LPC-10 coder. */
  205. /* Revision 1.1 1996/02/07 14:43:51 jaf */
  206. /* Initial revision */
  207. /* LPC Configuration parameters: */
  208. /* Frame size, Prediction order, Pitch period */
  209. /* Arguments */
  210. /* $Log$
  211. * Revision 1.16 2004/06/26 03:50:14 markster
  212. * Merge source cleanups (bug #1911)
  213. *
  214. * Revision 1.15 2003/09/19 01:20:22 markster
  215. * Code cleanups (bug #66)
  216. *
  217. * Revision 1.2 2003/09/19 01:20:22 markster
  218. * Code cleanups (bug #66)
  219. *
  220. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  221. * mer feb 12 14:56:57 CET 2003
  222. *
  223. * Revision 1.2 2000/01/05 08:20:39 markster
  224. * Some OSS fixes and a few lpc changes to make it actually work
  225. *
  226. * Revision 1.2 1996/08/20 20:22:39 jaf
  227. * Removed all static local variables that were SAVE'd in the Fortran
  228. * code, and put them in struct lpc10_decoder_state that is passed as an
  229. * argument.
  230. *
  231. * Removed init function, since all initialization is now done in
  232. * init_lpc10_decoder_state().
  233. *
  234. * Revision 1.1 1996/08/19 22:32:38 jaf
  235. * Initial revision
  236. * */
  237. /* Revision 1.3 1996/03/29 22:05:55 jaf */
  238. /* Commented out the common block variables that are not needed by the */
  239. /* embedded version. */
  240. /* Revision 1.2 1996/03/26 19:34:50 jaf */
  241. /* Added comments indicating which constants are not needed in an */
  242. /* application that uses the LPC-10 coder. */
  243. /* Revision 1.1 1996/02/07 14:44:09 jaf */
  244. /* Initial revision */
  245. /* LPC Processing control variables: */
  246. /* *** Read-only: initialized in setup */
  247. /* Files for Speech, Parameter, and Bitstream Input & Output, */
  248. /* and message and debug outputs. */
  249. /* Here are the only files which use these variables: */
  250. /* lpcsim.f setup.f trans.f error.f vqsetup.f */
  251. /* Many files which use fdebug are not listed, since it is only used in */
  252. /* those other files conditionally, to print trace statements. */
  253. /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  254. /* LPC order, Frame size, Quantization rate, Bits per frame, */
  255. /* Error correction */
  256. /* Subroutine SETUP is the only place where order is assigned a value, */
  257. /* and that value is 10. It could increase efficiency 1% or so to */
  258. /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
  259. */
  260. /* a variable in a COMMON block, since it is used in many places in the */
  261. /* core of the coding and decoding routines. Actually, I take that back.
  262. */
  263. /* At least when compiling with f2c, the upper bound of DO loops is */
  264. /* stored in a local variable before the DO loop begins, and then that is
  265. */
  266. /* compared against on each iteration. */
  267. /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
  268. /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
  269. /* is used in only a few places, and never in the core coding and */
  270. /* decoding routines, so it could be eliminated entirely. */
  271. /* nbits is similar to quant, and is given a value of 54 in SETUP. */
  272. /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
  273. /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
  274. /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
  275. */
  276. /* a constant or a variable, since it is only examined once per frame. */
  277. /* Leaving it as a variable that is set to .TRUE. seems like a good */
  278. /* idea, since it does enable some error-correction capability for */
  279. /* unvoiced frames, with no change in the coding rate, and no noticeable
  280. */
  281. /* quality difference in the decoded speech. */
  282. /* integer quant, nbits */
  283. /* *** Read/write: variables for debugging, not needed for LPC algorithm
  284. */
  285. /* Current frame, Unstable frames, Output clip count, Max onset buffer,
  286. */
  287. /* Debug listing detail level, Line count on listing page */
  288. /* nframe is not needed for an embedded LPC10 at all. */
  289. /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
  290. /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
  291. /* an application, I would recommend removing the call to ERROR in RCCHK,
  292. */
  293. /* and remove ERROR and nunsfm completely. */
  294. /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
  295. */
  296. /* sread.f. When LPC10 is embedded into an application, one might want */
  297. /* to cause it to be incremented in a routine that takes the output of */
  298. /* SYNTHS and sends it to an audio device. It could be optionally */
  299. /* displayed, for those that might want to know what it is. */
  300. /* maxosp is never initialized to 0 in SETUP, although it probably should
  301. */
  302. /* be, and it is updated in subroutine ANALYS. I doubt that its value */
  303. /* would be of much interest to an application in which LPC10 is */
  304. /* embedded. */
  305. /* listl and lincnt are not needed for an embedded LPC10 at all. */
  306. /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
  307. /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
  308. /* common /contrl/ quant, nbits */
  309. /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
  310. /* Function return value definitions */
  311. /* Parameters/constants */
  312. /* The variables below that are not Fortran PARAMETER's are */
  313. /* initialized with DATA statements, and then never modified. */
  314. /* The following are used regardless of CORRP's value. */
  315. /* DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */
  316. /* The following are used only if CORRP is .TRUE. */
  317. /* ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */
  318. /* Local variables that need not be saved */
  319. /* The following are used regardless of CORRP's value */
  320. /* The following are used only if CORRP is .TRUE. */
  321. /* Local state */
  322. /* The following are used regardless of CORRP's value */
  323. /* The following are used only if CORRP is .TRUE. */
  324. /* I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */
  325. /* and DRMS. They should be checked to see if they are reasonable.
  326. */
  327. /* I'm also guessing for ERATE, but I think 0 is the right initial
  328. */
  329. /* value. */
  330. /* Parameter adjustments */
  331. if (irc) {
  332. --irc;
  333. }
  334. if (voice) {
  335. --voice;
  336. }
  337. if (rc) {
  338. --rc;
  339. }
  340. /* Function Body */
  341. iptold = &(st->iptold);
  342. first = &(st->first);
  343. ivp2h = &(st->ivp2h);
  344. iovoic = &(st->iovoic);
  345. iavgp = &(st->iavgp);
  346. erate = &(st->erate);
  347. drc = &(st->drc[0]);
  348. dpit = &(st->dpit[0]);
  349. drms = &(st->drms[0]);
  350. /* DATA statements for "constants" defined above. */
  351. /* IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) */
  352. /* 800 FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) */
  353. /* If no error correction, do pitch and voicing then jump to decode */
  354. i4 = detau[*ipitv];
  355. if (! contrl_1.corrp) {
  356. voice[1] = 1;
  357. voice[2] = 1;
  358. if (*ipitv <= 1) {
  359. voice[1] = 0;
  360. }
  361. if (*ipitv == 0 || *ipitv == 2) {
  362. voice[2] = 0;
  363. }
  364. *pitch = i4;
  365. if (*pitch <= 4) {
  366. *pitch = *iptold;
  367. }
  368. if (voice[1] == 1 && voice[2] == 1) {
  369. *iptold = *pitch;
  370. }
  371. if (voice[1] != voice[2]) {
  372. *pitch = *iptold;
  373. }
  374. goto L900;
  375. }
  376. /* Do error correction pitch and voicing */
  377. if (i4 > 4) {
  378. dpit[0] = i4;
  379. ivoic = 2;
  380. *iavgp = (*iavgp * 15 + i4 + 8) / 16;
  381. } else {
  382. ivoic = i4;
  383. dpit[0] = *iavgp;
  384. }
  385. drms[0] = *irms;
  386. i__1 = contrl_1.order;
  387. for (i__ = 1; i__ <= i__1; ++i__) {
  388. drc[i__ * 3 - 3] = irc[i__];
  389. }
  390. /* Determine index to IVTAB from V/UV decision */
  391. /* If error rate is high then use alternate table */
  392. index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;
  393. i1 = ivtab[index - 1];
  394. ipit = i1 & 3;
  395. icorf = i1 / 8;
  396. if (*erate < ethrs) {
  397. icorf /= 64;
  398. }
  399. /* Determine error rate: 4=high 1=low */
  400. ixcor = 4;
  401. if (*erate < ethrs3) {
  402. ixcor = 3;
  403. }
  404. if (*erate < ethrs2) {
  405. ixcor = 2;
  406. }
  407. if (*erate < ethrs1) {
  408. ixcor = 1;
  409. }
  410. /* Voice/unvoice decision determined from bits 0 and 1 of IVTAB */
  411. voice[1] = icorf / 2 & 1;
  412. voice[2] = icorf & 1;
  413. /* Skip decoding on first frame because present data not yet available */
  414. if (*first) {
  415. *first = FALSE_;
  416. /* Assign PITCH a "default" value on the first call, since */
  417. /* otherwise it would be left uninitialized. The two lines
  418. */
  419. /* below were copied from above, since it seemed like a */
  420. /* reasonable thing to do for the first call. */
  421. *pitch = i4;
  422. if (*pitch <= 4) {
  423. *pitch = *iptold;
  424. }
  425. goto L500;
  426. }
  427. /* If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). */
  428. /* Determine error rate and correct errors using a Hamming 8,4 code */
  429. /* during transition or unvoiced frame. If IOUT is negative, */
  430. /* more than 1 error occurred, use previous frame's parameters. */
  431. if ((icorf & bit[3]) != 0) {
  432. errcnt = 0;
  433. lsb = drms[1] & 1;
  434. index = (drc[22] << 4) + drms[1] / 2;
  435. ham84_(&index, &iout, &errcnt);
  436. drms[1] = drms[2];
  437. if (iout >= 0) {
  438. drms[1] = (iout << 1) + lsb;
  439. }
  440. for (i__ = 1; i__ <= 4; ++i__) {
  441. if (i__ == 1) {
  442. i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);
  443. } else {
  444. i1 = drc[(9 - i__) * 3 - 2] & 15;
  445. }
  446. i2 = drc[(5 - i__) * 3 - 2] & 31;
  447. lsb = i2 & 1;
  448. index = (i1 << 4) + i2 / 2;
  449. ham84_(&index, &iout, &errcnt);
  450. if (iout >= 0) {
  451. iout = (iout << 1) + lsb;
  452. if ((iout & 16) == 16) {
  453. iout += -32;
  454. }
  455. } else {
  456. iout = drc[(5 - i__) * 3 - 1];
  457. }
  458. drc[(5 - i__) * 3 - 2] = iout;
  459. }
  460. /* Determine error rate */
  461. *erate = (integer)(*erate * .96875f + errcnt * 102);
  462. }
  463. /* Get unsmoothed RMS, RC's, and PITCH */
  464. *irms = drms[1];
  465. i__1 = contrl_1.order;
  466. for (i__ = 1; i__ <= i__1; ++i__) {
  467. irc[i__] = drc[i__ * 3 - 2];
  468. }
  469. if (ipit == 1) {
  470. dpit[1] = dpit[2];
  471. }
  472. if (ipit == 3) {
  473. dpit[1] = dpit[0];
  474. }
  475. *pitch = dpit[1];
  476. /* If bit 2 of ICORF is set then smooth RMS and RC's, */
  477. if ((icorf & bit[1]) != 0) {
  478. if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3]
  479. && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[
  480. ixcor + 3]) {
  481. *irms = median_(&drms[2], &drms[1], drms);
  482. }
  483. for (i__ = 1; i__ <= 6; ++i__) {
  484. if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))
  485. >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *
  486. 3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[
  487. ixcor + ((i__ + 2) << 2) - 5]) {
  488. irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[
  489. i__ * 3 - 3]);
  490. }
  491. }
  492. }
  493. /* If bit 3 of ICORF is set then smooth pitch */
  494. if ((icorf & bit[2]) != 0) {
  495. if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1]
  496. && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[
  497. ixcor - 1]) {
  498. *pitch = median_(&dpit[2], &dpit[1], dpit);
  499. }
  500. }
  501. /* If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with */
  502. /* values so that after quantization bias is removed in decode */
  503. /* the values will be zero. */
  504. L500:
  505. if ((icorf & bit[4]) != 0) {
  506. i__1 = contrl_1.order;
  507. for (i__ = 5; i__ <= i__1; ++i__) {
  508. irc[i__] = zrc[i__ - 1];
  509. }
  510. }
  511. /* House keeping - one frame delay */
  512. *iovoic = ivoic;
  513. *ivp2h = voice[2];
  514. dpit[2] = dpit[1];
  515. dpit[1] = dpit[0];
  516. drms[2] = drms[1];
  517. drms[1] = drms[0];
  518. i__1 = contrl_1.order;
  519. for (i__ = 1; i__ <= i__1; ++i__) {
  520. drc[i__ * 3 - 1] = drc[i__ * 3 - 2];
  521. drc[i__ * 3 - 2] = drc[i__ * 3 - 3];
  522. }
  523. L900:
  524. /* IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) */
  525. /* 801 FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) */
  526. /* Decode RMS */
  527. *irms = rmst[(31 - *irms) * 2];
  528. /* Decode RC(1) and RC(2) from log-area-ratios */
  529. /* Protect from illegal coded value (-16) caused by bit errors */
  530. for (i__ = 1; i__ <= 2; ++i__) {
  531. i2 = irc[i__];
  532. i1 = 0;
  533. if (i2 < 0) {
  534. i1 = 1;
  535. i2 = -i2;
  536. if (i2 > 15) {
  537. i2 = 0;
  538. }
  539. }
  540. i2 = detab7[i2 * 2];
  541. if (i1 == 1) {
  542. i2 = -i2;
  543. }
  544. ishift = 15 - nbit[i__ - 1];
  545. irc[i__] = i2 * pow_ii(&c__2, &ishift);
  546. }
  547. /* Decode RC(3)-RC(10) to sign plus 14 bits */
  548. i__1 = contrl_1.order;
  549. for (i__ = 3; i__ <= i__1; ++i__) {
  550. i2 = irc[i__];
  551. ishift = 15 - nbit[i__ - 1];
  552. i2 *= pow_ii(&c__2, &ishift);
  553. i2 += qb[i__ - 3];
  554. irc[i__] = (integer)(i2 * descl[i__ - 3] + deadd[i__ - 3]);
  555. }
  556. /* IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) */
  557. /* 811 FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) */
  558. /* Scale RMS and RC's to reals */
  559. *rms = (real) (*irms);
  560. i__1 = contrl_1.order;
  561. for (i__ = 1; i__ <= i__1; ++i__) {
  562. rc[i__] = irc[i__] / 16384.f;
  563. }
  564. return 0;
  565. } /* decode_ */