~singpolyma/asterisk

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

#define GSM_MAGIC 0xD

#ifndef GSM_H
typedef unsigned char           gsm_byte;
#endif
typedef unsigned char           wav_byte;
typedef unsigned int			uword;

#define readGSM_33(c1) { \
		gsm_byte *__c = (c1); \
        LARc[0]  = (*__c++ & 0xF) << 2;           /* 1 */ \
        LARc[0] |= (*__c >> 6) & 0x3; \
        LARc[1]  = *__c++ & 0x3F; \
        LARc[2]  = (*__c >> 3) & 0x1F; \
        LARc[3]  = (*__c++ & 0x7) << 2; \
        LARc[3] |= (*__c >> 6) & 0x3; \
        LARc[4]  = (*__c >> 2) & 0xF; \
        LARc[5]  = (*__c++ & 0x3) << 2; \
        LARc[5] |= (*__c >> 6) & 0x3; \
        LARc[6]  = (*__c >> 3) & 0x7; \
        LARc[7]  = *__c++ & 0x7; \
        Nc[0]  = (*__c >> 1) & 0x7F; \
        bc[0]  = (*__c++ & 0x1) << 1; \
        bc[0] |= (*__c >> 7) & 0x1; \
        Mc[0]  = (*__c >> 5) & 0x3; \
        xmaxc[0]  = (*__c++ & 0x1F) << 1; \
        xmaxc[0] |= (*__c >> 7) & 0x1; \
        xmc[0]  = (*__c >> 4) & 0x7; \
        xmc[1]  = (*__c >> 1) & 0x7; \
        xmc[2]  = (*__c++ & 0x1) << 2; \
        xmc[2] |= (*__c >> 6) & 0x3; \
        xmc[3]  = (*__c >> 3) & 0x7; \
        xmc[4]  = *__c++ & 0x7; \
        xmc[5]  = (*__c >> 5) & 0x7; \
        xmc[6]  = (*__c >> 2) & 0x7; \
        xmc[7]  = (*__c++ & 0x3) << 1;            /* 10 */ \
        xmc[7] |= (*__c >> 7) & 0x1; \
        xmc[8]  = (*__c >> 4) & 0x7; \
        xmc[9]  = (*__c >> 1) & 0x7; \
        xmc[10]  = (*__c++ & 0x1) << 2; \
        xmc[10] |= (*__c >> 6) & 0x3; \
        xmc[11]  = (*__c >> 3) & 0x7; \
        xmc[12]  = *__c++ & 0x7; \
        Nc[1]  = (*__c >> 1) & 0x7F; \
        bc[1]  = (*__c++ & 0x1) << 1; \
        bc[1] |= (*__c >> 7) & 0x1; \
        Mc[1]  = (*__c >> 5) & 0x3; \
        xmaxc[1]  = (*__c++ & 0x1F) << 1; \
        xmaxc[1] |= (*__c >> 7) & 0x1; \
        xmc[13]  = (*__c >> 4) & 0x7; \
        xmc[14]  = (*__c >> 1) & 0x7; \
        xmc[15]  = (*__c++ & 0x1) << 2; \
        xmc[15] |= (*__c >> 6) & 0x3; \
        xmc[16]  = (*__c >> 3) & 0x7; \
        xmc[17]  = *__c++ & 0x7; \
        xmc[18]  = (*__c >> 5) & 0x7; \
        xmc[19]  = (*__c >> 2) & 0x7; \
        xmc[20]  = (*__c++ & 0x3) << 1; \
        xmc[20] |= (*__c >> 7) & 0x1; \
        xmc[21]  = (*__c >> 4) & 0x7; \
        xmc[22]  = (*__c >> 1) & 0x7; \
        xmc[23]  = (*__c++ & 0x1) << 2; \
        xmc[23] |= (*__c >> 6) & 0x3; \
        xmc[24]  = (*__c >> 3) & 0x7; \
        xmc[25]  = *__c++ & 0x7; \
        Nc[2]  = (*__c >> 1) & 0x7F; \
        bc[2]  = (*__c++ & 0x1) << 1;             /* 20 */ \
        bc[2] |= (*__c >> 7) & 0x1; \
        Mc[2]  = (*__c >> 5) & 0x3; \
        xmaxc[2]  = (*__c++ & 0x1F) << 1; \
        xmaxc[2] |= (*__c >> 7) & 0x1; \
        xmc[26]  = (*__c >> 4) & 0x7; \
        xmc[27]  = (*__c >> 1) & 0x7; \
        xmc[28]  = (*__c++ & 0x1) << 2; \
        xmc[28] |= (*__c >> 6) & 0x3; \
        xmc[29]  = (*__c >> 3) & 0x7; \
        xmc[30]  = *__c++ & 0x7; \
        xmc[31]  = (*__c >> 5) & 0x7; \
        xmc[32]  = (*__c >> 2) & 0x7; \
        xmc[33]  = (*__c++ & 0x3) << 1; \
        xmc[33] |= (*__c >> 7) & 0x1; \
        xmc[34]  = (*__c >> 4) & 0x7; \
        xmc[35]  = (*__c >> 1) & 0x7; \
        xmc[36]  = (*__c++ & 0x1) << 2; \
        xmc[36] |= (*__c >> 6) & 0x3; \
        xmc[37]  = (*__c >> 3) & 0x7; \
        xmc[38]  = *__c++ & 0x7; \
        Nc[3]  = (*__c >> 1) & 0x7F; \
        bc[3]  = (*__c++ & 0x1) << 1; \
        bc[3] |= (*__c >> 7) & 0x1; \
        Mc[3]  = (*__c >> 5) & 0x3; \
        xmaxc[3]  = (*__c++ & 0x1F) << 1; \
        xmaxc[3] |= (*__c >> 7) & 0x1; \
        xmc[39]  = (*__c >> 4) & 0x7; \
        xmc[40]  = (*__c >> 1) & 0x7; \
        xmc[41]  = (*__c++ & 0x1) << 2; \
        xmc[41] |= (*__c >> 6) & 0x3; \
        xmc[42]  = (*__c >> 3) & 0x7; \
        xmc[43]  = *__c++ & 0x7;                  /* 30  */ \
        xmc[44]  = (*__c >> 5) & 0x7; \
        xmc[45]  = (*__c >> 2) & 0x7; \
        xmc[46]  = (*__c++ & 0x3) << 1; \
        xmc[46] |= (*__c >> 7) & 0x1; \
        xmc[47]  = (*__c >> 4) & 0x7; \
        xmc[48]  = (*__c >> 1) & 0x7; \
        xmc[49]  = (*__c++ & 0x1) << 2; \
        xmc[49] |= (*__c >> 6) & 0x3; \
        xmc[50]  = (*__c >> 3) & 0x7; \
        xmc[51]  = *__c & 0x7;                    /* 33 */ \
}

