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