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

Linux/Unix编程

开发平台:

Visual C++

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