static inline void conv66(gsm_byte * d, wav_byte * c) {
	gsm_byte frame_chain;
    unsigned int sr;
	unsigned int    LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];

	readGSM_33(d);
	sr = 0;
	sr = (sr >> 6) | (LARc[0] << 10);
	sr = (sr >> 6) | (LARc[1] << 10);
	*c++ = sr >> 4;
	sr = (sr >> 5) | (LARc[2] << 11);
	*c++ = sr >> 7;
	sr = (sr >> 5) | (LARc[3] << 11);
	sr = (sr >> 4) | (LARc[4] << 12);
	*c++ = sr >> 6;
	sr = (sr >> 4) | (LARc[5] << 12);
	sr = (sr >> 3) | (LARc[6] << 13);
	*c++ = sr >> 7;
	sr = (sr >> 3) | (LARc[7] << 13);
	sr = (sr >> 7) | (Nc[0] << 9);
	*c++ = sr >> 5;
	sr = (sr >> 2) | (bc[0] << 14);
	sr = (sr >> 2) | (Mc[0] << 14);
	sr = (sr >> 6) | (xmaxc[0] << 10);
	*c++ = sr >> 3;
	sr = (sr >> 3 )|( xmc[0] << 13);
	*c++ = sr >> 8;
	sr = (sr >> 3 )|( xmc[1] << 13);
	sr = (sr >> 3 )|( xmc[2] << 13);
    sr = (sr >> 3 )|( xmc[3] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[4] << 13);
    sr = (sr >> 3 )|( xmc[5] << 13);
    sr = (sr >> 3 )|( xmc[6] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[7] << 13);
    sr = (sr >> 3 )|( xmc[8] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[9] << 13);
    sr = (sr >> 3 )|( xmc[10] << 13);
    sr = (sr >> 3 )|( xmc[11] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[12] << 13);
    sr = (sr >> 7 )|( Nc[1] << 9);
    *c++ = sr >> 5;
    sr = (sr >> 2 )|( bc[1] << 14);
    sr = (sr >> 2 )|( Mc[1] << 14);
    sr = (sr >> 6 )|( xmaxc[1] << 10);
    *c++ = sr >> 3;
    sr = (sr >> 3 )|( xmc[13] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[14] << 13);
    sr = (sr >> 3 )|( xmc[15] << 13);
    sr = (sr >> 3 )|( xmc[16] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[17] << 13);
    sr = (sr >> 3 )|( xmc[18] << 13);
    sr = (sr >> 3 )|( xmc[19] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[20] << 13);
    sr = (sr >> 3 )|( xmc[21] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[22] << 13);
    sr = (sr >> 3 )|( xmc[23] << 13);
    sr = (sr >> 3 )|( xmc[24] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[25] << 13);
    sr = (sr >> 7 )|( Nc[2] << 9);
    *c++ = sr >> 5;
    sr = (sr >> 2 )|( bc[2] << 14);
    sr = (sr >> 2 )|( Mc[2] << 14);
    sr = (sr >> 6 )|( xmaxc[2] << 10);
    *c++ = sr >> 3;
    sr = (sr >> 3 )|( xmc[26] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[27] << 13);
    sr = (sr >> 3 )|( xmc[28] << 13);
    sr = (sr >> 3 )|( xmc[29] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[30] << 13);
    sr = (sr >> 3 )|( xmc[31] << 13);
    sr = (sr >> 3 )|( xmc[32] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[33] << 13);
    sr = (sr >> 3 )|( xmc[34] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[35] << 13);
    sr = (sr >> 3 )|( xmc[36] << 13);
    sr = (sr >> 3 )|( xmc[37] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[38] << 13);
    sr = (sr >> 7 )|( Nc[3] << 9);
    *c++ = sr >> 5;
    sr = (sr >> 2 )|( bc[3] << 14);
    sr = (sr >> 2 )|( Mc[3] << 14);
    sr = (sr >> 6 )|( xmaxc[3] << 10);
    *c++ = sr >> 3;
    sr = (sr >> 3 )|( xmc[39] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[40] << 13);
    sr = (sr >> 3 )|( xmc[41] << 13);
    sr = (sr >> 3 )|( xmc[42] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[43] << 13);
    sr = (sr >> 3 )|( xmc[44] << 13);
    sr = (sr >> 3 )|( xmc[45] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[46] << 13);
    sr = (sr >> 3 )|( xmc[47] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[48] << 13);
    sr = (sr >> 3 )|( xmc[49] << 13);
    sr = (sr >> 3 )|( xmc[50] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[51] << 13);
    sr = sr >> 4;
    *c = sr >> 8;
    frame_chain = *c;
    readGSM_33(d+33); /* puts all the parameters into LARc etc. */


    sr = 0;
