gsm_implode.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /* $Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/gsm_implode.c,v 1.2 1996/07/02 14:32:43 jutta Exp jutta $ */
  7. #include "private.h"
  8. #include "gsm.h"
  9. #include "proto.h"
  10. void gsm_implode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c)
  11. {
  12. /* variable size index
  13. GSM_MAGIC 4 -
  14. LARc[0] 6 0
  15. LARc[1] 6 1
  16. LARc[2] 5 2
  17. LARc[3] 5 3
  18. LARc[4] 4 4
  19. LARc[5] 4 5
  20. LARc[6] 3 6
  21. LARc[7] 3 7
  22. Nc[0] 7 8
  23. bc[0] 2 9
  24. Mc[0] 2 10
  25. xmaxc[0] 6 11
  26. xmc[0] 3 12
  27. xmc[1] 3 13
  28. xmc[2] 3 14
  29. xmc[3] 3 15
  30. xmc[4] 3 16
  31. xmc[5] 3 17
  32. xmc[6] 3 18
  33. xmc[7] 3 19
  34. xmc[8] 3 20
  35. xmc[9] 3 21
  36. xmc[10] 3 22
  37. xmc[11] 3 23
  38. xmc[12] 3 24
  39. Nc[1] 7 25
  40. bc[1] 2 26
  41. Mc[1] 2 27
  42. xmaxc[1] 6 28
  43. xmc[13] 3 29
  44. xmc[14] 3 30
  45. xmc[15] 3 31
  46. xmc[16] 3 32
  47. xmc[17] 3 33
  48. xmc[18] 3 34
  49. xmc[19] 3 35
  50. xmc[20] 3 36
  51. xmc[21] 3 37
  52. xmc[22] 3 38
  53. xmc[23] 3 39
  54. xmc[24] 3 40
  55. xmc[25] 3 41
  56. Nc[2] 7 42
  57. bc[2] 2 43
  58. Mc[2] 2 44
  59. xmaxc[2] 6 45
  60. xmc[26] 3 46
  61. xmc[27] 3 47
  62. xmc[28] 3 48
  63. xmc[29] 3 49
  64. xmc[30] 3 50
  65. xmc[31] 3 51
  66. xmc[32] 3 52
  67. xmc[33] 3 53
  68. xmc[34] 3 54
  69. xmc[35] 3 55
  70. xmc[36] 3 56
  71. xmc[37] 3 57
  72. xmc[38] 3 58
  73. Nc[3] 7 59
  74. bc[3] 2 60
  75. Mc[3] 2 61
  76. xmaxc[3] 6 62
  77. xmc[39] 3 63
  78. xmc[40] 3 64
  79. xmc[41] 3 65
  80. xmc[42] 3 66
  81. xmc[43] 3 67
  82. xmc[44] 3 68
  83. xmc[45] 3 69
  84. xmc[46] 3 70
  85. xmc[47] 3 71
  86. xmc[48] 3 72
  87. xmc[49] 3 73
  88. xmc[50] 3 74
  89. xmc[51] 3 75
  90. */
  91. /* There are 76 parameters per frame. The first eight are
  92. * unique. The remaining 68 are four identical subframes of
  93. * 17 parameters each. gsm_implode converts from a representation
  94. * of these parameters as values in one array of signed words
  95. * to the "packed" version of a GSM frame.
  96. */
  97. # define LARc source
  98. # define Nc *((gsm_signal (*) [17])(source + 8))
  99. # define bc *((gsm_signal (*) [17])(source + 9))
  100. # define Mc *((gsm_signal (*) [17])(source + 10))
  101. # define xmaxc *((gsm_signal (*) [17])(source + 11))
  102. #ifdef WAV49
  103. if (s->wav_fmt) {
  104. uword sr = 0;
  105. if (s->frame_index) {
  106. sr = sr >> 6 | LARc[0] << 10;
  107. sr = sr >> 6 | LARc[1] << 10;
  108. *c++ = sr >> 4;
  109. sr = sr >> 5 | LARc[2] << 11;
  110. *c++ = sr >> 7;
  111. sr = sr >> 5 | LARc[3] << 11;
  112. sr = sr >> 4 | LARc[4] << 12;
  113. *c++ = sr >> 6;
  114. sr = sr >> 4 | LARc[5] << 12;
  115. sr = sr >> 3 | LARc[6] << 13;
  116. *c++ = sr >> 7;
  117. sr = sr >> 3 | LARc[7] << 13;
  118. sr = sr >> 7 | Nc[0] << 9;
  119. *c++ = sr >> 5;
  120. sr = sr >> 2 | bc[0] << 14;
  121. sr = sr >> 2 | Mc[0] << 14;
  122. sr = sr >> 6 | xmaxc[0] << 10;
  123. *c++ = sr >> 3;
  124. #undef xmc
  125. #define xmc (source + 12)
  126. sr = sr >> 3 | xmc[0] << 13;
  127. *c++ = sr >> 8;
  128. sr = sr >> 3 | xmc[1] << 13;
  129. sr = sr >> 3 | xmc[2] << 13;
  130. sr = sr >> 3 | xmc[3] << 13;
  131. *c++ = sr >> 7;
  132. sr = sr >> 3 | xmc[4] << 13;
  133. sr = sr >> 3 | xmc[5] << 13;
  134. sr = sr >> 3 | xmc[6] << 13;
  135. *c++ = sr >> 6;
  136. sr = sr >> 3 | xmc[7] << 13;
  137. sr = sr >> 3 | xmc[8] << 13;
  138. *c++ = sr >> 8;
  139. sr = sr >> 3 | xmc[9] << 13;
  140. sr = sr >> 3 | xmc[10] << 13;
  141. sr = sr >> 3 | xmc[11] << 13;
  142. *c++ = sr >> 7;
  143. sr = sr >> 3 | xmc[12] << 13;
  144. sr = sr >> 7 | Nc[1] << 9;
  145. *c++ = sr >> 5;
  146. sr = sr >> 2 | bc[1] << 14;
  147. sr = sr >> 2 | Mc[1] << 14;
  148. sr = sr >> 6 | xmaxc[1] << 10;
  149. *c++ = sr >> 3;
  150. #undef xmc
  151. #define xmc (source + 29 - 13)
  152. sr = sr >> 3 | xmc[13] << 13;
  153. *c++ = sr >> 8;
  154. sr = sr >> 3 | xmc[14] << 13;
  155. sr = sr >> 3 | xmc[15] << 13;
  156. sr = sr >> 3 | xmc[16] << 13;
  157. *c++ = sr >> 7;
  158. sr = sr >> 3 | xmc[17] << 13;
  159. sr = sr >> 3 | xmc[18] << 13;
  160. sr = sr >> 3 | xmc[19] << 13;
  161. *c++ = sr >> 6;
  162. sr = sr >> 3 | xmc[20] << 13;
  163. sr = sr >> 3 | xmc[21] << 13;
  164. *c++ = sr >> 8;
  165. sr = sr >> 3 | xmc[22] << 13;
  166. sr = sr >> 3 | xmc[23] << 13;
  167. sr = sr >> 3 | xmc[24] << 13;
  168. *c++ = sr >> 7;
  169. sr = sr >> 3 | xmc[25] << 13;
  170. sr = sr >> 7 | Nc[2] << 9;
  171. *c++ = sr >> 5;
  172. sr = sr >> 2 | bc[2] << 14;
  173. sr = sr >> 2 | Mc[2] << 14;
  174. sr = sr >> 6 | xmaxc[2] << 10;
  175. *c++ = sr >> 3;
  176. #undef xmc
  177. #define xmc (source + 46 - 26)
  178. sr = sr >> 3 | xmc[26] << 13;
  179. *c++ = sr >> 8;
  180. sr = sr >> 3 | xmc[27] << 13;
  181. sr = sr >> 3 | xmc[28] << 13;
  182. sr = sr >> 3 | xmc[29] << 13;
  183. *c++ = sr >> 7;
  184. sr = sr >> 3 | xmc[30] << 13;
  185. sr = sr >> 3 | xmc[31] << 13;
  186. sr = sr >> 3 | xmc[32] << 13;
  187. *c++ = sr >> 6;
  188. sr = sr >> 3 | xmc[33] << 13;
  189. sr = sr >> 3 | xmc[34] << 13;
  190. *c++ = sr >> 8;
  191. sr = sr >> 3 | xmc[35] << 13;
  192. sr = sr >> 3 | xmc[36] << 13;
  193. sr = sr >> 3 | xmc[37] << 13;
  194. *c++ = sr >> 7;
  195. sr = sr >> 3 | xmc[38] << 13;
  196. sr = sr >> 7 | Nc[3] << 9;
  197. *c++ = sr >> 5;
  198. sr = sr >> 2 | bc[3] << 14;
  199. sr = sr >> 2 | Mc[3] << 14;
  200. sr = sr >> 6 | xmaxc[3] << 10;
  201. *c++ = sr >> 3;
  202. #undef xmc
  203. #define xmc (source + 63 - 39)
  204. sr = sr >> 3 | xmc[39] << 13;
  205. *c++ = sr >> 8;
  206. sr = sr >> 3 | xmc[40] << 13;
  207. sr = sr >> 3 | xmc[41] << 13;
  208. sr = sr >> 3 | xmc[42] << 13;
  209. *c++ = sr >> 7;
  210. sr = sr >> 3 | xmc[43] << 13;
  211. sr = sr >> 3 | xmc[44] << 13;
  212. sr = sr >> 3 | xmc[45] << 13;
  213. *c++ = sr >> 6;
  214. sr = sr >> 3 | xmc[46] << 13;
  215. sr = sr >> 3 | xmc[47] << 13;
  216. *c++ = sr >> 8;
  217. sr = sr >> 3 | xmc[48] << 13;
  218. sr = sr >> 3 | xmc[49] << 13;
  219. sr = sr >> 3 | xmc[50] << 13;
  220. *c++ = sr >> 7;
  221. sr = sr >> 3 | xmc[51] << 13;
  222. sr = sr >> 4;
  223. *c = sr >> 8;
  224. s->frame_chain = *c;
  225. }
  226. else {
  227. sr = sr >> 4 | s->frame_chain << 12;
  228. sr = sr >> 6 | LARc[0] << 10;
  229. *c++ = sr >> 6;
  230. sr = sr >> 6 | LARc[1] << 10;
  231. *c++ = sr >> 8;
  232. sr = sr >> 5 | LARc[2] << 11;
  233. sr = sr >> 5 | LARc[3] << 11;
  234. *c++ = sr >> 6;
  235. sr = sr >> 4 | LARc[4] << 12;
  236. sr = sr >> 4 | LARc[5] << 12;
  237. *c++ = sr >> 6;
  238. sr = sr >> 3 | LARc[6] << 13;
  239. sr = sr >> 3 | LARc[7] << 13;
  240. *c++ = sr >> 8;
  241. sr = sr >> 7 | Nc[0] << 9;
  242. sr = sr >> 2 | bc[0] << 14;
  243. *c++ = sr >> 7;
  244. sr = sr >> 2 | Mc[0] << 14;
  245. sr = sr >> 6 | xmaxc[0] << 10;
  246. *c++ = sr >> 7;
  247. #undef xmc
  248. #define xmc (source + 12)
  249. sr = sr >> 3 | xmc[0] << 13;
  250. sr = sr >> 3 | xmc[1] << 13;
  251. sr = sr >> 3 | xmc[2] << 13;
  252. *c++ = sr >> 6;
  253. sr = sr >> 3 | xmc[3] << 13;
  254. sr = sr >> 3 | xmc[4] << 13;
  255. *c++ = sr >> 8;
  256. sr = sr >> 3 | xmc[5] << 13;
  257. sr = sr >> 3 | xmc[6] << 13;
  258. sr = sr >> 3 | xmc[7] << 13;
  259. *c++ = sr >> 7;
  260. sr = sr >> 3 | xmc[8] << 13;
  261. sr = sr >> 3 | xmc[9] << 13;
  262. sr = sr >> 3 | xmc[10] << 13;
  263. *c++ = sr >> 6;
  264. sr = sr >> 3 | xmc[11] << 13;
  265. sr = sr >> 3 | xmc[12] << 13;
  266. *c++ = sr >> 8;
  267. sr = sr >> 7 | Nc[1] << 9;
  268. sr = sr >> 2 | bc[1] << 14;
  269. *c++ = sr >> 7;
  270. sr = sr >> 2 | Mc[1] << 14;
  271. sr = sr >> 6 | xmaxc[1] << 10;
  272. *c++ = sr >> 7;
  273. #undef xmc
  274. #define xmc (source + 29 - 13)
  275. sr = sr >> 3 | xmc[13] << 13;
  276. sr = sr >> 3 | xmc[14] << 13;
  277. sr = sr >> 3 | xmc[15] << 13;
  278. *c++ = sr >> 6;
  279. sr = sr >> 3 | xmc[16] << 13;
  280. sr = sr >> 3 | xmc[17] << 13;
  281. *c++ = sr >> 8;
  282. sr = sr >> 3 | xmc[18] << 13;
  283. sr = sr >> 3 | xmc[19] << 13;
  284. sr = sr >> 3 | xmc[20] << 13;
  285. *c++ = sr >> 7;
  286. sr = sr >> 3 | xmc[21] << 13;
  287. sr = sr >> 3 | xmc[22] << 13;
  288. sr = sr >> 3 | xmc[23] << 13;
  289. *c++ = sr >> 6;
  290. sr = sr >> 3 | xmc[24] << 13;
  291. sr = sr >> 3 | xmc[25] << 13;
  292. *c++ = sr >> 8;
  293. sr = sr >> 7 | Nc[2] << 9;
  294. sr = sr >> 2 | bc[2] << 14;
  295. *c++ = sr >> 7;
  296. sr = sr >> 2 | Mc[2] << 14;
  297. sr = sr >> 6 | xmaxc[2] << 10;
  298. *c++ = sr >> 7;
  299. #undef xmc
  300. #define xmc (source + 46 - 26)
  301. sr = sr >> 3 | xmc[26] << 13;
  302. sr = sr >> 3 | xmc[27] << 13;
  303. sr = sr >> 3 | xmc[28] << 13;
  304. *c++ = sr >> 6;
  305. sr = sr >> 3 | xmc[29] << 13;
  306. sr = sr >> 3 | xmc[30] << 13;
  307. *c++ = sr >> 8;
  308. sr = sr >> 3 | xmc[31] << 13;
  309. sr = sr >> 3 | xmc[32] << 13;
  310. sr = sr >> 3 | xmc[33] << 13;
  311. *c++ = sr >> 7;
  312. sr = sr >> 3 | xmc[34] << 13;
  313. sr = sr >> 3 | xmc[35] << 13;
  314. sr = sr >> 3 | xmc[36] << 13;
  315. *c++ = sr >> 6;
  316. sr = sr >> 3 | xmc[37] << 13;
  317. sr = sr >> 3 | xmc[38] << 13;
  318. *c++ = sr >> 8;
  319. sr = sr >> 7 | Nc[3] << 9;
  320. sr = sr >> 2 | bc[3] << 14;
  321. *c++ = sr >> 7;
  322. sr = sr >> 2 | Mc[3] << 14;
  323. sr = sr >> 6 | xmaxc[3] << 10;
  324. *c++ = sr >> 7;
  325. #undef xmc
  326. #define xmc (source + 63 - 39)
  327. sr = sr >> 3 | xmc[39] << 13;
  328. sr = sr >> 3 | xmc[40] << 13;
  329. sr = sr >> 3 | xmc[41] << 13;
  330. *c++ = sr >> 6;
  331. sr = sr >> 3 | xmc[42] << 13;
  332. sr = sr >> 3 | xmc[43] << 13;
  333. *c++ = sr >> 8;
  334. sr = sr >> 3 | xmc[44] << 13;
  335. sr = sr >> 3 | xmc[45] << 13;
  336. sr = sr >> 3 | xmc[46] << 13;
  337. *c++ = sr >> 7;
  338. sr = sr >> 3 | xmc[47] << 13;
  339. sr = sr >> 3 | xmc[48] << 13;
  340. sr = sr >> 3 | xmc[49] << 13;
  341. *c++ = sr >> 6;
  342. sr = sr >> 3 | xmc[50] << 13;
  343. sr = sr >> 3 | xmc[51] << 13;
  344. *c++ = sr >> 8;
  345. }
  346. }
  347. else
  348. #endif
  349. {
  350. *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */
  351. | ((LARc[0] >> 2) & 0xF);
  352. *c++ = ((LARc[0] & 0x3) << 6)
  353. | (LARc[1] & 0x3F);
  354. *c++ = ((LARc[2] & 0x1F) << 3)
  355. | ((LARc[3] >> 2) & 0x7);
  356. *c++ = ((LARc[3] & 0x3) << 6)
  357. | ((LARc[4] & 0xF) << 2)
  358. | ((LARc[5] >> 2) & 0x3);
  359. *c++ = ((LARc[5] & 0x3) << 6)
  360. | ((LARc[6] & 0x7) << 3)
  361. | (LARc[7] & 0x7);
  362. *c++ = ((Nc[0] & 0x7F) << 1)
  363. | ((bc[0] >> 1) & 0x1);
  364. *c++ = ((bc[0] & 0x1) << 7)
  365. | ((Mc[0] & 0x3) << 5)
  366. | ((xmaxc[0] >> 1) & 0x1F);
  367. *c++ = ((xmaxc[0] & 0x1) << 7)
  368. #undef xmc
  369. #define xmc (source + 12)
  370. | ((xmc[0] & 0x7) << 4)
  371. | ((xmc[1] & 0x7) << 1)
  372. | ((xmc[2] >> 2) & 0x1);
  373. *c++ = ((xmc[2] & 0x3) << 6)
  374. | ((xmc[3] & 0x7) << 3)
  375. | (xmc[4] & 0x7);
  376. *c++ = ((xmc[5] & 0x7) << 5) /* 10 */
  377. | ((xmc[6] & 0x7) << 2)
  378. | ((xmc[7] >> 1) & 0x3);
  379. *c++ = ((xmc[7] & 0x1) << 7)
  380. | ((xmc[8] & 0x7) << 4)
  381. | ((xmc[9] & 0x7) << 1)
  382. | ((xmc[10] >> 2) & 0x1);
  383. *c++ = ((xmc[10] & 0x3) << 6)
  384. | ((xmc[11] & 0x7) << 3)
  385. | (xmc[12] & 0x7);
  386. *c++ = ((Nc[1] & 0x7F) << 1)
  387. | ((bc[1] >> 1) & 0x1);
  388. *c++ = ((bc[1] & 0x1) << 7)
  389. | ((Mc[1] & 0x3) << 5)
  390. | ((xmaxc[1] >> 1) & 0x1F);
  391. *c++ = ((xmaxc[1] & 0x1) << 7)
  392. #undef xmc
  393. #define xmc (source + 29 - 13)
  394. | ((xmc[13] & 0x7) << 4)
  395. | ((xmc[14] & 0x7) << 1)
  396. | ((xmc[15] >> 2) & 0x1);
  397. *c++ = ((xmc[15] & 0x3) << 6)
  398. | ((xmc[16] & 0x7) << 3)
  399. | (xmc[17] & 0x7);
  400. *c++ = ((xmc[18] & 0x7) << 5)
  401. | ((xmc[19] & 0x7) << 2)
  402. | ((xmc[20] >> 1) & 0x3);
  403. *c++ = ((xmc[20] & 0x1) << 7)
  404. | ((xmc[21] & 0x7) << 4)
  405. | ((xmc[22] & 0x7) << 1)
  406. | ((xmc[23] >> 2) & 0x1);
  407. *c++ = ((xmc[23] & 0x3) << 6)
  408. | ((xmc[24] & 0x7) << 3)
  409. | (xmc[25] & 0x7);
  410. *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */
  411. | ((bc[2] >> 1) & 0x1);
  412. *c++ = ((bc[2] & 0x1) << 7)
  413. | ((Mc[2] & 0x3) << 5)
  414. | ((xmaxc[2] >> 1) & 0x1F);
  415. *c++ = ((xmaxc[2] & 0x1) << 7)
  416. #undef xmc
  417. #define xmc (source + 46 - 26)
  418. | ((xmc[26] & 0x7) << 4)
  419. | ((xmc[27] & 0x7) << 1)
  420. | ((xmc[28] >> 2) & 0x1);
  421. *c++ = ((xmc[28] & 0x3) << 6)
  422. | ((xmc[29] & 0x7) << 3)
  423. | (xmc[30] & 0x7);
  424. *c++ = ((xmc[31] & 0x7) << 5)
  425. | ((xmc[32] & 0x7) << 2)
  426. | ((xmc[33] >> 1) & 0x3);
  427. *c++ = ((xmc[33] & 0x1) << 7)
  428. | ((xmc[34] & 0x7) << 4)
  429. | ((xmc[35] & 0x7) << 1)
  430. | ((xmc[36] >> 2) & 0x1);
  431. *c++ = ((xmc[36] & 0x3) << 6)
  432. | ((xmc[37] & 0x7) << 3)
  433. | (xmc[38] & 0x7);
  434. *c++ = ((Nc[3] & 0x7F) << 1)
  435. | ((bc[3] >> 1) & 0x1);
  436. *c++ = ((bc[3] & 0x1) << 7)
  437. | ((Mc[3] & 0x3) << 5)
  438. | ((xmaxc[3] >> 1) & 0x1F);
  439. *c++ = ((xmaxc[3] & 0x1) << 7)
  440. #undef xmc
  441. #define xmc (source + 63 - 39)
  442. | ((xmc[39] & 0x7) << 4)
  443. | ((xmc[40] & 0x7) << 1)
  444. | ((xmc[41] >> 2) & 0x1);
  445. *c++ = ((xmc[41] & 0x3) << 6) /* 30 */
  446. | ((xmc[42] & 0x7) << 3)
  447. | (xmc[43] & 0x7);
  448. *c++ = ((xmc[44] & 0x7) << 5)
  449. | ((xmc[45] & 0x7) << 2)
  450. | ((xmc[46] >> 1) & 0x3);
  451. *c++ = ((xmc[46] & 0x1) << 7)
  452. | ((xmc[47] & 0x7) << 4)
  453. | ((xmc[48] & 0x7) << 1)
  454. | ((xmc[49] >> 2) & 0x1);
  455. *c++ = ((xmc[49] & 0x3) << 6)
  456. | ((xmc[50] & 0x7) << 3)
  457. | (xmc[51] & 0x7);
  458. }
  459. }