msgsm.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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];
  448. /* silence bogus compiler warning */
  449. unsigned int xmc[13*4] = { 0, };
  450. sr = *c++;
  451. LARc[0] = sr & 0x3f; sr >>= 6;
  452. sr |= (uword)*c++ << 2;
  453. LARc[1] = sr & 0x3f; sr >>= 6;
  454. sr |= (uword)*c++ << 4;
  455. LARc[2] = sr & 0x1f; sr >>= 5;
  456. LARc[3] = sr & 0x1f; sr >>= 5;
  457. sr |= (uword)*c++ << 2;
  458. LARc[4] = sr & 0xf; sr >>= 4;
  459. LARc[5] = sr & 0xf; sr >>= 4;
  460. sr |= (uword)*c++ << 2; /* 5 */
  461. LARc[6] = sr & 0x7; sr >>= 3;
  462. LARc[7] = sr & 0x7; sr >>= 3;
  463. sr |= (uword)*c++ << 4;
  464. Nc[0] = sr & 0x7f; sr >>= 7;
  465. bc[0] = sr & 0x3; sr >>= 2;
  466. Mc[0] = sr & 0x3; sr >>= 2;
  467. sr |= (uword)*c++ << 1;
  468. xmaxc[0] = sr & 0x3f; sr >>= 6;
  469. xmc[0] = sr & 0x7; sr >>= 3;
  470. sr = *c++;
  471. xmc[1] = sr & 0x7; sr >>= 3;
  472. xmc[2] = sr & 0x7; sr >>= 3;
  473. sr |= (uword)*c++ << 2;
  474. xmc[3] = sr & 0x7; sr >>= 3;
  475. xmc[4] = sr & 0x7; sr >>= 3;
  476. xmc[5] = sr & 0x7; sr >>= 3;
  477. sr |= (uword)*c++ << 1; /* 10 */
  478. xmc[6] = sr & 0x7; sr >>= 3;
  479. xmc[7] = sr & 0x7; sr >>= 3;
  480. xmc[8] = sr & 0x7; sr >>= 3;
  481. sr = *c++;
  482. xmc[9] = sr & 0x7; sr >>= 3;
  483. xmc[10] = sr & 0x7; sr >>= 3;
  484. sr |= (uword)*c++ << 2;
  485. xmc[11] = sr & 0x7; sr >>= 3;
  486. xmc[12] = sr & 0x7; sr >>= 3;
  487. sr |= (uword)*c++ << 4;
  488. Nc[1] = sr & 0x7f; sr >>= 7;
  489. bc[1] = sr & 0x3; sr >>= 2;
  490. Mc[1] = sr & 0x3; sr >>= 2;
  491. sr |= (uword)*c++ << 1;
  492. xmaxc[1] = sr & 0x3f; sr >>= 6;
  493. xmc[13] = sr & 0x7; sr >>= 3;
  494. sr = *c++; /* 15 */
  495. xmc[14] = sr & 0x7; sr >>= 3;
  496. xmc[15] = sr & 0x7; sr >>= 3;
  497. sr |= (uword)*c++ << 2;
  498. xmc[16] = sr & 0x7; sr >>= 3;
  499. xmc[17] = sr & 0x7; sr >>= 3;
  500. xmc[18] = sr & 0x7; sr >>= 3;
  501. sr |= (uword)*c++ << 1;
  502. xmc[19] = sr & 0x7; sr >>= 3;
  503. xmc[20] = sr & 0x7; sr >>= 3;
  504. xmc[21] = sr & 0x7; sr >>= 3;
  505. sr = *c++;
  506. xmc[22] = sr & 0x7; sr >>= 3;
  507. xmc[23] = sr & 0x7; sr >>= 3;
  508. sr |= (uword)*c++ << 2;
  509. xmc[24] = sr & 0x7; sr >>= 3;
  510. xmc[25] = sr & 0x7; sr >>= 3;
  511. sr |= (uword)*c++ << 4; /* 20 */
  512. Nc[2] = sr & 0x7f; sr >>= 7;
  513. bc[2] = sr & 0x3; sr >>= 2;
  514. Mc[2] = sr & 0x3; sr >>= 2;
  515. sr |= (uword)*c++ << 1;
  516. xmaxc[2] = sr & 0x3f; sr >>= 6;
  517. xmc[26] = sr & 0x7; sr >>= 3;
  518. sr = *c++;
  519. xmc[27] = sr & 0x7; sr >>= 3;
  520. xmc[28] = sr & 0x7; sr >>= 3;
  521. sr |= (uword)*c++ << 2;
  522. xmc[29] = sr & 0x7; sr >>= 3;
  523. xmc[30] = sr & 0x7; sr >>= 3;
  524. xmc[31] = sr & 0x7; sr >>= 3;
  525. sr |= (uword)*c++ << 1;
  526. xmc[32] = sr & 0x7; sr >>= 3;
  527. xmc[33] = sr & 0x7; sr >>= 3;
  528. xmc[34] = sr & 0x7; sr >>= 3;
  529. sr = *c++; /* 25 */
  530. xmc[35] = sr & 0x7; sr >>= 3;
  531. xmc[36] = sr & 0x7; sr >>= 3;
  532. sr |= (uword)*c++ << 2;
  533. xmc[37] = sr & 0x7; sr >>= 3;
  534. xmc[38] = sr & 0x7; sr >>= 3;
  535. sr |= (uword)*c++ << 4;
  536. Nc[3] = sr & 0x7f; sr >>= 7;
  537. bc[3] = sr & 0x3; sr >>= 2;
  538. Mc[3] = sr & 0x3; sr >>= 2;
  539. sr |= (uword)*c++ << 1;
  540. xmaxc[3] = sr & 0x3f; sr >>= 6;
  541. xmc[39] = sr & 0x7; sr >>= 3;
  542. sr = *c++;
  543. xmc[40] = sr & 0x7; sr >>= 3;
  544. xmc[41] = sr & 0x7; sr >>= 3;
  545. sr |= (uword)*c++ << 2; /* 30 */
  546. xmc[42] = sr & 0x7; sr >>= 3;
  547. xmc[43] = sr & 0x7; sr >>= 3;
  548. xmc[44] = sr & 0x7; sr >>= 3;
  549. sr |= (uword)*c++ << 1;
  550. xmc[45] = sr & 0x7; sr >>= 3;
  551. xmc[46] = sr & 0x7; sr >>= 3;
  552. xmc[47] = sr & 0x7; sr >>= 3;
  553. sr = *c++;
  554. xmc[49] = sr & 0x7; sr >>= 3;
  555. sr |= (uword)*c++ << 2;
  556. xmc[50] = sr & 0x7; sr >>= 3;
  557. xmc[51] = sr & 0x7; sr >>= 3;
  558. frame_chain = sr & 0xf;
  559. writeGSM_33(d);/* LARc etc. -> array of 33 GSM bytes */
  560. sr = frame_chain;
  561. sr |= (uword)*c++ << 4; /* 1 */
  562. LARc[0] = sr & 0x3f; sr >>= 6;
  563. LARc[1] = sr & 0x3f; sr >>= 6;
  564. sr = *c++;
  565. LARc[2] = sr & 0x1f; sr >>= 5;
  566. sr |= (uword)*c++ << 3;
  567. LARc[3] = sr & 0x1f; sr >>= 5;
  568. LARc[4] = sr & 0xf; sr >>= 4;
  569. sr |= (uword)*c++ << 2;
  570. LARc[5] = sr & 0xf; sr >>= 4;
  571. LARc[6] = sr & 0x7; sr >>= 3;
  572. LARc[7] = sr & 0x7; sr >>= 3;
  573. sr = *c++; /* 5 */
  574. Nc[0] = sr & 0x7f; sr >>= 7;
  575. sr |= (uword)*c++ << 1;
  576. bc[0] = sr & 0x3; sr >>= 2;
  577. Mc[0] = sr & 0x3; sr >>= 2;
  578. sr |= (uword)*c++ << 5;
  579. xmaxc[0] = sr & 0x3f; sr >>= 6;
  580. xmc[0] = sr & 0x7; sr >>= 3;
  581. xmc[1] = sr & 0x7; sr >>= 3;
  582. sr |= (uword)*c++ << 1;
  583. xmc[2] = sr & 0x7; sr >>= 3;
  584. xmc[3] = sr & 0x7; sr >>= 3;
  585. xmc[4] = sr & 0x7; sr >>= 3;
  586. sr = *c++;
  587. xmc[5] = sr & 0x7; sr >>= 3;
  588. xmc[6] = sr & 0x7; sr >>= 3;
  589. sr |= (uword)*c++ << 2; /* 10 */
  590. xmc[7] = sr & 0x7; sr >>= 3;
  591. xmc[8] = sr & 0x7; sr >>= 3;
  592. xmc[9] = sr & 0x7; sr >>= 3;
  593. sr |= (uword)*c++ << 1;
  594. xmc[10] = sr & 0x7; sr >>= 3;
  595. xmc[11] = sr & 0x7; sr >>= 3;
  596. xmc[12] = sr & 0x7; sr >>= 3;
  597. sr = *c++;
  598. Nc[1] = sr & 0x7f; sr >>= 7;
  599. sr |= (uword)*c++ << 1;
  600. bc[1] = sr & 0x3; sr >>= 2;
  601. Mc[1] = sr & 0x3; sr >>= 2;
  602. sr |= (uword)*c++ << 5;
  603. xmaxc[1] = sr & 0x3f; sr >>= 6;
  604. xmc[13] = sr & 0x7; sr >>= 3;
  605. xmc[14] = sr & 0x7; sr >>= 3;
  606. sr |= (uword)*c++ << 1; /* 15 */
  607. xmc[15] = sr & 0x7; sr >>= 3;
  608. xmc[16] = sr & 0x7; sr >>= 3;
  609. xmc[17] = sr & 0x7; sr >>= 3;
  610. sr = *c++;
  611. xmc[18] = sr & 0x7; sr >>= 3;
  612. xmc[19] = sr & 0x7; sr >>= 3;
  613. sr |= (uword)*c++ << 2;
  614. xmc[20] = sr & 0x7; sr >>= 3;
  615. xmc[21] = sr & 0x7; sr >>= 3;
  616. xmc[22] = sr & 0x7; sr >>= 3;
  617. sr |= (uword)*c++ << 1;
  618. xmc[23] = sr & 0x7; sr >>= 3;
  619. xmc[24] = sr & 0x7; sr >>= 3;
  620. xmc[25] = sr & 0x7; sr >>= 3;
  621. sr = *c++;
  622. Nc[2] = sr & 0x7f; sr >>= 7;
  623. sr |= (uword)*c++ << 1; /* 20 */
  624. bc[2] = sr & 0x3; sr >>= 2;
  625. Mc[2] = sr & 0x3; sr >>= 2;
  626. sr |= (uword)*c++ << 5;
  627. xmaxc[2] = sr & 0x3f; sr >>= 6;
  628. xmc[26] = sr & 0x7; sr >>= 3;
  629. xmc[27] = sr & 0x7; sr >>= 3;
  630. sr |= (uword)*c++ << 1;
  631. xmc[28] = sr & 0x7; sr >>= 3;
  632. xmc[29] = sr & 0x7; sr >>= 3;
  633. xmc[30] = sr & 0x7; sr >>= 3;
  634. sr = *c++;
  635. xmc[31] = sr & 0x7; sr >>= 3;
  636. xmc[32] = sr & 0x7; sr >>= 3;
  637. sr |= (uword)*c++ << 2;
  638. xmc[33] = sr & 0x7; sr >>= 3;
  639. xmc[34] = sr & 0x7; sr >>= 3;
  640. xmc[35] = sr & 0x7; sr >>= 3;
  641. sr |= (uword)*c++ << 1; /* 25 */
  642. xmc[36] = sr & 0x7; sr >>= 3;
  643. xmc[37] = sr & 0x7; sr >>= 3;
  644. xmc[38] = sr & 0x7; sr >>= 3;
  645. sr = *c++;
  646. Nc[3] = sr & 0x7f; sr >>= 7;
  647. sr |= (uword)*c++ << 1;
  648. bc[3] = sr & 0x3; sr >>= 2;
  649. Mc[3] = sr & 0x3; sr >>= 2;
  650. sr |= (uword)*c++ << 5;
  651. xmaxc[3] = sr & 0x3f; sr >>= 6;
  652. xmc[39] = sr & 0x7; sr >>= 3;
  653. xmc[40] = sr & 0x7; sr >>= 3;
  654. sr |= (uword)*c++ << 1;
  655. xmc[41] = sr & 0x7; sr >>= 3;
  656. xmc[42] = sr & 0x7; sr >>= 3;
  657. xmc[43] = sr & 0x7; sr >>= 3;
  658. sr = *c++; /* 30 */
  659. xmc[44] = sr & 0x7; sr >>= 3;
  660. xmc[45] = sr & 0x7; sr >>= 3;
  661. sr |= (uword)*c++ << 2;
  662. xmc[46] = sr & 0x7; sr >>= 3;
  663. xmc[47] = sr & 0x7; sr >>= 3;
  664. xmc[48] = sr & 0x7; sr >>= 3;
  665. sr |= (uword)*c++ << 1;
  666. xmc[49] = sr & 0x7; sr >>= 3;
  667. xmc[50] = sr & 0x7; sr >>= 3;
  668. xmc[51] = sr & 0x7; sr >>= 3;
  669. writeGSM_33(d+33);
  670. }