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

Linux/Unix编程

开发平台:

Visual C++

  1. /*
  2. $Log: chanwr.c,v $
  3. Revision 1.1.1.1  2002/07/28 05:23:21  freeman_yong
  4. lpc10 codec
  5.  * Revision 1.2  1996/08/20  20:20:24  jaf
  6.  * Removed all static local variables that were SAVE'd in the Fortran
  7.  * code, and put them in struct lpc10_encoder_state that is passed as an
  8.  * argument.
  9.  *
  10.  * Revision 1.1  1996/08/19  22:40:31  jaf
  11.  * Initial revision
  12.  *
  13. */
  14. #ifdef P_R_O_T_O_T_Y_P_E_S
  15. extern int chanwr_(integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st);
  16. extern int chanrd_(integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits);
  17. #endif
  18. /*  -- translated by f2c (version 19951025).
  19.    You must link the resulting object file with the libraries:
  20. -lf2c -lm   (in that order)
  21. */
  22. #include "f2c.h"
  23. /* *********************************************************************** */
  24. /*  CHANL Version 49 */
  25. /* $Log: chanwr.c,v $
  26. /* Revision 1.1.1.1  2002/07/28 05:23:21  freeman_yong
  27. /* lpc10 codec
  28. /*
  29.  * Revision 1.2  1996/08/20  20:20:24  jaf
  30.  * Removed all static local variables that were SAVE'd in the Fortran
  31.  * code, and put them in struct lpc10_encoder_state that is passed as an
  32.  * argument.
  33.  *
  34.  * Revision 1.1  1996/08/19  22:40:31  jaf
  35.  * Initial revision
  36.  * */
  37. /* Revision 1.3  1996/03/21  15:14:57  jaf */
  38. /* Added comments about which indices of argument arrays are read or */
  39. /* written, and about the one bit of local state in CHANWR.  CHANRD */
  40. /* has no local state. */
  41. /* Revision 1.2  1996/03/13  18:55:10  jaf */
  42. /* Comments added explaining which of the local variables of this */
  43. /* subroutine need to be saved from one invocation to the next, and which */
  44. /* do not. */
  45. /* Revision 1.1  1996/02/07 14:43:31  jaf */
  46. /* Initial revision */
  47. /* *********************************************************************** */
  48. /* CHANWR: */
  49. /*   Place quantized parameters into bitstream */
  50. /* Input: */
  51. /*  ORDER  - Number of reflection coefficients (not really variable) */
  52. /*  IPITV  - Quantized pitch/voicing parameter */
  53. /*  IRMS   - Quantized energy parameter */
  54. /*  IRC    - Quantized reflection coefficients */
  55. /*           Indices 1 through ORDER read. */
  56. /* Output: */
  57. /*  IBITS  - Serial bitstream */
  58. /*           Indices 1 through 54 written. */
  59. /*           Bit 54, the SYNC bit, alternates from one call to the next. */
  60. /* Subroutine CHANWR maintains one bit of local state from one call to */
  61. /* the next, in the variable ISYNC.  I believe that this one bit is only */
  62. /* intended to allow a receiver to resynchronize its interpretation of */
  63. /* the bit stream, by looking for which of the 54 bits alternates every */
  64. /* frame time.  This is just a simple framing mechanism that is not */
  65. /* useful when other, higher overhead framing mechanisms are used to */
  66. /* transmit the coded frames. */
  67. /* I'm not going to make an entry to reinitialize this bit, since it */
  68. /* doesn't help a receiver much to know whether the first sync bit is a 0 */
  69. /* or a 1.  It needs to examine several frames in sequence to have */
  70. /* reasonably good assurance that its framing is correct. */
  71. /* CHANRD: */
  72. /*   Reconstruct parameters from bitstream */
  73. /* Input: */
  74. /*  ORDER  - Number of reflection coefficients (not really variable) */
  75. /*  IBITS  - Serial bitstream */
  76. /*           Indices 1 through 53 read (SYNC bit is ignored). */
  77. /* Output: */
  78. /*  IPITV  - Quantized pitch/voicing parameter */
  79. /*  IRMS   - Quantized energy parameter */
  80. /*  IRC    - Quantized reflection coefficients */
  81. /*           Indices 1 through ORDER written */
  82. /* Entry CHANRD has no local state. */
  83. /*   IBITS is 54 bits of LPC data ordered as follows: */
  84. /*  R1-0, R2-0, R3-0,  P-0,  A-0, */
  85. /*  R1-1, R2-1, R3-1,  P-1,  A-1, */
  86. /*  R1-2, R4-0, R3-2,  A-2,  P-2, R4-1, */
  87. /*  R1-3, R2-2, R3-3, R4-2,  A-3, */
  88. /*  R1-4, R2-3, R3-4, R4-3,  A-4, */
  89. /*   P-3, R2-4, R7-0, R8-0,  P-4, R4-4, */
  90. /*  R5-0, R6-0, R7-1,R10-0, R8-1, */
  91. /*  R5-1, R6-1, R7-2, R9-0,  P-5, */
  92. /*  R5-2, R6-2,R10-1, R8-2,  P-6, R9-1, */
  93. /*  R5-3, R6-3, R7-3, R9-2, R8-3, SYNC */
  94. /* Subroutine */ int chanwr_0_(int n__, integer *order, integer *ipitv, 
  95. integer *irms, integer *irc, integer *ibits,
  96.        struct lpc10_encoder_state *st)
  97. {
  98.     /* Initialized data */
  99.     integer *isync;
  100.     static integer bit[10] = { 2,4,8,8,8,8,16,16,16,16 };
  101.     static integer iblist[53] = { 13,12,11,1,2,13,12,11,1,2,13,10,11,2,1,10,
  102.     13,12,11,10,2,13,12,11,10,2,1,12,7,6,1,10,9,8,7,4,6,9,8,7,5,1,9,8,
  103.     4,6,1,5,9,8,7,5,6 };
  104.     /* System generated locals */
  105.     integer i__1;
  106.     /* Local variables */
  107.     integer itab[13], i__;
  108. /*       Arguments */
  109. /*       Parameters/constants */
  110. /*       These arrays are not Fortran PARAMETER's, but they are defined */
  111. /*       by DATA statements below, and their contents are never altered. 
  112. */
  113. /*       Local variables that need not be saved */
  114. /*       Local state */
  115. /*       ISYNC is only used by CHANWR, not by ENTRY CHANRD. */
  116.     /* Parameter adjustments */
  117.     --irc;
  118.     --ibits;
  119.     /* Function Body */
  120.     switch(n__) {
  121. case 1: goto L_chanrd;
  122. }
  123.     isync = &(st->isync);
  124. /* ***********************************************************************
  125.  */
  126. /*  Place quantized parameters into bitstream */
  127. /* ***********************************************************************
  128.  */
  129. /*   Place parameters into ITAB */
  130.     itab[0] = *ipitv;
  131.     itab[1] = *irms;
  132.     itab[2] = 0;
  133.     i__1 = *order;
  134.     for (i__ = 1; i__ <= i__1; ++i__) {
  135. itab[i__ + 2] = irc[*order + 1 - i__] & 32767;
  136.     }
  137. /*   Put 54 bits into IBITS array */
  138.     for (i__ = 1; i__ <= 53; ++i__) {
  139. ibits[i__] = itab[iblist[i__ - 1] - 1] & 1;
  140. itab[iblist[i__ - 1] - 1] /= 2;
  141.     }
  142.     ibits[54] = *isync & 1;
  143.     *isync = 1 - *isync;
  144.     return 0;
  145. /* ***********************************************************************
  146.  */
  147. /*  Reconstruct parameters from bitstream */
  148. /* ***********************************************************************
  149.  */
  150. L_chanrd:
  151. /*   Reconstruct ITAB */
  152.     for (i__ = 1; i__ <= 13; ++i__) {
  153. itab[i__ - 1] = 0;
  154.     }
  155.     for (i__ = 1; i__ <= 53; ++i__) {
  156. itab[iblist[54 - i__ - 1] - 1] = (itab[iblist[54 - i__ - 1] - 1] << 1)
  157.  + ibits[54 - i__];
  158.     }
  159. /*   Sign extend RC's */
  160.     i__1 = *order;
  161.     for (i__ = 1; i__ <= i__1; ++i__) {
  162. if ((itab[i__ + 2] & bit[i__ - 1]) != 0) {
  163.     itab[i__ + 2] -= bit[i__ - 1] << 1;
  164. }
  165.     }
  166. /*   Restore variables */
  167.     *ipitv = itab[0];
  168.     *irms = itab[1];
  169.     i__1 = *order;
  170.     for (i__ = 1; i__ <= i__1; ++i__) {
  171. irc[i__] = itab[*order + 4 - i__ - 1];
  172.     }
  173.     return 0;
  174. } /* chanwr_ */
  175. /* Subroutine */ int chanwr_(integer *order, integer *ipitv, integer *irms, 
  176. integer *irc, integer *ibits, struct lpc10_encoder_state *st)
  177. {
  178.     return chanwr_0_(0, order, ipitv, irms, irc, ibits, st);
  179.     }
  180. /* Subroutine */ int chanrd_(integer *order, integer *ipitv, integer *irms, 
  181. integer *irc, integer *ibits)
  182. {
  183.     return chanwr_0_(1, order, ipitv, irms, irc, ibits, 0);
  184.     }