Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
11 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1993-1996 Microsoft Corporation
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. // gentable.c
  13. //
  14. // Description:
  15. // This is a utility program to generate various tables in the
  16. // form of 'C' source code. Portions of some of these tables can
  17. // be pasted into codec source code. The output is to stdio
  18. // and can be redirected into a file. Portions of the file can
  19. // then be cut and pasted into another 'C' source file as necessary.
  20. //
  21. //==========================================================================;
  22. #include <stdio.h>
  23. //--------------------------------------------------------------------------;
  24. //
  25. // Name:
  26. // UlawToAlawTable
  27. //
  28. //
  29. // Description:
  30. /* This table was copied directly from the G.711 specification. Using
  31. the G.711 spec terminology, this table converts u-law decoder output
  32. value numbers to A-law decoder output value numbers.
  33. */
  34. //
  35. // Arguments:
  36. //
  37. //
  38. // Return:
  39. //
  40. //
  41. // Notes:
  42. //
  43. //
  44. // History:
  45. // 08/01/93 Created.
  46. //
  47. //
  48. //--------------------------------------------------------------------------;
  49. unsigned char UlawToAlawTable[128] =
  50. {
  51. 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,
  52. 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
  53. 27,29,31,
  54. 33,34,35,36,37,38,39,40,41,42,43,44,
  55. 46,
  56. 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,
  57. 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
  58. 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
  59. 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,
  60. 120,121,122,123,124,125,126,127,128
  61. };
  62. //--------------------------------------------------------------------------;
  63. //
  64. // Name:
  65. // AlawToUlawTable
  66. //
  67. //
  68. // Description:
  69. /* This table was copied directly from the G.711 specification. Using
  70. the G.711 spec terminology, this table converts A-law decoder output
  71. value numbers to u-law decoder output value numbers. A-law decoder
  72. output value numbers range from 1 to 128, so AlawToUlawTable[0] is
  73. unused. Note that u-law decoder output value numbers range from
  74. 0 to 127.
  75. */
  76. //
  77. // Arguments:
  78. //
  79. //
  80. // Return:
  81. //
  82. //
  83. // Notes:
  84. //
  85. //
  86. // History:
  87. // 08/01/93 Created.
  88. //
  89. //
  90. //--------------------------------------------------------------------------;
  91. unsigned char AlawToUlawTable[129] =
  92. {
  93. 0, // this first entry not used
  94. 1,3,5,7,9,11,13,
  95. 15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
  96. 32,32,33,33,34,34,35,35,
  97. 36,37,38,39,40,41,42,43,44,45,46,47,
  98. 48,48,49,49,
  99. 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
  100. 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
  101. 79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
  102. 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,
  103. 116,117,118,119,120,121,122,123,124,125,126,127
  104. };
  105. short DecodeTable[256];
  106. //
  107. // Our main procedure.
  108. //
  109. void main()
  110. {
  111. short i,j;
  112. short SegBase[16];
  113. short IntervalStep[16];
  114. short Sample;
  115. //
  116. // This generates a decode table for A-law. The resulting
  117. // table can be used to convert an A-law character to
  118. // a 16-bit PCM value.
  119. //
  120. // These seg base values and interval steps are based directly
  121. // on the G.711 A-law spec. They correspond to 13-bit PCM data.
  122. SegBase[ 0] = -1; IntervalStep[ 0] = -2;
  123. SegBase[ 1] = -33; IntervalStep[ 1] = -2;
  124. SegBase[ 2] = -66; IntervalStep[ 2] = -4;
  125. SegBase[ 3] = -132; IntervalStep[ 3] = -8;
  126. SegBase[ 4] = -264; IntervalStep[ 4] = -16;
  127. SegBase[ 5] = -528; IntervalStep[ 5] = -32;
  128. SegBase[ 6] = -1056; IntervalStep[ 6] = -64;
  129. SegBase[ 7] = -2112; IntervalStep[ 7] = -128;
  130. SegBase[ 8] = 1; IntervalStep[ 8] = 2;
  131. SegBase[ 9] = 33; IntervalStep[ 9] = 2;
  132. SegBase[10] = 66; IntervalStep[10] = 4;
  133. SegBase[11] = 132; IntervalStep[11] = 8;
  134. SegBase[12] = 264; IntervalStep[12] = 16;
  135. SegBase[13] = 528; IntervalStep[13] = 32;
  136. SegBase[14] = 1056; IntervalStep[14] = 64;
  137. SegBase[15] = 2112; IntervalStep[15] = 128;
  138. printf("\n\n\n\n\n// A-law decode table:\n\n");
  139. for (i=0; i<16; i++)
  140. for (j=0; j<16; j++)
  141. {
  142. Sample = SegBase[i^0x05] + IntervalStep[i^0x05]*(j^0x05);
  143. // Sample is a 13-bit signed PCM value.
  144. // In our table, we'll convert it to 16-bit. The
  145. // generated comment will indicate the 13-bit value.
  146. printf( "\t%6d,\t\t// y[%02x]= %6d\n",
  147. Sample << 3,
  148. i*16 + j,
  149. Sample);
  150. }
  151. //
  152. // This generates a decode table for u-law. The resulting
  153. // table can be used to convert a u-law character to
  154. // a 16-bit PCM value.
  155. //
  156. // These seg base values and interval steps are based directly
  157. // on the G.711 A-law spec. They correspond to 14-bit PCM data.
  158. SegBase[ 0] = -8031; IntervalStep[ 0] = 256;
  159. SegBase[ 1] = -3999; IntervalStep[ 1] = 128;
  160. SegBase[ 2] = -1983; IntervalStep[ 2] = 64;
  161. SegBase[ 3] = -975; IntervalStep[ 3] = 32;
  162. SegBase[ 4] = -471; IntervalStep[ 4] = 16;
  163. SegBase[ 5] = -219; IntervalStep[ 5] = 8;
  164. SegBase[ 6] = -93; IntervalStep[ 6] = 4;
  165. SegBase[ 7] = -30; IntervalStep[ 7] = 2;
  166. SegBase[ 8] = 8031; IntervalStep[ 8] = -256;
  167. SegBase[ 9] = 3999; IntervalStep[ 9] = -128;
  168. SegBase[10] = 1983; IntervalStep[10] = -64;
  169. SegBase[11] = 975; IntervalStep[11] = -32;
  170. SegBase[12] = 471; IntervalStep[12] = -16;
  171. SegBase[13] = 219; IntervalStep[13] = -8;
  172. SegBase[14] = 93; IntervalStep[14] = -4;
  173. SegBase[15] = 30; IntervalStep[15] = -2;
  174. printf("\n\n\n\n\n// u-law decode table:\n\n");
  175. for (i=0; i<16; i++)
  176. for (j=0; j<16; j++)
  177. {
  178. Sample = SegBase[i] + IntervalStep[i]*j;
  179. // Sample is a 14-bit signed PCM value.
  180. // In our table, we'll convert it to 16-bit. The
  181. // generated comment will indicate the 14-bit value.
  182. printf( "\t%6d,\t\t// y[%02x]= %6d\n",
  183. Sample << 2,
  184. i*16 + j,
  185. Sample);
  186. }
  187. //
  188. // This generates a conversion table from A-law chars
  189. // to u-law chars. The AlawToUlawTable above converts
  190. // decoder output value numbers, which is not quite what
  191. // we want. Using that table, this routine will generate
  192. // 'C' source code for a table that converts directly from
  193. // A-law chars to u-law chars.
  194. //
  195. printf("\n\n\n\n\n// A-law to u-law char conversion table:\n\n");
  196. for (i=0; i<256; i++) // i counts thru all A-law chars
  197. {
  198. // Here is the process to go from an A-law char
  199. // to a u-law char.
  200. // 1. convert from A-law char to A-law decoder
  201. // output value number. from observing the tables
  202. // in the G.711 spec it can be seen that this is
  203. // done by inverting the even bits and dropping the
  204. // sign bit of the A-law char and then adding 1.
  205. // 2. using the AlawToUlawTable above, convert from
  206. // the A-law decoder output value number to the
  207. // corresponding u-law output value number.
  208. // 3. convert from u-law decoder output value
  209. // number to u-law char. from observing the tables
  210. // in the G.711 spec it can be seen that this is
  211. // done by inverting the 7 LSBs of the u-law
  212. // decoder output value number.
  213. // 4. apply polarity to the u-law char. that is,
  214. // set the sign bit of the u-law char the same
  215. // as the sign bit of the original A-law char.
  216. j = i; // j starts of as original A-law char
  217. // Step 1:
  218. j = ((i^0x55) & 0x7F) + 1;
  219. // Step 2:
  220. j = AlawToUlawTable[j];
  221. // Step 3:
  222. j = (j ^ 0x7F);
  223. // Step 4:
  224. j = j | (i & 0x80); // j ends as corresponding u-law char
  225. // Now i is an A-law char and j is the corresponding u-law char
  226. printf( "\t0x%02x,\t\t// A-law[%02x] ==> u-law[%02x]\n",
  227. j,
  228. i,
  229. j);
  230. }
  231. //
  232. // This generates a conversion table from u-law chars
  233. // to A-law chars. The UlawToAlawTable above converts
  234. // decoder output value numbers, which is not quite what
  235. // we want. Using that table, this routine will generate
  236. // 'C' source code for a table that converts directly from
  237. // u-law chars to A-law chars.
  238. //
  239. printf("\n\n\n\n\n// u-law to A-law char conversion table:\n\n");
  240. for (i=0; i<256; i++) // i counts thru all U-law chars
  241. {
  242. // Here is the process to go from a u-law char
  243. // to a A-law char.
  244. // 1. convert from u-law char to u-law decoder
  245. // output value number. from observing the tables
  246. // in the G.711 spec it can be seen that this is
  247. // done by dropping the sign bit of the u-law
  248. // char and then inverting the 7 LSBs.
  249. // 2. using the UlawToAlawTable above, convert from
  250. // the u-law decoder output value number to the
  251. // corresponding A-law output value number.
  252. // 3. convert from A-law decoder output value
  253. // number to A-law char. from observing the tables
  254. // in the G.711 spec it can be seen that this is
  255. // done by subtracting 1 from the A-law decoder output
  256. // value number and inverting the even bits.
  257. // 4. apply polarity to the A-law char. that is,
  258. // set the sign bit of the A-law char the same
  259. // as the sign bit of the original u-law char.
  260. j = i; // j starts of as original u-law char
  261. // Step 1:
  262. j = (i & 0x7F) ^ 0x7F;
  263. // Step 2:
  264. j = UlawToAlawTable[j];
  265. // Step 3:
  266. j = (j - 1)^0x55;
  267. // Step 4:
  268. j = j | (i & 0x80); // j ends as corresponding A-law char
  269. // Now i is a u-law char and j is the corresponding A-law char
  270. printf( "\t0x%02x,\t\t// u-law[%02x] ==> A-law[%02x]\n",
  271. j,
  272. i,
  273. j);
  274. }
  275. return;
  276. }