/*                       sr = (sr >> 4 )|( s->frame_chain << 12); */
    sr = (sr >> 4 )|( frame_chain << 12);

    sr = (sr >> 6 )|( LARc[0] << 10);
    *c++ = sr >> 6;
    sr = (sr >> 6 )|( LARc[1] << 10);
    *c++ = sr >> 8;
    sr = (sr >> 5 )|( LARc[2] << 11);
    sr = (sr >> 5 )|( LARc[3] << 11);
    *c++ = sr >> 6;
    sr = (sr >> 4 )|( LARc[4] << 12);
    sr = (sr >> 4 )|( LARc[5] << 12);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( LARc[6] << 13);
    sr = (sr >> 3 )|( LARc[7] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 7 )|( Nc[0] << 9);
    sr = (sr >> 2 )|( bc[0] << 14);
    *c++ = sr >> 7;
    sr = (sr >> 2 )|( Mc[0] << 14);
    sr = (sr >> 6 )|( xmaxc[0] << 10);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[0] << 13);
    sr = (sr >> 3 )|( xmc[1] << 13);
    sr = (sr >> 3 )|( xmc[2] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[3] << 13);
    sr = (sr >> 3 )|( xmc[4] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[5] << 13);
    sr = (sr >> 3 )|( xmc[6] << 13);
    sr = (sr >> 3 )|( xmc[7] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[8] << 13);
    sr = (sr >> 3 )|( xmc[9] << 13);
    sr = (sr >> 3 )|( xmc[10] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[11] << 13);
    sr = (sr >> 3 )|( xmc[12] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 7 )|( Nc[1] << 9);
    sr = (sr >> 2 )|( bc[1] << 14);
    *c++ = sr >> 7;
    sr = (sr >> 2 )|( Mc[1] << 14);
    sr = (sr >> 6 )|( xmaxc[1] << 10);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[13] << 13);
    sr = (sr >> 3 )|( xmc[14] << 13);
    sr = (sr >> 3 )|( xmc[15] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[16] << 13);
    sr = (sr >> 3 )|( xmc[17] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[18] << 13);
    sr = (sr >> 3 )|( xmc[19] << 13);
    sr = (sr >> 3 )|( xmc[20] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[21] << 13);
    sr = (sr >> 3 )|( xmc[22] << 13);
    sr = (sr >> 3 )|( xmc[23] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[24] << 13);
    sr = (sr >> 3 )|( xmc[25] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 7 )|( Nc[2] << 9);
    sr = (sr >> 2 )|( bc[2] << 14);
    *c++ = sr >> 7;
    sr = (sr >> 2 )|( Mc[2] << 14);
    sr = (sr >> 6 )|( xmaxc[2] << 10);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[26] << 13);
    sr = (sr >> 3 )|( xmc[27] << 13);
    sr = (sr >> 3 )|( xmc[28] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[29] << 13);
    sr = (sr >> 3 )|( xmc[30] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[31] << 13);
    sr = (sr >> 3 )|( xmc[32] << 13);
    sr = (sr >> 3 )|( xmc[33] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[34] << 13);
    sr = (sr >> 3 )|( xmc[35] << 13);
    sr = (sr >> 3 )|( xmc[36] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[37] << 13);
    sr = (sr >> 3 )|( xmc[38] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 7 )|( Nc[3] << 9);
    sr = (sr >> 2 )|( bc[3] << 14);
    *c++ = sr >> 7;
    sr = (sr >> 2 )|( Mc[3] << 14);
    sr = (sr >> 6 )|( xmaxc[3] << 10);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[39] << 13);
    sr = (sr >> 3 )|( xmc[40] << 13);
    sr = (sr >> 3 )|( xmc[41] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[42] << 13);
    sr = (sr >> 3 )|( xmc[43] << 13);
    *c++ = sr >> 8;
    sr = (sr >> 3 )|( xmc[44] << 13);
    sr = (sr >> 3 )|( xmc[45] << 13);
    sr = (sr >> 3 )|( xmc[46] << 13);
    *c++ = sr >> 7;
    sr = (sr >> 3 )|( xmc[47] << 13);
    sr = (sr >> 3 )|( xmc[48] << 13);
    sr = (sr >> 3 )|( xmc[49] << 13);
    *c++ = sr >> 6;
    sr = (sr >> 3 )|( xmc[50] << 13);
    sr = (sr >> 3 )|( xmc[51] << 13);
    *c++ = sr >> 8;

}

