5c9e1ab33e09ff76dad15f58b415bcf553a208bf
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.
7 #include "gsm610_priv.h"
10 void gsm_encode (gsm s
, gsm_signal
* source
, gsm_byte
* c
)
12 word LARc
[8], Nc
[4], Mc
[4], bc
[4], xmaxc
[4], xmc
[13*4];
14 Gsm_Coder(s
, source
, LARc
, Nc
, bc
, Mc
, xmaxc
, xmc
);
106 s
->frame_index
= !s
->frame_index
;
107 if (s
->frame_index
) {
112 sr
= sr
>> 6 | LARc
[0] << 10;
113 sr
= sr
>> 6 | LARc
[1] << 10;
115 sr
= sr
>> 5 | LARc
[2] << 11;
117 sr
= sr
>> 5 | LARc
[3] << 11;
118 sr
= sr
>> 4 | LARc
[4] << 12;
120 sr
= sr
>> 4 | LARc
[5] << 12;
121 sr
= sr
>> 3 | LARc
[6] << 13;
123 sr
= sr
>> 3 | LARc
[7] << 13;
124 sr
= sr
>> 7 | Nc
[0] << 9;
126 sr
= sr
>> 2 | bc
[0] << 14;
127 sr
= sr
>> 2 | Mc
[0] << 14;
128 sr
= sr
>> 6 | xmaxc
[0] << 10;
130 sr
= sr
>> 3 | xmc
[0] << 13;
132 sr
= sr
>> 3 | xmc
[1] << 13;
133 sr
= sr
>> 3 | xmc
[2] << 13;
134 sr
= sr
>> 3 | xmc
[3] << 13;
136 sr
= sr
>> 3 | xmc
[4] << 13;
137 sr
= sr
>> 3 | xmc
[5] << 13;
138 sr
= sr
>> 3 | xmc
[6] << 13;
140 sr
= sr
>> 3 | xmc
[7] << 13;
141 sr
= sr
>> 3 | xmc
[8] << 13;
143 sr
= sr
>> 3 | xmc
[9] << 13;
144 sr
= sr
>> 3 | xmc
[10] << 13;
145 sr
= sr
>> 3 | xmc
[11] << 13;
147 sr
= sr
>> 3 | xmc
[12] << 13;
148 sr
= sr
>> 7 | Nc
[1] << 9;
150 sr
= sr
>> 2 | bc
[1] << 14;
151 sr
= sr
>> 2 | Mc
[1] << 14;
152 sr
= sr
>> 6 | xmaxc
[1] << 10;
154 sr
= sr
>> 3 | xmc
[13] << 13;
156 sr
= sr
>> 3 | xmc
[14] << 13;
157 sr
= sr
>> 3 | xmc
[15] << 13;
158 sr
= sr
>> 3 | xmc
[16] << 13;
160 sr
= sr
>> 3 | xmc
[17] << 13;
161 sr
= sr
>> 3 | xmc
[18] << 13;
162 sr
= sr
>> 3 | xmc
[19] << 13;
164 sr
= sr
>> 3 | xmc
[20] << 13;
165 sr
= sr
>> 3 | xmc
[21] << 13;
167 sr
= sr
>> 3 | xmc
[22] << 13;
168 sr
= sr
>> 3 | xmc
[23] << 13;
169 sr
= sr
>> 3 | xmc
[24] << 13;
171 sr
= sr
>> 3 | xmc
[25] << 13;
172 sr
= sr
>> 7 | Nc
[2] << 9;
174 sr
= sr
>> 2 | bc
[2] << 14;
175 sr
= sr
>> 2 | Mc
[2] << 14;
176 sr
= sr
>> 6 | xmaxc
[2] << 10;
178 sr
= sr
>> 3 | xmc
[26] << 13;
180 sr
= sr
>> 3 | xmc
[27] << 13;
181 sr
= sr
>> 3 | xmc
[28] << 13;
182 sr
= sr
>> 3 | xmc
[29] << 13;
184 sr
= sr
>> 3 | xmc
[30] << 13;
185 sr
= sr
>> 3 | xmc
[31] << 13;
186 sr
= sr
>> 3 | xmc
[32] << 13;
188 sr
= sr
>> 3 | xmc
[33] << 13;
189 sr
= sr
>> 3 | xmc
[34] << 13;
191 sr
= sr
>> 3 | xmc
[35] << 13;
192 sr
= sr
>> 3 | xmc
[36] << 13;
193 sr
= sr
>> 3 | xmc
[37] << 13;
195 sr
= sr
>> 3 | xmc
[38] << 13;
196 sr
= sr
>> 7 | Nc
[3] << 9;
198 sr
= sr
>> 2 | bc
[3] << 14;
199 sr
= sr
>> 2 | Mc
[3] << 14;
200 sr
= sr
>> 6 | xmaxc
[3] << 10;
202 sr
= sr
>> 3 | xmc
[39] << 13;
204 sr
= sr
>> 3 | xmc
[40] << 13;
205 sr
= sr
>> 3 | xmc
[41] << 13;
206 sr
= sr
>> 3 | xmc
[42] << 13;
208 sr
= sr
>> 3 | xmc
[43] << 13;
209 sr
= sr
>> 3 | xmc
[44] << 13;
210 sr
= sr
>> 3 | xmc
[45] << 13;
212 sr
= sr
>> 3 | xmc
[46] << 13;
213 sr
= sr
>> 3 | xmc
[47] << 13;
215 sr
= sr
>> 3 | xmc
[48] << 13;
216 sr
= sr
>> 3 | xmc
[49] << 13;
217 sr
= sr
>> 3 | xmc
[50] << 13;
219 sr
= sr
>> 3 | xmc
[51] << 13;
228 sr
= sr
>> 4 | s
->frame_chain
<< 12;
229 sr
= sr
>> 6 | LARc
[0] << 10;
231 sr
= sr
>> 6 | LARc
[1] << 10;
233 sr
= sr
>> 5 | LARc
[2] << 11;
234 sr
= sr
>> 5 | LARc
[3] << 11;
236 sr
= sr
>> 4 | LARc
[4] << 12;
237 sr
= sr
>> 4 | LARc
[5] << 12;
239 sr
= sr
>> 3 | LARc
[6] << 13;
240 sr
= sr
>> 3 | LARc
[7] << 13;
242 sr
= sr
>> 7 | Nc
[0] << 9;
243 sr
= sr
>> 2 | bc
[0] << 14;
245 sr
= sr
>> 2 | Mc
[0] << 14;
246 sr
= sr
>> 6 | xmaxc
[0] << 10;
248 sr
= sr
>> 3 | xmc
[0] << 13;
249 sr
= sr
>> 3 | xmc
[1] << 13;
250 sr
= sr
>> 3 | xmc
[2] << 13;
252 sr
= sr
>> 3 | xmc
[3] << 13;
253 sr
= sr
>> 3 | xmc
[4] << 13;
255 sr
= sr
>> 3 | xmc
[5] << 13;
256 sr
= sr
>> 3 | xmc
[6] << 13;
257 sr
= sr
>> 3 | xmc
[7] << 13;
259 sr
= sr
>> 3 | xmc
[8] << 13;
260 sr
= sr
>> 3 | xmc
[9] << 13;
261 sr
= sr
>> 3 | xmc
[10] << 13;
263 sr
= sr
>> 3 | xmc
[11] << 13;
264 sr
= sr
>> 3 | xmc
[12] << 13;
266 sr
= sr
>> 7 | Nc
[1] << 9;
267 sr
= sr
>> 2 | bc
[1] << 14;
269 sr
= sr
>> 2 | Mc
[1] << 14;
270 sr
= sr
>> 6 | xmaxc
[1] << 10;
272 sr
= sr
>> 3 | xmc
[13] << 13;
273 sr
= sr
>> 3 | xmc
[14] << 13;
274 sr
= sr
>> 3 | xmc
[15] << 13;
276 sr
= sr
>> 3 | xmc
[16] << 13;
277 sr
= sr
>> 3 | xmc
[17] << 13;
279 sr
= sr
>> 3 | xmc
[18] << 13;
280 sr
= sr
>> 3 | xmc
[19] << 13;
281 sr
= sr
>> 3 | xmc
[20] << 13;
283 sr
= sr
>> 3 | xmc
[21] << 13;
284 sr
= sr
>> 3 | xmc
[22] << 13;
285 sr
= sr
>> 3 | xmc
[23] << 13;
287 sr
= sr
>> 3 | xmc
[24] << 13;
288 sr
= sr
>> 3 | xmc
[25] << 13;
290 sr
= sr
>> 7 | Nc
[2] << 9;
291 sr
= sr
>> 2 | bc
[2] << 14;
293 sr
= sr
>> 2 | Mc
[2] << 14;
294 sr
= sr
>> 6 | xmaxc
[2] << 10;
296 sr
= sr
>> 3 | xmc
[26] << 13;
297 sr
= sr
>> 3 | xmc
[27] << 13;
298 sr
= sr
>> 3 | xmc
[28] << 13;
300 sr
= sr
>> 3 | xmc
[29] << 13;
301 sr
= sr
>> 3 | xmc
[30] << 13;
303 sr
= sr
>> 3 | xmc
[31] << 13;
304 sr
= sr
>> 3 | xmc
[32] << 13;
305 sr
= sr
>> 3 | xmc
[33] << 13;
307 sr
= sr
>> 3 | xmc
[34] << 13;
308 sr
= sr
>> 3 | xmc
[35] << 13;
309 sr
= sr
>> 3 | xmc
[36] << 13;
311 sr
= sr
>> 3 | xmc
[37] << 13;
312 sr
= sr
>> 3 | xmc
[38] << 13;
314 sr
= sr
>> 7 | Nc
[3] << 9;
315 sr
= sr
>> 2 | bc
[3] << 14;
317 sr
= sr
>> 2 | Mc
[3] << 14;
318 sr
= sr
>> 6 | xmaxc
[3] << 10;
320 sr
= sr
>> 3 | xmc
[39] << 13;
321 sr
= sr
>> 3 | xmc
[40] << 13;
322 sr
= sr
>> 3 | xmc
[41] << 13;
324 sr
= sr
>> 3 | xmc
[42] << 13;
325 sr
= sr
>> 3 | xmc
[43] << 13;
327 sr
= sr
>> 3 | xmc
[44] << 13;
328 sr
= sr
>> 3 | xmc
[45] << 13;
329 sr
= sr
>> 3 | xmc
[46] << 13;
331 sr
= sr
>> 3 | xmc
[47] << 13;
332 sr
= sr
>> 3 | xmc
[48] << 13;
333 sr
= sr
>> 3 | xmc
[49] << 13;
335 sr
= sr
>> 3 | xmc
[50] << 13;
336 sr
= sr
>> 3 | xmc
[51] << 13;
346 *c
++ = ((GSM_MAGIC
& 0xF) << 4) /* 1 */
347 | ((LARc
[0] >> 2) & 0xF);
348 *c
++ = ((LARc
[0] & 0x3) << 6)
350 *c
++ = ((LARc
[2] & 0x1F) << 3)
351 | ((LARc
[3] >> 2) & 0x7);
352 *c
++ = ((LARc
[3] & 0x3) << 6)
353 | ((LARc
[4] & 0xF) << 2)
354 | ((LARc
[5] >> 2) & 0x3);
355 *c
++ = ((LARc
[5] & 0x3) << 6)
356 | ((LARc
[6] & 0x7) << 3)
358 *c
++ = ((Nc
[0] & 0x7F) << 1)
359 | ((bc
[0] >> 1) & 0x1);
360 *c
++ = ((bc
[0] & 0x1) << 7)
361 | ((Mc
[0] & 0x3) << 5)
362 | ((xmaxc
[0] >> 1) & 0x1F);
363 *c
++ = ((xmaxc
[0] & 0x1) << 7)
364 | ((xmc
[0] & 0x7) << 4)
365 | ((xmc
[1] & 0x7) << 1)
366 | ((xmc
[2] >> 2) & 0x1);
367 *c
++ = ((xmc
[2] & 0x3) << 6)
368 | ((xmc
[3] & 0x7) << 3)
370 *c
++ = ((xmc
[5] & 0x7) << 5) /* 10 */
371 | ((xmc
[6] & 0x7) << 2)
372 | ((xmc
[7] >> 1) & 0x3);
373 *c
++ = ((xmc
[7] & 0x1) << 7)
374 | ((xmc
[8] & 0x7) << 4)
375 | ((xmc
[9] & 0x7) << 1)
376 | ((xmc
[10] >> 2) & 0x1);
377 *c
++ = ((xmc
[10] & 0x3) << 6)
378 | ((xmc
[11] & 0x7) << 3)
380 *c
++ = ((Nc
[1] & 0x7F) << 1)
381 | ((bc
[1] >> 1) & 0x1);
382 *c
++ = ((bc
[1] & 0x1) << 7)
383 | ((Mc
[1] & 0x3) << 5)
384 | ((xmaxc
[1] >> 1) & 0x1F);
385 *c
++ = ((xmaxc
[1] & 0x1) << 7)
386 | ((xmc
[13] & 0x7) << 4)
387 | ((xmc
[14] & 0x7) << 1)
388 | ((xmc
[15] >> 2) & 0x1);
389 *c
++ = ((xmc
[15] & 0x3) << 6)
390 | ((xmc
[16] & 0x7) << 3)
392 *c
++ = ((xmc
[18] & 0x7) << 5)
393 | ((xmc
[19] & 0x7) << 2)
394 | ((xmc
[20] >> 1) & 0x3);
395 *c
++ = ((xmc
[20] & 0x1) << 7)
396 | ((xmc
[21] & 0x7) << 4)
397 | ((xmc
[22] & 0x7) << 1)
398 | ((xmc
[23] >> 2) & 0x1);
399 *c
++ = ((xmc
[23] & 0x3) << 6)
400 | ((xmc
[24] & 0x7) << 3)
402 *c
++ = ((Nc
[2] & 0x7F) << 1) /* 20 */
403 | ((bc
[2] >> 1) & 0x1);
404 *c
++ = ((bc
[2] & 0x1) << 7)
405 | ((Mc
[2] & 0x3) << 5)
406 | ((xmaxc
[2] >> 1) & 0x1F);
407 *c
++ = ((xmaxc
[2] & 0x1) << 7)
408 | ((xmc
[26] & 0x7) << 4)
409 | ((xmc
[27] & 0x7) << 1)
410 | ((xmc
[28] >> 2) & 0x1);
411 *c
++ = ((xmc
[28] & 0x3) << 6)
412 | ((xmc
[29] & 0x7) << 3)
414 *c
++ = ((xmc
[31] & 0x7) << 5)
415 | ((xmc
[32] & 0x7) << 2)
416 | ((xmc
[33] >> 1) & 0x3);
417 *c
++ = ((xmc
[33] & 0x1) << 7)
418 | ((xmc
[34] & 0x7) << 4)
419 | ((xmc
[35] & 0x7) << 1)
420 | ((xmc
[36] >> 2) & 0x1);
421 *c
++ = ((xmc
[36] & 0x3) << 6)
422 | ((xmc
[37] & 0x7) << 3)
424 *c
++ = ((Nc
[3] & 0x7F) << 1)
425 | ((bc
[3] >> 1) & 0x1);
426 *c
++ = ((bc
[3] & 0x1) << 7)
427 | ((Mc
[3] & 0x3) << 5)
428 | ((xmaxc
[3] >> 1) & 0x1F);
429 *c
++ = ((xmaxc
[3] & 0x1) << 7)
430 | ((xmc
[39] & 0x7) << 4)
431 | ((xmc
[40] & 0x7) << 1)
432 | ((xmc
[41] >> 2) & 0x1);
433 *c
++ = ((xmc
[41] & 0x3) << 6) /* 30 */
434 | ((xmc
[42] & 0x7) << 3)
436 *c
++ = ((xmc
[44] & 0x7) << 5)
437 | ((xmc
[45] & 0x7) << 2)
438 | ((xmc
[46] >> 1) & 0x3);
439 *c
++ = ((xmc
[46] & 0x1) << 7)
440 | ((xmc
[47] & 0x7) << 4)
441 | ((xmc
[48] & 0x7) << 1)
442 | ((xmc
[49] >> 2) & 0x1);
443 *c
++ = ((xmc
[49] & 0x3) << 6)
444 | ((xmc
[50] & 0x7) << 3)