5c9e1ab33e09ff76dad15f58b415bcf553a208bf
[Faustine.git] / interpretor / lib / src / libsndfile-1.0.25 / src / GSM610 / gsm_encode.c
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
10 void gsm_encode (gsm s, gsm_signal * source, gsm_byte * c)
11 {
12 word 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
109 uword sr;
110
111 sr = 0;
112 sr = sr >> 6 | LARc[0] << 10;
113 sr = sr >> 6 | LARc[1] << 10;
114 *c++ = sr >> 4;
115 sr = sr >> 5 | LARc[2] << 11;
116 *c++ = sr >> 7;
117 sr = sr >> 5 | LARc[3] << 11;
118 sr = sr >> 4 | LARc[4] << 12;
119 *c++ = sr >> 6;
120 sr = sr >> 4 | LARc[5] << 12;
121 sr = sr >> 3 | LARc[6] << 13;
122 *c++ = sr >> 7;
123 sr = sr >> 3 | LARc[7] << 13;
124 sr = sr >> 7 | Nc[0] << 9;
125 *c++ = sr >> 5;
126 sr = sr >> 2 | bc[0] << 14;
127 sr = sr >> 2 | Mc[0] << 14;
128 sr = sr >> 6 | xmaxc[0] << 10;
129 *c++ = sr >> 3;
130 sr = sr >> 3 | xmc[0] << 13;
131 *c++ = sr >> 8;
132 sr = sr >> 3 | xmc[1] << 13;
133 sr = sr >> 3 | xmc[2] << 13;
134 sr = sr >> 3 | xmc[3] << 13;
135 *c++ = sr >> 7;
136 sr = sr >> 3 | xmc[4] << 13;
137 sr = sr >> 3 | xmc[5] << 13;
138 sr = sr >> 3 | xmc[6] << 13;
139 *c++ = sr >> 6;
140 sr = sr >> 3 | xmc[7] << 13;
141 sr = sr >> 3 | xmc[8] << 13;
142 *c++ = sr >> 8;
143 sr = sr >> 3 | xmc[9] << 13;
144 sr = sr >> 3 | xmc[10] << 13;
145 sr = sr >> 3 | xmc[11] << 13;
146 *c++ = sr >> 7;
147 sr = sr >> 3 | xmc[12] << 13;
148 sr = sr >> 7 | Nc[1] << 9;
149 *c++ = sr >> 5;
150 sr = sr >> 2 | bc[1] << 14;
151 sr = sr >> 2 | Mc[1] << 14;
152 sr = sr >> 6 | xmaxc[1] << 10;
153 *c++ = sr >> 3;
154 sr = sr >> 3 | xmc[13] << 13;
155 *c++ = sr >> 8;
156 sr = sr >> 3 | xmc[14] << 13;
157 sr = sr >> 3 | xmc[15] << 13;
158 sr = sr >> 3 | xmc[16] << 13;
159 *c++ = sr >> 7;
160 sr = sr >> 3 | xmc[17] << 13;
161 sr = sr >> 3 | xmc[18] << 13;
162 sr = sr >> 3 | xmc[19] << 13;
163 *c++ = sr >> 6;
164 sr = sr >> 3 | xmc[20] << 13;
165 sr = sr >> 3 | xmc[21] << 13;
166 *c++ = sr >> 8;
167 sr = sr >> 3 | xmc[22] << 13;
168 sr = sr >> 3 | xmc[23] << 13;
169 sr = sr >> 3 | xmc[24] << 13;
170 *c++ = sr >> 7;
171 sr = sr >> 3 | xmc[25] << 13;
172 sr = sr >> 7 | Nc[2] << 9;
173 *c++ = sr >> 5;
174 sr = sr >> 2 | bc[2] << 14;
175 sr = sr >> 2 | Mc[2] << 14;
176 sr = sr >> 6 | xmaxc[2] << 10;
177 *c++ = sr >> 3;
178 sr = sr >> 3 | xmc[26] << 13;
179 *c++ = sr >> 8;
180 sr = sr >> 3 | xmc[27] << 13;
181 sr = sr >> 3 | xmc[28] << 13;
182 sr = sr >> 3 | xmc[29] << 13;
183 *c++ = sr >> 7;
184 sr = sr >> 3 | xmc[30] << 13;
185 sr = sr >> 3 | xmc[31] << 13;
186 sr = sr >> 3 | xmc[32] << 13;
187 *c++ = sr >> 6;
188 sr = sr >> 3 | xmc[33] << 13;
189 sr = sr >> 3 | xmc[34] << 13;
190 *c++ = sr >> 8;
191 sr = sr >> 3 | xmc[35] << 13;
192 sr = sr >> 3 | xmc[36] << 13;
193 sr = sr >> 3 | xmc[37] << 13;
194 *c++ = sr >> 7;
195 sr = sr >> 3 | xmc[38] << 13;
196 sr = sr >> 7 | Nc[3] << 9;
197 *c++ = sr >> 5;
198 sr = sr >> 2 | bc[3] << 14;
199 sr = sr >> 2 | Mc[3] << 14;
200 sr = sr >> 6 | xmaxc[3] << 10;
201 *c++ = sr >> 3;
202 sr = sr >> 3 | xmc[39] << 13;
203 *c++ = sr >> 8;
204 sr = sr >> 3 | xmc[40] << 13;
205 sr = sr >> 3 | xmc[41] << 13;
206 sr = sr >> 3 | xmc[42] << 13;
207 *c++ = sr >> 7;
208 sr = sr >> 3 | xmc[43] << 13;
209 sr = sr >> 3 | xmc[44] << 13;
210 sr = sr >> 3 | xmc[45] << 13;
211 *c++ = sr >> 6;
212 sr = sr >> 3 | xmc[46] << 13;
213 sr = sr >> 3 | xmc[47] << 13;
214 *c++ = sr >> 8;
215 sr = sr >> 3 | xmc[48] << 13;
216 sr = sr >> 3 | xmc[49] << 13;
217 sr = sr >> 3 | xmc[50] << 13;
218 *c++ = sr >> 7;
219 sr = sr >> 3 | xmc[51] << 13;
220 sr = sr >> 4;
221 *c = sr >> 8;
222 s->frame_chain = *c;
223 }
224 else {
225 uword sr;
226
227 sr = 0;
228 sr = sr >> 4 | s->frame_chain << 12;
229 sr = sr >> 6 | LARc[0] << 10;
230 *c++ = sr >> 6;
231 sr = sr >> 6 | LARc[1] << 10;
232 *c++ = sr >> 8;
233 sr = sr >> 5 | LARc[2] << 11;
234 sr = sr >> 5 | LARc[3] << 11;
235 *c++ = sr >> 6;
236 sr = sr >> 4 | LARc[4] << 12;
237 sr = sr >> 4 | LARc[5] << 12;
238 *c++ = sr >> 6;
239 sr = sr >> 3 | LARc[6] << 13;
240 sr = sr >> 3 | LARc[7] << 13;
241 *c++ = sr >> 8;
242 sr = sr >> 7 | Nc[0] << 9;
243 sr = sr >> 2 | bc[0] << 14;
244 *c++ = sr >> 7;
245 sr = sr >> 2 | Mc[0] << 14;
246 sr = sr >> 6 | xmaxc[0] << 10;
247 *c++ = sr >> 7;
248 sr = sr >> 3 | xmc[0] << 13;
249 sr = sr >> 3 | xmc[1] << 13;
250 sr = sr >> 3 | xmc[2] << 13;
251 *c++ = sr >> 6;
252 sr = sr >> 3 | xmc[3] << 13;
253 sr = sr >> 3 | xmc[4] << 13;
254 *c++ = sr >> 8;
255 sr = sr >> 3 | xmc[5] << 13;
256 sr = sr >> 3 | xmc[6] << 13;
257 sr = sr >> 3 | xmc[7] << 13;
258 *c++ = sr >> 7;
259 sr = sr >> 3 | xmc[8] << 13;
260 sr = sr >> 3 | xmc[9] << 13;
261 sr = sr >> 3 | xmc[10] << 13;
262 *c++ = sr >> 6;
263 sr = sr >> 3 | xmc[11] << 13;
264 sr = sr >> 3 | xmc[12] << 13;
265 *c++ = sr >> 8;
266 sr = sr >> 7 | Nc[1] << 9;
267 sr = sr >> 2 | bc[1] << 14;
268 *c++ = sr >> 7;
269 sr = sr >> 2 | Mc[1] << 14;
270 sr = sr >> 6 | xmaxc[1] << 10;
271 *c++ = sr >> 7;
272 sr = sr >> 3 | xmc[13] << 13;
273 sr = sr >> 3 | xmc[14] << 13;
274 sr = sr >> 3 | xmc[15] << 13;
275 *c++ = sr >> 6;
276 sr = sr >> 3 | xmc[16] << 13;
277 sr = sr >> 3 | xmc[17] << 13;
278 *c++ = sr >> 8;
279 sr = sr >> 3 | xmc[18] << 13;
280 sr = sr >> 3 | xmc[19] << 13;
281 sr = sr >> 3 | xmc[20] << 13;
282 *c++ = sr >> 7;
283 sr = sr >> 3 | xmc[21] << 13;
284 sr = sr >> 3 | xmc[22] << 13;
285 sr = sr >> 3 | xmc[23] << 13;
286 *c++ = sr >> 6;
287 sr = sr >> 3 | xmc[24] << 13;
288 sr = sr >> 3 | xmc[25] << 13;
289 *c++ = sr >> 8;
290 sr = sr >> 7 | Nc[2] << 9;
291 sr = sr >> 2 | bc[2] << 14;
292 *c++ = sr >> 7;
293 sr = sr >> 2 | Mc[2] << 14;
294 sr = sr >> 6 | xmaxc[2] << 10;
295 *c++ = sr >> 7;
296 sr = sr >> 3 | xmc[26] << 13;
297 sr = sr >> 3 | xmc[27] << 13;
298 sr = sr >> 3 | xmc[28] << 13;
299 *c++ = sr >> 6;
300 sr = sr >> 3 | xmc[29] << 13;
301 sr = sr >> 3 | xmc[30] << 13;
302 *c++ = sr >> 8;
303 sr = sr >> 3 | xmc[31] << 13;
304 sr = sr >> 3 | xmc[32] << 13;
305 sr = sr >> 3 | xmc[33] << 13;
306 *c++ = sr >> 7;
307 sr = sr >> 3 | xmc[34] << 13;
308 sr = sr >> 3 | xmc[35] << 13;
309 sr = sr >> 3 | xmc[36] << 13;
310 *c++ = sr >> 6;
311 sr = sr >> 3 | xmc[37] << 13;
312 sr = sr >> 3 | xmc[38] << 13;
313 *c++ = sr >> 8;
314 sr = sr >> 7 | Nc[3] << 9;
315 sr = sr >> 2 | bc[3] << 14;
316 *c++ = sr >> 7;
317 sr = sr >> 2 | Mc[3] << 14;
318 sr = sr >> 6 | xmaxc[3] << 10;
319 *c++ = sr >> 7;
320 sr = sr >> 3 | xmc[39] << 13;
321 sr = sr >> 3 | xmc[40] << 13;
322 sr = sr >> 3 | xmc[41] << 13;
323 *c++ = sr >> 6;
324 sr = sr >> 3 | xmc[42] << 13;
325 sr = sr >> 3 | xmc[43] << 13;
326 *c++ = sr >> 8;
327 sr = sr >> 3 | xmc[44] << 13;
328 sr = sr >> 3 | xmc[45] << 13;
329 sr = sr >> 3 | xmc[46] << 13;
330 *c++ = sr >> 7;
331 sr = sr >> 3 | xmc[47] << 13;
332 sr = sr >> 3 | xmc[48] << 13;
333 sr = sr >> 3 | xmc[49] << 13;
334 *c++ = sr >> 6;
335 sr = sr >> 3 | xmc[50] << 13;
336 sr = sr >> 3 | xmc[51] << 13;
337 *c++ = sr >> 8;
338 }
339 }
340
341 else
342
343 #endif /* WAV49 */
344 {
345
346 *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */
347 | ((LARc[0] >> 2) & 0xF);
348 *c++ = ((LARc[0] & 0x3) << 6)
349 | (LARc[1] & 0x3F);
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)
357 | (LARc[7] & 0x7);
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)
369 | (xmc[4] & 0x7);
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)
379 | (xmc[12] & 0x7);
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)
391 | (xmc[17] & 0x7);
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)
401 | (xmc[25] & 0x7);
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)
413 | (xmc[30] & 0x7);
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)
423 | (xmc[38] & 0x7);
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)
435 | (xmc[43] & 0x7);
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)
445 | (xmc[51] & 0x7);
446
447 }
448 }
449