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