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