chanwr.c 7.0 KB

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