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