#define writeGSM_33(c1) { \
				gsm_byte *__c = (c1); \
                *__c++ =   ((GSM_MAGIC & 0xF) << 4)               /* 1 */ \
                           | ((LARc[0] >> 2) & 0xF); \
                *__c++ =   ((LARc[0] & 0x3) << 6) \
                           | (LARc[1] & 0x3F); \
                *__c++ =   ((LARc[2] & 0x1F) << 3) \
                           | ((LARc[3] >> 2) & 0x7); \
                *__c++ =   ((LARc[3] & 0x3) << 6) \
                       | ((LARc[4] & 0xF) << 2) \
                       | ((LARc[5] >> 2) & 0x3); \
                *__c++ =   ((LARc[5] & 0x3) << 6) \
                       | ((LARc[6] & 0x7) << 3) \
                       | (LARc[7] & 0x7);   \
                *__c++ =   ((Nc[0] & 0x7F) << 1) \
                       | ((bc[0] >> 1) & 0x1); \
                *__c++ =   ((bc[0] & 0x1) << 7) \
                       | ((Mc[0] & 0x3) << 5) \
                       | ((xmaxc[0] >> 1) & 0x1F); \
                *__c++ =   ((xmaxc[0] & 0x1) << 7) \
                       | ((xmc[0] & 0x7) << 4) \
                       | ((xmc[1] & 0x7) << 1) \
                           | ((xmc[2] >> 2) & 0x1); \
                *__c++ =   ((xmc[2] & 0x3) << 6) \
                       | ((xmc[3] & 0x7) << 3) \
                       | (xmc[4] & 0x7); \
                *__c++ =   ((xmc[5] & 0x7) << 5)                  /* 10 */ \
                       | ((xmc[6] & 0x7) << 2) \
                       | ((xmc[7] >> 1) & 0x3); \
                *__c++ =   ((xmc[7] & 0x1) << 7) \
                       | ((xmc[8] & 0x7) << 4) \
                       | ((xmc[9] & 0x7) << 1) \
                       | ((xmc[10] >> 2) & 0x1); \
                *__c++ =   ((xmc[10] & 0x3) << 6) \
                       | ((xmc[11] & 0x7) << 3) \
                       | (xmc[12] & 0x7); \
                *__c++ =   ((Nc[1] & 0x7F) << 1) \
                       | ((bc[1] >> 1) & 0x1); \
                *__c++ =   ((bc[1] & 0x1) << 7) \
                       | ((Mc[1] & 0x3) << 5) \
                       | ((xmaxc[1] >> 1) & 0x1F);  \
                *__c++ =   ((xmaxc[1] & 0x1) << 7) \
                       | ((xmc[13] & 0x7) << 4) \
                           | ((xmc[14] & 0x7) << 1) \
                       | ((xmc[15] >> 2) & 0x1); \
                *__c++ =   ((xmc[15] & 0x3) << 6) \
                       | ((xmc[16] & 0x7) << 3) \
                       | (xmc[17] & 0x7); \
                *__c++ =   ((xmc[18] & 0x7) << 5) \
                       | ((xmc[19] & 0x7) << 2) \
                       | ((xmc[20] >> 1) & 0x3); \
                *__c++ =   ((xmc[20] & 0x1) << 7) \
                       | ((xmc[21] & 0x7) << 4) \
                       | ((xmc[22] & 0x7) << 1) \
                           | ((xmc[23] >> 2) & 0x1); \
                *__c++ =   ((xmc[23] & 0x3) << 6) \
                       | ((xmc[24] & 0x7) << 3) \
                           | (xmc[25] & 0x7); \
                *__c++ =   ((Nc[2] & 0x7F) << 1)                  /* 20 */ \
                       | ((bc[2] >> 1) & 0x1); \
                *__c++ =   ((bc[2] & 0x1) << 7) \
                       | ((Mc[2] & 0x3) << 5) \
                       | ((xmaxc[2] >> 1) & 0x1F); \
                *__c++ =   ((xmaxc[2] & 0x1) << 7)   \
                       | ((xmc[26] & 0x7) << 4) \
                       | ((xmc[27] & 0x7) << 1) \
                       | ((xmc[28] >> 2) & 0x1); \
                *__c++ =   ((xmc[28] & 0x3) << 6) \
                       | ((xmc[29] & 0x7) << 3) \
                       | (xmc[30] & 0x7); \
                *__c++ =   ((xmc[31] & 0x7) << 5) \
                       | ((xmc[32] & 0x7) << 2) \
                       | ((xmc[33] >> 1) & 0x3); \
                *__c++ =   ((xmc[33] & 0x1) << 7) \
                       | ((xmc[34] & 0x7) << 4) \
                       | ((xmc[35] & 0x7) << 1) \
                       | ((xmc[36] >> 2) & 0x1); \
                *__c++ =   ((xmc[36] & 0x3) << 6) \
                           | ((xmc[37] & 0x7) << 3) \
                       | (xmc[38] & 0x7); \
                *__c++ =   ((Nc[3] & 0x7F) << 1) \
                       | ((bc[3] >> 1) & 0x1); \
                *__c++ =   ((bc[3] & 0x1) << 7)  \
                       | ((Mc[3] & 0x3) << 5) \
                       | ((xmaxc[3] >> 1) & 0x1F); \
                *__c++ =   ((xmaxc[3] & 0x1) << 7) \
                       | ((xmc[39] & 0x7) << 4) \
                       | ((xmc[40] & 0x7) << 1) \
                       | ((xmc[41] >> 2) & 0x1); \
                *__c++ =   ((xmc[41] & 0x3) << 6)                 /* 30 */ \
                       | ((xmc[42] & 0x7) << 3) \
                       | (xmc[43] & 0x7); \
                *__c++ =   ((xmc[44] & 0x7) << 5) \
                       | ((xmc[45] & 0x7) << 2) \
                       | ((xmc[46] >> 1) & 0x3); \
                *__c++ =   ((xmc[46] & 0x1) << 7) \
                       | ((xmc[47] & 0x7) << 4) \
                       | ((xmc[48] & 0x7) << 1) \
                       | ((xmc[49] >> 2) & 0x1); \
                *__c++ =   ((xmc[49] & 0x3) << 6) \
                       | ((xmc[50] & 0x7) << 3) \
                           | (xmc[51] & 0x7); \
}

