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