msgsm.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /* Conversion routines derived from code by guido@sienanet.it */
  2. #define GSM_MAGIC 0xD
  3. #ifndef GSM_H
  4. typedef unsigned char gsm_byte;
  5. #endif
  6. typedef unsigned char wav_byte;
  7. typedef unsigned int uword;
  8. #define readGSM_33(c1) { \
  9. gsm_byte *c = (c1); \
  10. LARc[0] = (*c++ & 0xF) << 2; /* 1 */ \
  11. LARc[0] |= (*c >> 6) & 0x3; \
  12. LARc[1] = *c++ & 0x3F; \
  13. LARc[2] = (*c >> 3) & 0x1F; \
  14. LARc[3] = (*c++ & 0x7) << 2; \
  15. LARc[3] |= (*c >> 6) & 0x3; \
  16. LARc[4] = (*c >> 2) & 0xF; \
  17. LARc[5] = (*c++ & 0x3) << 2; \
  18. LARc[5] |= (*c >> 6) & 0x3; \
  19. LARc[6] = (*c >> 3) & 0x7; \
  20. LARc[7] = *c++ & 0x7; \
  21. Nc[0] = (*c >> 1) & 0x7F; \
  22. bc[0] = (*c++ & 0x1) << 1; \
  23. bc[0] |= (*c >> 7) & 0x1; \
  24. Mc[0] = (*c >> 5) & 0x3; \
  25. xmaxc[0] = (*c++ & 0x1F) << 1; \
  26. xmaxc[0] |= (*c >> 7) & 0x1; \
  27. xmc[0] = (*c >> 4) & 0x7; \
  28. xmc[1] = (*c >> 1) & 0x7; \
  29. xmc[2] = (*c++ & 0x1) << 2; \
  30. xmc[2] |= (*c >> 6) & 0x3; \
  31. xmc[3] = (*c >> 3) & 0x7; \
  32. xmc[4] = *c++ & 0x7; \
  33. xmc[5] = (*c >> 5) & 0x7; \
  34. xmc[6] = (*c >> 2) & 0x7; \
  35. xmc[7] = (*c++ & 0x3) << 1; /* 10 */ \
  36. xmc[7] |= (*c >> 7) & 0x1; \
  37. xmc[8] = (*c >> 4) & 0x7; \
  38. xmc[9] = (*c >> 1) & 0x7; \
  39. xmc[10] = (*c++ & 0x1) << 2; \
  40. xmc[10] |= (*c >> 6) & 0x3; \
  41. xmc[11] = (*c >> 3) & 0x7; \
  42. xmc[12] = *c++ & 0x7; \
  43. Nc[1] = (*c >> 1) & 0x7F; \
  44. bc[1] = (*c++ & 0x1) << 1; \
  45. bc[1] |= (*c >> 7) & 0x1; \
  46. Mc[1] = (*c >> 5) & 0x3; \
  47. xmaxc[1] = (*c++ & 0x1F) << 1; \
  48. xmaxc[1] |= (*c >> 7) & 0x1; \
  49. xmc[13] = (*c >> 4) & 0x7; \
  50. xmc[14] = (*c >> 1) & 0x7; \
  51. xmc[15] = (*c++ & 0x1) << 2; \
  52. xmc[15] |= (*c >> 6) & 0x3; \
  53. xmc[16] = (*c >> 3) & 0x7; \
  54. xmc[17] = *c++ & 0x7; \
  55. xmc[18] = (*c >> 5) & 0x7; \
  56. xmc[19] = (*c >> 2) & 0x7; \
  57. xmc[20] = (*c++ & 0x3) << 1; \
  58. xmc[20] |= (*c >> 7) & 0x1; \
  59. xmc[21] = (*c >> 4) & 0x7; \
  60. xmc[22] = (*c >> 1) & 0x7; \
  61. xmc[23] = (*c++ & 0x1) << 2; \
  62. xmc[23] |= (*c >> 6) & 0x3; \
  63. xmc[24] = (*c >> 3) & 0x7; \
  64. xmc[25] = *c++ & 0x7; \
  65. Nc[2] = (*c >> 1) & 0x7F; \
  66. bc[2] = (*c++ & 0x1) << 1; /* 20 */ \
  67. bc[2] |= (*c >> 7) & 0x1; \
  68. Mc[2] = (*c >> 5) & 0x3; \
  69. xmaxc[2] = (*c++ & 0x1F) << 1; \
  70. xmaxc[2] |= (*c >> 7) & 0x1; \
  71. xmc[26] = (*c >> 4) & 0x7; \
  72. xmc[27] = (*c >> 1) & 0x7; \
  73. xmc[28] = (*c++ & 0x1) << 2; \
  74. xmc[28] |= (*c >> 6) & 0x3; \
  75. xmc[29] = (*c >> 3) & 0x7; \
  76. xmc[30] = *c++ & 0x7; \
  77. xmc[31] = (*c >> 5) & 0x7; \
  78. xmc[32] = (*c >> 2) & 0x7; \
  79. xmc[33] = (*c++ & 0x3) << 1; \
  80. xmc[33] |= (*c >> 7) & 0x1; \
  81. xmc[34] = (*c >> 4) & 0x7; \
  82. xmc[35] = (*c >> 1) & 0x7; \
  83. xmc[36] = (*c++ & 0x1) << 2; \
  84. xmc[36] |= (*c >> 6) & 0x3; \
  85. xmc[37] = (*c >> 3) & 0x7; \
  86. xmc[38] = *c++ & 0x7; \
  87. Nc[3] = (*c >> 1) & 0x7F; \
  88. bc[3] = (*c++ & 0x1) << 1; \
  89. bc[3] |= (*c >> 7) & 0x1; \
  90. Mc[3] = (*c >> 5) & 0x3; \
  91. xmaxc[3] = (*c++ & 0x1F) << 1; \
  92. xmaxc[3] |= (*c >> 7) & 0x1; \
  93. xmc[39] = (*c >> 4) & 0x7; \
  94. xmc[40] = (*c >> 1) & 0x7; \
  95. xmc[41] = (*c++ & 0x1) << 2; \
  96. xmc[41] |= (*c >> 6) & 0x3; \
  97. xmc[42] = (*c >> 3) & 0x7; \
  98. xmc[43] = *c++ & 0x7; /* 30 */ \
  99. xmc[44] = (*c >> 5) & 0x7; \
  100. xmc[45] = (*c >> 2) & 0x7; \
  101. xmc[46] = (*c++ & 0x3) << 1; \
  102. xmc[46] |= (*c >> 7) & 0x1; \
  103. xmc[47] = (*c >> 4) & 0x7; \
  104. xmc[48] = (*c >> 1) & 0x7; \
  105. xmc[49] = (*c++ & 0x1) << 2; \
  106. xmc[49] |= (*c >> 6) & 0x3; \
  107. xmc[50] = (*c >> 3) & 0x7; \
  108. xmc[51] = *c & 0x7; /* 33 */ \
  109. }
  110. static inline void conv66(gsm_byte * d, wav_byte * c) {
  111. gsm_byte frame_chain;
  112. unsigned int sr;
  113. unsigned int LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
  114. readGSM_33(d);
  115. sr = 0;
  116. sr = (sr >> 6) | (LARc[0] << 10);
  117. sr = (sr >> 6) | (LARc[1] << 10);
  118. *c++ = sr >> 4;
  119. sr = (sr >> 5) | (LARc[2] << 11);
  120. *c++ = sr >> 7;
  121. sr = (sr >> 5) | (LARc[3] << 11);
  122. sr = (sr >> 4) | (LARc[4] << 12);
  123. *c++ = sr >> 6;
  124. sr = (sr >> 4) | (LARc[5] << 12);
  125. sr = (sr >> 3) | (LARc[6] << 13);
  126. *c++ = sr >> 7;
  127. sr = (sr >> 3) | (LARc[7] << 13);
  128. sr = (sr >> 7) | (Nc[0] << 9);
  129. *c++ = sr >> 5;
  130. sr = (sr >> 2) | (bc[0] << 14);
  131. sr = (sr >> 2) | (Mc[0] << 14);
  132. sr = (sr >> 6) | (xmaxc[0] << 10);
  133. *c++ = sr >> 3;
  134. sr = (sr >> 3 )|( xmc[0] << 13);
  135. *c++ = sr >> 8;
  136. sr = (sr >> 3 )|( xmc[1] << 13);
  137. sr = (sr >> 3 )|( xmc[2] << 13);
  138. sr = (sr >> 3 )|( xmc[3] << 13);
  139. *c++ = sr >> 7;
  140. sr = (sr >> 3 )|( xmc[4] << 13);
  141. sr = (sr >> 3 )|( xmc[5] << 13);
  142. sr = (sr >> 3 )|( xmc[6] << 13);
  143. *c++ = sr >> 6;
  144. sr = (sr >> 3 )|( xmc[7] << 13);
  145. sr = (sr >> 3 )|( xmc[8] << 13);
  146. *c++ = sr >> 8;
  147. sr = (sr >> 3 )|( xmc[9] << 13);
  148. sr = (sr >> 3 )|( xmc[10] << 13);
  149. sr = (sr >> 3 )|( xmc[11] << 13);
  150. *c++ = sr >> 7;
  151. sr = (sr >> 3 )|( xmc[12] << 13);
  152. sr = (sr >> 7 )|( Nc[1] << 9);
  153. *c++ = sr >> 5;
  154. sr = (sr >> 2 )|( bc[1] << 14);
  155. sr = (sr >> 2 )|( Mc[1] << 14);
  156. sr = (sr >> 6 )|( xmaxc[1] << 10);
  157. *c++ = sr >> 3;
  158. sr = (sr >> 3 )|( xmc[13] << 13);
  159. *c++ = sr >> 8;
  160. sr = (sr >> 3 )|( xmc[14] << 13);
  161. sr = (sr >> 3 )|( xmc[15] << 13);
  162. sr = (sr >> 3 )|( xmc[16] << 13);
  163. *c++ = sr >> 7;
  164. sr = (sr >> 3 )|( xmc[17] << 13);
  165. sr = (sr >> 3 )|( xmc[18] << 13);
  166. sr = (sr >> 3 )|( xmc[19] << 13);
  167. *c++ = sr >> 6;
  168. sr = (sr >> 3 )|( xmc[20] << 13);
  169. sr = (sr >> 3 )|( xmc[21] << 13);
  170. *c++ = sr >> 8;
  171. sr = (sr >> 3 )|( xmc[22] << 13);
  172. sr = (sr >> 3 )|( xmc[23] << 13);
  173. sr = (sr >> 3 )|( xmc[24] << 13);
  174. *c++ = sr >> 7;
  175. sr = (sr >> 3 )|( xmc[25] << 13);
  176. sr = (sr >> 7 )|( Nc[2] << 9);
  177. *c++ = sr >> 5;
  178. sr = (sr >> 2 )|( bc[2] << 14);
  179. sr = (sr >> 2 )|( Mc[2] << 14);
  180. sr = (sr >> 6 )|( xmaxc[2] << 10);
  181. *c++ = sr >> 3;
  182. sr = (sr >> 3 )|( xmc[26] << 13);
  183. *c++ = sr >> 8;
  184. sr = (sr >> 3 )|( xmc[27] << 13);
  185. sr = (sr >> 3 )|( xmc[28] << 13);
  186. sr = (sr >> 3 )|( xmc[29] << 13);
  187. *c++ = sr >> 7;
  188. sr = (sr >> 3 )|( xmc[30] << 13);
  189. sr = (sr >> 3 )|( xmc[31] << 13);
  190. sr = (sr >> 3 )|( xmc[32] << 13);
  191. *c++ = sr >> 6;
  192. sr = (sr >> 3 )|( xmc[33] << 13);
  193. sr = (sr >> 3 )|( xmc[34] << 13);
  194. *c++ = sr >> 8;
  195. sr = (sr >> 3 )|( xmc[35] << 13);
  196. sr = (sr >> 3 )|( xmc[36] << 13);
  197. sr = (sr >> 3 )|( xmc[37] << 13);
  198. *c++ = sr >> 7;
  199. sr = (sr >> 3 )|( xmc[38] << 13);
  200. sr = (sr >> 7 )|( Nc[3] << 9);
  201. *c++ = sr >> 5;
  202. sr = (sr >> 2 )|( bc[3] << 14);
  203. sr = (sr >> 2 )|( Mc[3] << 14);
  204. sr = (sr >> 6 )|( xmaxc[3] << 10);
  205. *c++ = sr >> 3;
  206. sr = (sr >> 3 )|( xmc[39] << 13);
  207. *c++ = sr >> 8;
  208. sr = (sr >> 3 )|( xmc[40] << 13);
  209. sr = (sr >> 3 )|( xmc[41] << 13);
  210. sr = (sr >> 3 )|( xmc[42] << 13);
  211. *c++ = sr >> 7;
  212. sr = (sr >> 3 )|( xmc[43] << 13);
  213. sr = (sr >> 3 )|( xmc[44] << 13);
  214. sr = (sr >> 3 )|( xmc[45] << 13);
  215. *c++ = sr >> 6;
  216. sr = (sr >> 3 )|( xmc[46] << 13);
  217. sr = (sr >> 3 )|( xmc[47] << 13);
  218. *c++ = sr >> 8;
  219. sr = (sr >> 3 )|( xmc[48] << 13);
  220. sr = (sr >> 3 )|( xmc[49] << 13);
  221. sr = (sr >> 3 )|( xmc[50] << 13);
  222. *c++ = sr >> 7;
  223. sr = (sr >> 3 )|( xmc[51] << 13);
  224. sr = sr >> 4;
  225. *c = sr >> 8;
  226. frame_chain = *c;
  227. readGSM_33(d+33);// puts all the parameters into LARc etc.
  228. sr = 0;
  229. // sr = (sr >> 4 )|( s->frame_chain << 12);
  230. sr = (sr >> 4 )|( frame_chain << 12);
  231. sr = (sr >> 6 )|( LARc[0] << 10);
  232. *c++ = sr >> 6;
  233. sr = (sr >> 6 )|( LARc[1] << 10);
  234. *c++ = sr >> 8;
  235. sr = (sr >> 5 )|( LARc[2] << 11);
  236. sr = (sr >> 5 )|( LARc[3] << 11);
  237. *c++ = sr >> 6;
  238. sr = (sr >> 4 )|( LARc[4] << 12);
  239. sr = (sr >> 4 )|( LARc[5] << 12);
  240. *c++ = sr >> 6;
  241. sr = (sr >> 3 )|( LARc[6] << 13);
  242. sr = (sr >> 3 )|( LARc[7] << 13);
  243. *c++ = sr >> 8;
  244. sr = (sr >> 7 )|( Nc[0] << 9);
  245. sr = (sr >> 2 )|( bc[0] << 14);
  246. *c++ = sr >> 7;
  247. sr = (sr >> 2 )|( Mc[0] << 14);
  248. sr = (sr >> 6 )|( xmaxc[0] << 10);
  249. *c++ = sr >> 7;
  250. sr = (sr >> 3 )|( xmc[0] << 13);
  251. sr = (sr >> 3 )|( xmc[1] << 13);
  252. sr = (sr >> 3 )|( xmc[2] << 13);
  253. *c++ = sr >> 6;
  254. sr = (sr >> 3 )|( xmc[3] << 13);
  255. sr = (sr >> 3 )|( xmc[4] << 13);
  256. *c++ = sr >> 8;
  257. sr = (sr >> 3 )|( xmc[5] << 13);
  258. sr = (sr >> 3 )|( xmc[6] << 13);
  259. sr = (sr >> 3 )|( xmc[7] << 13);
  260. *c++ = sr >> 7;
  261. sr = (sr >> 3 )|( xmc[8] << 13);
  262. sr = (sr >> 3 )|( xmc[9] << 13);
  263. sr = (sr >> 3 )|( xmc[10] << 13);
  264. *c++ = sr >> 6;
  265. sr = (sr >> 3 )|( xmc[11] << 13);
  266. sr = (sr >> 3 )|( xmc[12] << 13);
  267. *c++ = sr >> 8;
  268. sr = (sr >> 7 )|( Nc[1] << 9);
  269. sr = (sr >> 2 )|( bc[1] << 14);
  270. *c++ = sr >> 7;
  271. sr = (sr >> 2 )|( Mc[1] << 14);
  272. sr = (sr >> 6 )|( xmaxc[1] << 10);
  273. *c++ = sr >> 7;
  274. sr = (sr >> 3 )|( xmc[13] << 13);
  275. sr = (sr >> 3 )|( xmc[14] << 13);
  276. sr = (sr >> 3 )|( xmc[15] << 13);
  277. *c++ = sr >> 6;
  278. sr = (sr >> 3 )|( xmc[16] << 13);
  279. sr = (sr >> 3 )|( xmc[17] << 13);
  280. *c++ = sr >> 8;
  281. sr = (sr >> 3 )|( xmc[18] << 13);
  282. sr = (sr >> 3 )|( xmc[19] << 13);
  283. sr = (sr >> 3 )|( xmc[20] << 13);
  284. *c++ = sr >> 7;
  285. sr = (sr >> 3 )|( xmc[21] << 13);
  286. sr = (sr >> 3 )|( xmc[22] << 13);
  287. sr = (sr >> 3 )|( xmc[23] << 13);
  288. *c++ = sr >> 6;
  289. sr = (sr >> 3 )|( xmc[24] << 13);
  290. sr = (sr >> 3 )|( xmc[25] << 13);
  291. *c++ = sr >> 8;
  292. sr = (sr >> 7 )|( Nc[2] << 9);
  293. sr = (sr >> 2 )|( bc[2] << 14);
  294. *c++ = sr >> 7;
  295. sr = (sr >> 2 )|( Mc[2] << 14);
  296. sr = (sr >> 6 )|( xmaxc[2] << 10);
  297. *c++ = sr >> 7;
  298. sr = (sr >> 3 )|( xmc[26] << 13);
  299. sr = (sr >> 3 )|( xmc[27] << 13);
  300. sr = (sr >> 3 )|( xmc[28] << 13);
  301. *c++ = sr >> 6;
  302. sr = (sr >> 3 )|( xmc[29] << 13);
  303. sr = (sr >> 3 )|( xmc[30] << 13);
  304. *c++ = sr >> 8;
  305. sr = (sr >> 3 )|( xmc[31] << 13);
  306. sr = (sr >> 3 )|( xmc[32] << 13);
  307. sr = (sr >> 3 )|( xmc[33] << 13);
  308. *c++ = sr >> 7;
  309. sr = (sr >> 3 )|( xmc[34] << 13);
  310. sr = (sr >> 3 )|( xmc[35] << 13);
  311. sr = (sr >> 3 )|( xmc[36] << 13);
  312. *c++ = sr >> 6;
  313. sr = (sr >> 3 )|( xmc[37] << 13);
  314. sr = (sr >> 3 )|( xmc[38] << 13);
  315. *c++ = sr >> 8;
  316. sr = (sr >> 7 )|( Nc[3] << 9);
  317. sr = (sr >> 2 )|( bc[3] << 14);
  318. *c++ = sr >> 7;
  319. sr = (sr >> 2 )|( Mc[3] << 14);
  320. sr = (sr >> 6 )|( xmaxc[3] << 10);
  321. *c++ = sr >> 7;
  322. sr = (sr >> 3 )|( xmc[39] << 13);
  323. sr = (sr >> 3 )|( xmc[40] << 13);
  324. sr = (sr >> 3 )|( xmc[41] << 13);
  325. *c++ = sr >> 6;
  326. sr = (sr >> 3 )|( xmc[42] << 13);
  327. sr = (sr >> 3 )|( xmc[43] << 13);
  328. *c++ = sr >> 8;
  329. sr = (sr >> 3 )|( xmc[44] << 13);
  330. sr = (sr >> 3 )|( xmc[45] << 13);
  331. sr = (sr >> 3 )|( xmc[46] << 13);
  332. *c++ = sr >> 7;
  333. sr = (sr >> 3 )|( xmc[47] << 13);
  334. sr = (sr >> 3 )|( xmc[48] << 13);
  335. sr = (sr >> 3 )|( xmc[49] << 13);
  336. *c++ = sr >> 6;
  337. sr = (sr >> 3 )|( xmc[50] << 13);
  338. sr = (sr >> 3 )|( xmc[51] << 13);
  339. *c++ = sr >> 8;
  340. }
  341. #define writeGSM_33(c1) { \
  342. gsm_byte *c = (c1); \
  343. *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */ \
  344. | ((LARc[0] >> 2) & 0xF); \
  345. *c++ = ((LARc[0] & 0x3) << 6) \
  346. | (LARc[1] & 0x3F); \
  347. *c++ = ((LARc[2] & 0x1F) << 3) \
  348. | ((LARc[3] >> 2) & 0x7); \
  349. *c++ = ((LARc[3] & 0x3) << 6) \
  350. | ((LARc[4] & 0xF) << 2) \
  351. | ((LARc[5] >> 2) & 0x3); \
  352. *c++ = ((LARc[5] & 0x3) << 6) \
  353. | ((LARc[6] & 0x7) << 3) \
  354. | (LARc[7] & 0x7); \
  355. *c++ = ((Nc[0] & 0x7F) << 1) \
  356. | ((bc[0] >> 1) & 0x1); \
  357. *c++ = ((bc[0] & 0x1) << 7) \
  358. | ((Mc[0] & 0x3) << 5) \
  359. | ((xmaxc[0] >> 1) & 0x1F); \
  360. *c++ = ((xmaxc[0] & 0x1) << 7) \
  361. | ((xmc[0] & 0x7) << 4) \
  362. | ((xmc[1] & 0x7) << 1) \
  363. | ((xmc[2] >> 2) & 0x1); \
  364. *c++ = ((xmc[2] & 0x3) << 6) \
  365. | ((xmc[3] & 0x7) << 3) \
  366. | (xmc[4] & 0x7); \
  367. *c++ = ((xmc[5] & 0x7) << 5) /* 10 */ \
  368. | ((xmc[6] & 0x7) << 2) \
  369. | ((xmc[7] >> 1) & 0x3); \
  370. *c++ = ((xmc[7] & 0x1) << 7) \
  371. | ((xmc[8] & 0x7) << 4) \
  372. | ((xmc[9] & 0x7) << 1) \
  373. | ((xmc[10] >> 2) & 0x1); \
  374. *c++ = ((xmc[10] & 0x3) << 6) \
  375. | ((xmc[11] & 0x7) << 3) \
  376. | (xmc[12] & 0x7); \
  377. *c++ = ((Nc[1] & 0x7F) << 1) \
  378. | ((bc[1] >> 1) & 0x1); \
  379. *c++ = ((bc[1] & 0x1) << 7) \
  380. | ((Mc[1] & 0x3) << 5) \
  381. | ((xmaxc[1] >> 1) & 0x1F); \
  382. *c++ = ((xmaxc[1] & 0x1) << 7) \
  383. | ((xmc[13] & 0x7) << 4) \
  384. | ((xmc[14] & 0x7) << 1) \
  385. | ((xmc[15] >> 2) & 0x1); \
  386. *c++ = ((xmc[15] & 0x3) << 6) \
  387. | ((xmc[16] & 0x7) << 3) \
  388. | (xmc[17] & 0x7); \
  389. *c++ = ((xmc[18] & 0x7) << 5) \
  390. | ((xmc[19] & 0x7) << 2) \
  391. | ((xmc[20] >> 1) & 0x3); \
  392. *c++ = ((xmc[20] & 0x1) << 7) \
  393. | ((xmc[21] & 0x7) << 4) \
  394. | ((xmc[22] & 0x7) << 1) \
  395. | ((xmc[23] >> 2) & 0x1); \
  396. *c++ = ((xmc[23] & 0x3) << 6) \
  397. | ((xmc[24] & 0x7) << 3) \
  398. | (xmc[25] & 0x7); \
  399. *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */ \
  400. | ((bc[2] >> 1) & 0x1); \
  401. *c++ = ((bc[2] & 0x1) << 7) \
  402. | ((Mc[2] & 0x3) << 5) \
  403. | ((xmaxc[2] >> 1) & 0x1F); \
  404. *c++ = ((xmaxc[2] & 0x1) << 7) \
  405. | ((xmc[26] & 0x7) << 4) \
  406. | ((xmc[27] & 0x7) << 1) \
  407. | ((xmc[28] >> 2) & 0x1); \
  408. *c++ = ((xmc[28] & 0x3) << 6) \
  409. | ((xmc[29] & 0x7) << 3) \
  410. | (xmc[30] & 0x7); \
  411. *c++ = ((xmc[31] & 0x7) << 5) \
  412. | ((xmc[32] & 0x7) << 2) \
  413. | ((xmc[33] >> 1) & 0x3); \
  414. *c++ = ((xmc[33] & 0x1) << 7) \
  415. | ((xmc[34] & 0x7) << 4) \
  416. | ((xmc[35] & 0x7) << 1) \
  417. | ((xmc[36] >> 2) & 0x1); \
  418. *c++ = ((xmc[36] & 0x3) << 6) \
  419. | ((xmc[37] & 0x7) << 3) \
  420. | (xmc[38] & 0x7); \
  421. *c++ = ((Nc[3] & 0x7F) << 1) \
  422. | ((bc[3] >> 1) & 0x1); \
  423. *c++ = ((bc[3] & 0x1) << 7) \
  424. | ((Mc[3] & 0x3) << 5) \
  425. | ((xmaxc[3] >> 1) & 0x1F); \
  426. *c++ = ((xmaxc[3] & 0x1) << 7) \
  427. | ((xmc[39] & 0x7) << 4) \
  428. | ((xmc[40] & 0x7) << 1) \
  429. | ((xmc[41] >> 2) & 0x1); \
  430. *c++ = ((xmc[41] & 0x3) << 6) /* 30 */ \
  431. | ((xmc[42] & 0x7) << 3) \
  432. | (xmc[43] & 0x7); \
  433. *c++ = ((xmc[44] & 0x7) << 5) \
  434. | ((xmc[45] & 0x7) << 2) \
  435. | ((xmc[46] >> 1) & 0x3); \
  436. *c++ = ((xmc[46] & 0x1) << 7) \
  437. | ((xmc[47] & 0x7) << 4) \
  438. | ((xmc[48] & 0x7) << 1) \
  439. | ((xmc[49] >> 2) & 0x1); \
  440. *c++ = ((xmc[49] & 0x3) << 6) \
  441. | ((xmc[50] & 0x7) << 3) \
  442. | (xmc[51] & 0x7); \
  443. }
  444. static inline void conv65( wav_byte * c, gsm_byte * d){
  445. unsigned int sr = 0;
  446. unsigned int frame_chain;
  447. unsigned int LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
  448. sr = *c++;
  449. LARc[0] = sr & 0x3f; sr >>= 6;
  450. sr |= (uword)*c++ << 2;
  451. LARc[1] = sr & 0x3f; sr >>= 6;
  452. sr |= (uword)*c++ << 4;
  453. LARc[2] = sr & 0x1f; sr >>= 5;
  454. LARc[3] = sr & 0x1f; sr >>= 5;
  455. sr |= (uword)*c++ << 2;
  456. LARc[4] = sr & 0xf; sr >>= 4;
  457. LARc[5] = sr & 0xf; sr >>= 4;
  458. sr |= (uword)*c++ << 2; /* 5 */
  459. LARc[6] = sr & 0x7; sr >>= 3;
  460. LARc[7] = sr & 0x7; sr >>= 3;
  461. sr |= (uword)*c++ << 4;
  462. Nc[0] = sr & 0x7f; sr >>= 7;
  463. bc[0] = sr & 0x3; sr >>= 2;
  464. Mc[0] = sr & 0x3; sr >>= 2;
  465. sr |= (uword)*c++ << 1;
  466. xmaxc[0] = sr & 0x3f; sr >>= 6;
  467. xmc[0] = sr & 0x7; sr >>= 3;
  468. sr = *c++;
  469. xmc[1] = sr & 0x7; sr >>= 3;
  470. xmc[2] = sr & 0x7; sr >>= 3;
  471. sr |= (uword)*c++ << 2;
  472. xmc[3] = sr & 0x7; sr >>= 3;
  473. xmc[4] = sr & 0x7; sr >>= 3;
  474. xmc[5] = sr & 0x7; sr >>= 3;
  475. sr |= (uword)*c++ << 1; /* 10 */
  476. xmc[6] = sr & 0x7; sr >>= 3;
  477. xmc[7] = sr & 0x7; sr >>= 3;
  478. xmc[8] = sr & 0x7; sr >>= 3;
  479. sr = *c++;
  480. xmc[9] = sr & 0x7; sr >>= 3;
  481. xmc[10] = sr & 0x7; sr >>= 3;
  482. sr |= (uword)*c++ << 2;
  483. xmc[11] = sr & 0x7; sr >>= 3;
  484. xmc[12] = sr & 0x7; sr >>= 3;
  485. sr |= (uword)*c++ << 4;
  486. Nc[1] = sr & 0x7f; sr >>= 7;
  487. bc[1] = sr & 0x3; sr >>= 2;
  488. Mc[1] = sr & 0x3; sr >>= 2;
  489. sr |= (uword)*c++ << 1;
  490. xmaxc[1] = sr & 0x3f; sr >>= 6;
  491. xmc[13] = sr & 0x7; sr >>= 3;
  492. sr = *c++; /* 15 */
  493. xmc[14] = sr & 0x7; sr >>= 3;
  494. xmc[15] = sr & 0x7; sr >>= 3;
  495. sr |= (uword)*c++ << 2;
  496. xmc[16] = sr & 0x7; sr >>= 3;
  497. xmc[17] = sr & 0x7; sr >>= 3;
  498. xmc[18] = sr & 0x7; sr >>= 3;
  499. sr |= (uword)*c++ << 1;
  500. xmc[19] = sr & 0x7; sr >>= 3;
  501. xmc[20] = sr & 0x7; sr >>= 3;
  502. xmc[21] = sr & 0x7; sr >>= 3;
  503. sr = *c++;
  504. xmc[22] = sr & 0x7; sr >>= 3;
  505. xmc[23] = sr & 0x7; sr >>= 3;
  506. sr |= (uword)*c++ << 2;
  507. xmc[24] = sr & 0x7; sr >>= 3;
  508. xmc[25] = sr & 0x7; sr >>= 3;
  509. sr |= (uword)*c++ << 4; /* 20 */
  510. Nc[2] = sr & 0x7f; sr >>= 7;
  511. bc[2] = sr & 0x3; sr >>= 2;
  512. Mc[2] = sr & 0x3; sr >>= 2;
  513. sr |= (uword)*c++ << 1;
  514. xmaxc[2] = sr & 0x3f; sr >>= 6;
  515. xmc[26] = sr & 0x7; sr >>= 3;
  516. sr = *c++;
  517. xmc[27] = sr & 0x7; sr >>= 3;
  518. xmc[28] = sr & 0x7; sr >>= 3;
  519. sr |= (uword)*c++ << 2;
  520. xmc[29] = sr & 0x7; sr >>= 3;
  521. xmc[30] = sr & 0x7; sr >>= 3;
  522. xmc[31] = sr & 0x7; sr >>= 3;
  523. sr |= (uword)*c++ << 1;
  524. xmc[32] = sr & 0x7; sr >>= 3;
  525. xmc[33] = sr & 0x7; sr >>= 3;
  526. xmc[34] = sr & 0x7; sr >>= 3;
  527. sr = *c++; /* 25 */
  528. xmc[35] = sr & 0x7; sr >>= 3;
  529. xmc[36] = sr & 0x7; sr >>= 3;
  530. sr |= (uword)*c++ << 2;
  531. xmc[37] = sr & 0x7; sr >>= 3;
  532. xmc[38] = sr & 0x7; sr >>= 3;
  533. sr |= (uword)*c++ << 4;
  534. Nc[3] = sr & 0x7f; sr >>= 7;
  535. bc[3] = sr & 0x3; sr >>= 2;
  536. Mc[3] = sr & 0x3; sr >>= 2;
  537. sr |= (uword)*c++ << 1;
  538. xmaxc[3] = sr & 0x3f; sr >>= 6;
  539. xmc[39] = sr & 0x7; sr >>= 3;
  540. sr = *c++;
  541. xmc[40] = sr & 0x7; sr >>= 3;
  542. xmc[41] = sr & 0x7; sr >>= 3;
  543. sr |= (uword)*c++ << 2; /* 30 */
  544. xmc[42] = sr & 0x7; sr >>= 3;
  545. xmc[43] = sr & 0x7; sr >>= 3;
  546. xmc[44] = sr & 0x7; sr >>= 3;
  547. sr |= (uword)*c++ << 1;
  548. xmc[45] = sr & 0x7; sr >>= 3;
  549. xmc[46] = sr & 0x7; sr >>= 3;
  550. xmc[47] = sr & 0x7; sr >>= 3;
  551. sr = *c++;
  552. xmc[49] = sr & 0x7; sr >>= 3;
  553. sr |= (uword)*c++ << 2;
  554. xmc[50] = sr & 0x7; sr >>= 3;
  555. xmc[51] = sr & 0x7; sr >>= 3;
  556. frame_chain = sr & 0xf;
  557. writeGSM_33(d);// LARc etc. -> array of 33 GSM bytes
  558. sr = frame_chain;
  559. sr |= (uword)*c++ << 4; /* 1 */
  560. LARc[0] = sr & 0x3f; sr >>= 6;
  561. LARc[1] = sr & 0x3f; sr >>= 6;
  562. sr = *c++;
  563. LARc[2] = sr & 0x1f; sr >>= 5;
  564. sr |= (uword)*c++ << 3;
  565. LARc[3] = sr & 0x1f; sr >>= 5;
  566. LARc[4] = sr & 0xf; sr >>= 4;
  567. sr |= (uword)*c++ << 2;
  568. LARc[5] = sr & 0xf; sr >>= 4;
  569. LARc[6] = sr & 0x7; sr >>= 3;
  570. LARc[7] = sr & 0x7; sr >>= 3;
  571. sr = *c++; /* 5 */
  572. Nc[0] = sr & 0x7f; sr >>= 7;
  573. sr |= (uword)*c++ << 1;
  574. bc[0] = sr & 0x3; sr >>= 2;
  575. Mc[0] = sr & 0x3; sr >>= 2;
  576. sr |= (uword)*c++ << 5;
  577. xmaxc[0] = sr & 0x3f; sr >>= 6;
  578. xmc[0] = sr & 0x7; sr >>= 3;
  579. xmc[1] = sr & 0x7; sr >>= 3;
  580. sr |= (uword)*c++ << 1;
  581. xmc[2] = sr & 0x7; sr >>= 3;
  582. xmc[3] = sr & 0x7; sr >>= 3;
  583. xmc[4] = sr & 0x7; sr >>= 3;
  584. sr = *c++;
  585. xmc[5] = sr & 0x7; sr >>= 3;
  586. xmc[6] = sr & 0x7; sr >>= 3;
  587. sr |= (uword)*c++ << 2; /* 10 */
  588. xmc[7] = sr & 0x7; sr >>= 3;
  589. xmc[8] = sr & 0x7; sr >>= 3;
  590. xmc[9] = sr & 0x7; sr >>= 3;
  591. sr |= (uword)*c++ << 1;
  592. xmc[10] = sr & 0x7; sr >>= 3;
  593. xmc[11] = sr & 0x7; sr >>= 3;
  594. xmc[12] = sr & 0x7; sr >>= 3;
  595. sr = *c++;
  596. Nc[1] = sr & 0x7f; sr >>= 7;
  597. sr |= (uword)*c++ << 1;
  598. bc[1] = sr & 0x3; sr >>= 2;
  599. Mc[1] = sr & 0x3; sr >>= 2;
  600. sr |= (uword)*c++ << 5;
  601. xmaxc[1] = sr & 0x3f; sr >>= 6;
  602. xmc[13] = sr & 0x7; sr >>= 3;
  603. xmc[14] = sr & 0x7; sr >>= 3;
  604. sr |= (uword)*c++ << 1; /* 15 */
  605. xmc[15] = sr & 0x7; sr >>= 3;
  606. xmc[16] = sr & 0x7; sr >>= 3;
  607. xmc[17] = sr & 0x7; sr >>= 3;
  608. sr = *c++;
  609. xmc[18] = sr & 0x7; sr >>= 3;
  610. xmc[19] = sr & 0x7; sr >>= 3;
  611. sr |= (uword)*c++ << 2;
  612. xmc[20] = sr & 0x7; sr >>= 3;
  613. xmc[21] = sr & 0x7; sr >>= 3;
  614. xmc[22] = sr & 0x7; sr >>= 3;
  615. sr |= (uword)*c++ << 1;
  616. xmc[23] = sr & 0x7; sr >>= 3;
  617. xmc[24] = sr & 0x7; sr >>= 3;
  618. xmc[25] = sr & 0x7; sr >>= 3;
  619. sr = *c++;
  620. Nc[2] = sr & 0x7f; sr >>= 7;
  621. sr |= (uword)*c++ << 1; /* 20 */
  622. bc[2] = sr & 0x3; sr >>= 2;
  623. Mc[2] = sr & 0x3; sr >>= 2;
  624. sr |= (uword)*c++ << 5;
  625. xmaxc[2] = sr & 0x3f; sr >>= 6;
  626. xmc[26] = sr & 0x7; sr >>= 3;
  627. xmc[27] = sr & 0x7; sr >>= 3;
  628. sr |= (uword)*c++ << 1;
  629. xmc[28] = sr & 0x7; sr >>= 3;
  630. xmc[29] = sr & 0x7; sr >>= 3;
  631. xmc[30] = sr & 0x7; sr >>= 3;
  632. sr = *c++;
  633. xmc[31] = sr & 0x7; sr >>= 3;
  634. xmc[32] = sr & 0x7; sr >>= 3;
  635. sr |= (uword)*c++ << 2;
  636. xmc[33] = sr & 0x7; sr >>= 3;
  637. xmc[34] = sr & 0x7; sr >>= 3;
  638. xmc[35] = sr & 0x7; sr >>= 3;
  639. sr |= (uword)*c++ << 1; /* 25 */
  640. xmc[36] = sr & 0x7; sr >>= 3;
  641. xmc[37] = sr & 0x7; sr >>= 3;
  642. xmc[38] = sr & 0x7; sr >>= 3;
  643. sr = *c++;
  644. Nc[3] = sr & 0x7f; sr >>= 7;
  645. sr |= (uword)*c++ << 1;
  646. bc[3] = sr & 0x3; sr >>= 2;
  647. Mc[3] = sr & 0x3; sr >>= 2;
  648. sr |= (uword)*c++ << 5;
  649. xmaxc[3] = sr & 0x3f; sr >>= 6;
  650. xmc[39] = sr & 0x7; sr >>= 3;
  651. xmc[40] = sr & 0x7; sr >>= 3;
  652. sr |= (uword)*c++ << 1;
  653. xmc[41] = sr & 0x7; sr >>= 3;
  654. xmc[42] = sr & 0x7; sr >>= 3;
  655. xmc[43] = sr & 0x7; sr >>= 3;
  656. sr = *c++; /* 30 */
  657. xmc[44] = sr & 0x7; sr >>= 3;
  658. xmc[45] = sr & 0x7; sr >>= 3;
  659. sr |= (uword)*c++ << 2;
  660. xmc[46] = sr & 0x7; sr >>= 3;
  661. xmc[47] = sr & 0x7; sr >>= 3;
  662. xmc[48] = sr & 0x7; sr >>= 3;
  663. sr |= (uword)*c++ << 1;
  664. xmc[49] = sr & 0x7; sr >>= 3;
  665. xmc[50] = sr & 0x7; sr >>= 3;
  666. xmc[51] = sr & 0x7; sr >>= 3;
  667. writeGSM_33(d+33);
  668. }