static inline void conv65( wav_byte * c, gsm_byte * d){

                unsigned int sr = 0;
                unsigned int frame_chain;
		unsigned int LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4];
		/* silence bogus compiler warning */
		unsigned int xmc[13*4] = { 0, };

                        sr = *c++;
                        LARc[0] = sr & 0x3f;  sr >>= 6;
                        sr |= (uword)*c++ << 2;
                        LARc[1] = sr & 0x3f;  sr >>= 6;
                        sr |= (uword)*c++ << 4;
                        LARc[2] = sr & 0x1f;  sr >>= 5;
                        LARc[3] = sr & 0x1f;  sr >>= 5;
                        sr |= (uword)*c++ << 2;
                        LARc[4] = sr & 0xf;  sr >>= 4;
                        LARc[5] = sr & 0xf;  sr >>= 4;
                        sr |= (uword)*c++ << 2;                 /* 5 */
                        LARc[6] = sr & 0x7;  sr >>= 3;
                        LARc[7] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 4;
                        Nc[0] = sr & 0x7f;  sr >>= 7;
                        bc[0] = sr & 0x3;  sr >>= 2;
                        Mc[0] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 1;
                        xmaxc[0] = sr & 0x3f;  sr >>= 6;
                        xmc[0] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[1] = sr & 0x7;  sr >>= 3;
                        xmc[2] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[3] = sr & 0x7;  sr >>= 3;
                        xmc[4] = sr & 0x7;  sr >>= 3;
                        xmc[5] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;                 /* 10 */
                        xmc[6] = sr & 0x7;  sr >>= 3;
                        xmc[7] = sr & 0x7;  sr >>= 3;
                        xmc[8] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[9] = sr & 0x7;  sr >>= 3;
                        xmc[10] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[11] = sr & 0x7;  sr >>= 3;
                        xmc[12] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 4;
                        Nc[1] = sr & 0x7f;  sr >>= 7;
                        bc[1] = sr & 0x3;  sr >>= 2;
                        Mc[1] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 1;
                        xmaxc[1] = sr & 0x3f;  sr >>= 6;
                        xmc[13] = sr & 0x7;  sr >>= 3;
                        sr = *c++;                              /* 15 */
                        xmc[14] = sr & 0x7;  sr >>= 3;
                        xmc[15] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[16] = sr & 0x7;  sr >>= 3;
                        xmc[17] = sr & 0x7;  sr >>= 3;
                        xmc[18] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[19] = sr & 0x7;  sr >>= 3;
                        xmc[20] = sr & 0x7;  sr >>= 3;
                        xmc[21] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[22] = sr & 0x7;  sr >>= 3;
                        xmc[23] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[24] = sr & 0x7;  sr >>= 3;
                        xmc[25] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 4;                 /* 20 */
                        Nc[2] = sr & 0x7f;  sr >>= 7;
                        bc[2] = sr & 0x3;  sr >>= 2;
                        Mc[2] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 1;
                        xmaxc[2] = sr & 0x3f;  sr >>= 6;
                        xmc[26] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[27] = sr & 0x7;  sr >>= 3;
                        xmc[28] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[29] = sr & 0x7;  sr >>= 3;
                        xmc[30] = sr & 0x7;  sr >>= 3;
                        xmc[31] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[32] = sr & 0x7;  sr >>= 3;
                        xmc[33] = sr & 0x7;  sr >>= 3;
                        xmc[34] = sr & 0x7;  sr >>= 3;
                        sr = *c++;                              /* 25 */
                        xmc[35] = sr & 0x7;  sr >>= 3;
                        xmc[36] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[37] = sr & 0x7;  sr >>= 3;
                        xmc[38] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 4;
                        Nc[3] = sr & 0x7f;  sr >>= 7;
                        bc[3] = sr & 0x3;  sr >>= 2;
                        Mc[3] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 1;
                        xmaxc[3] = sr & 0x3f;  sr >>= 6;
                        xmc[39] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[40] = sr & 0x7;  sr >>= 3;
                        xmc[41] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;                 /* 30 */
                        xmc[42] = sr & 0x7;  sr >>= 3;
                        xmc[43] = sr & 0x7;  sr >>= 3;
                        xmc[44] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[45] = sr & 0x7;  sr >>= 3;
                        xmc[46] = sr & 0x7;  sr >>= 3;
                        xmc[47] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[49] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[50] = sr & 0x7;  sr >>= 3;
                        xmc[51] = sr & 0x7;  sr >>= 3;

                        frame_chain = sr & 0xf;


                        writeGSM_33(d);/* LARc etc. -> array of 33 GSM bytes */


                        sr = frame_chain;
                        sr |= (uword)*c++ << 4;                 /* 1 */
                        LARc[0] = sr & 0x3f;  sr >>= 6;
                        LARc[1] = sr & 0x3f;  sr >>= 6;
                        sr = *c++;
                        LARc[2] = sr & 0x1f;  sr >>= 5;
                        sr |= (uword)*c++ << 3;
                        LARc[3] = sr & 0x1f;  sr >>= 5;
                        LARc[4] = sr & 0xf;  sr >>= 4;
                        sr |= (uword)*c++ << 2;
                        LARc[5] = sr & 0xf;  sr >>= 4;
                        LARc[6] = sr & 0x7;  sr >>= 3;
                        LARc[7] = sr & 0x7;  sr >>= 3;
                        sr = *c++;                              /* 5 */
                        Nc[0] = sr & 0x7f;  sr >>= 7;
                        sr |= (uword)*c++ << 1;
                        bc[0] = sr & 0x3;  sr >>= 2;
                        Mc[0] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 5;
                        xmaxc[0] = sr & 0x3f;  sr >>= 6;
                        xmc[0] = sr & 0x7;  sr >>= 3;
                        xmc[1] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[2] = sr & 0x7;  sr >>= 3;
                        xmc[3] = sr & 0x7;  sr >>= 3;
                        xmc[4] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[5] = sr & 0x7;  sr >>= 3;
                        xmc[6] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;                 /* 10 */
                        xmc[7] = sr & 0x7;  sr >>= 3;
                        xmc[8] = sr & 0x7;  sr >>= 3;
                        xmc[9] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[10] = sr & 0x7;  sr >>= 3;
                        xmc[11] = sr & 0x7;  sr >>= 3;
                        xmc[12] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        Nc[1] = sr & 0x7f;  sr >>= 7;
                        sr |= (uword)*c++ << 1;
                        bc[1] = sr & 0x3;  sr >>= 2;
                        Mc[1] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 5;
                        xmaxc[1] = sr & 0x3f;  sr >>= 6;
                        xmc[13] = sr & 0x7;  sr >>= 3;
                        xmc[14] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;                 /* 15 */
                        xmc[15] = sr & 0x7;  sr >>= 3;
                        xmc[16] = sr & 0x7;  sr >>= 3;
                        xmc[17] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[18] = sr & 0x7;  sr >>= 3;
                        xmc[19] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[20] = sr & 0x7;  sr >>= 3;
                        xmc[21] = sr & 0x7;  sr >>= 3;
                        xmc[22] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[23] = sr & 0x7;  sr >>= 3;
                        xmc[24] = sr & 0x7;  sr >>= 3;
                        xmc[25] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        Nc[2] = sr & 0x7f;  sr >>= 7;
                        sr |= (uword)*c++ << 1;                 /* 20 */
                        bc[2] = sr & 0x3;  sr >>= 2;
                        Mc[2] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 5;
                        xmaxc[2] = sr & 0x3f;  sr >>= 6;
                        xmc[26] = sr & 0x7;  sr >>= 3;
                        xmc[27] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[28] = sr & 0x7;  sr >>= 3;
                        xmc[29] = sr & 0x7;  sr >>= 3;
                        xmc[30] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        xmc[31] = sr & 0x7;  sr >>= 3;
                        xmc[32] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[33] = sr & 0x7;  sr >>= 3;
                        xmc[34] = sr & 0x7;  sr >>= 3;
                        xmc[35] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;                 /* 25 */
                        xmc[36] = sr & 0x7;  sr >>= 3;
                        xmc[37] = sr & 0x7;  sr >>= 3;
                        xmc[38] = sr & 0x7;  sr >>= 3;
                        sr = *c++;
                        Nc[3] = sr & 0x7f;  sr >>= 7;
                        sr |= (uword)*c++ << 1;
                        bc[3] = sr & 0x3;  sr >>= 2;
                        Mc[3] = sr & 0x3;  sr >>= 2;
                        sr |= (uword)*c++ << 5;
                        xmaxc[3] = sr & 0x3f;  sr >>= 6;
                        xmc[39] = sr & 0x7;  sr >>= 3;
                        xmc[40] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[41] = sr & 0x7;  sr >>= 3;
                        xmc[42] = sr & 0x7;  sr >>= 3;
                        xmc[43] = sr & 0x7;  sr >>= 3;
                        sr = *c++;                              /* 30 */
                        xmc[44] = sr & 0x7;  sr >>= 3;
                        xmc[45] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 2;
                        xmc[46] = sr & 0x7;  sr >>= 3;
                        xmc[47] = sr & 0x7;  sr >>= 3;
                        xmc[48] = sr & 0x7;  sr >>= 3;
                        sr |= (uword)*c++ << 1;
                        xmc[49] = sr & 0x7;  sr >>= 3;
                        xmc[50] = sr & 0x7;  sr >>= 3;
                        xmc[51] = sr & 0x7;  sr >>= 3;
                        writeGSM_33(d+33);

}