1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | #include "gsm610_priv.h" |
8 | |
9 | #include "gsm.h" |
10 | |
11 | int gsm_decode (gsm s, gsm_byte * c, gsm_signal * target) |
12 | { |
13 | word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; |
14 | |
15 | #ifdef WAV49 |
16 | if (s->wav_fmt) { |
17 | |
18 | uword sr = 0; |
19 | |
20 | s->frame_index = !s->frame_index; |
21 | if (s->frame_index) { |
22 | |
23 | sr = *c++; |
24 | LARc[0] = sr & 0x3f; sr >>= 6; |
25 | sr |= (uword)*c++ << 2; |
26 | LARc[1] = sr & 0x3f; sr >>= 6; |
27 | sr |= (uword)*c++ << 4; |
28 | LARc[2] = sr & 0x1f; sr >>= 5; |
29 | LARc[3] = sr & 0x1f; sr >>= 5; |
30 | sr |= (uword)*c++ << 2; |
31 | LARc[4] = sr & 0xf; sr >>= 4; |
32 | LARc[5] = sr & 0xf; sr >>= 4; |
33 | sr |= (uword)*c++ << 2; |
34 | LARc[6] = sr & 0x7; sr >>= 3; |
35 | LARc[7] = sr & 0x7; sr >>= 3; |
36 | sr |= (uword)*c++ << 4; |
37 | Nc[0] = sr & 0x7f; sr >>= 7; |
38 | bc[0] = sr & 0x3; sr >>= 2; |
39 | Mc[0] = sr & 0x3; sr >>= 2; |
40 | sr |= (uword)*c++ << 1; |
41 | xmaxc[0] = sr & 0x3f; sr >>= 6; |
42 | xmc[0] = sr & 0x7; sr >>= 3; |
43 | sr = *c++; |
44 | xmc[1] = sr & 0x7; sr >>= 3; |
45 | xmc[2] = sr & 0x7; sr >>= 3; |
46 | sr |= (uword)*c++ << 2; |
47 | xmc[3] = sr & 0x7; sr >>= 3; |
48 | xmc[4] = sr & 0x7; sr >>= 3; |
49 | xmc[5] = sr & 0x7; sr >>= 3; |
50 | sr |= (uword)*c++ << 1; |
51 | xmc[6] = sr & 0x7; sr >>= 3; |
52 | xmc[7] = sr & 0x7; sr >>= 3; |
53 | xmc[8] = sr & 0x7; sr >>= 3; |
54 | sr = *c++; |
55 | xmc[9] = sr & 0x7; sr >>= 3; |
56 | xmc[10] = sr & 0x7; sr >>= 3; |
57 | sr |= (uword)*c++ << 2; |
58 | xmc[11] = sr & 0x7; sr >>= 3; |
59 | xmc[12] = sr & 0x7; sr >>= 3; |
60 | sr |= (uword)*c++ << 4; |
61 | Nc[1] = sr & 0x7f; sr >>= 7; |
62 | bc[1] = sr & 0x3; sr >>= 2; |
63 | Mc[1] = sr & 0x3; sr >>= 2; |
64 | sr |= (uword)*c++ << 1; |
65 | xmaxc[1] = sr & 0x3f; sr >>= 6; |
66 | xmc[13] = sr & 0x7; sr >>= 3; |
67 | sr = *c++; |
68 | xmc[14] = sr & 0x7; sr >>= 3; |
69 | xmc[15] = sr & 0x7; sr >>= 3; |
70 | sr |= (uword)*c++ << 2; |
71 | xmc[16] = sr & 0x7; sr >>= 3; |
72 | xmc[17] = sr & 0x7; sr >>= 3; |
73 | xmc[18] = sr & 0x7; sr >>= 3; |
74 | sr |= (uword)*c++ << 1; |
75 | xmc[19] = sr & 0x7; sr >>= 3; |
76 | xmc[20] = sr & 0x7; sr >>= 3; |
77 | xmc[21] = sr & 0x7; sr >>= 3; |
78 | sr = *c++; |
79 | xmc[22] = sr & 0x7; sr >>= 3; |
80 | xmc[23] = sr & 0x7; sr >>= 3; |
81 | sr |= (uword)*c++ << 2; |
82 | xmc[24] = sr & 0x7; sr >>= 3; |
83 | xmc[25] = sr & 0x7; sr >>= 3; |
84 | sr |= (uword)*c++ << 4; |
85 | Nc[2] = sr & 0x7f; sr >>= 7; |
86 | bc[2] = sr & 0x3; sr >>= 2; |
87 | Mc[2] = sr & 0x3; sr >>= 2; |
88 | sr |= (uword)*c++ << 1; |
89 | xmaxc[2] = sr & 0x3f; sr >>= 6; |
90 | xmc[26] = sr & 0x7; sr >>= 3; |
91 | sr = *c++; |
92 | xmc[27] = sr & 0x7; sr >>= 3; |
93 | xmc[28] = sr & 0x7; sr >>= 3; |
94 | sr |= (uword)*c++ << 2; |
95 | xmc[29] = sr & 0x7; sr >>= 3; |
96 | xmc[30] = sr & 0x7; sr >>= 3; |
97 | xmc[31] = sr & 0x7; sr >>= 3; |
98 | sr |= (uword)*c++ << 1; |
99 | xmc[32] = sr & 0x7; sr >>= 3; |
100 | xmc[33] = sr & 0x7; sr >>= 3; |
101 | xmc[34] = sr & 0x7; sr >>= 3; |
| Value stored to 'sr' is never read |
102 | sr = *c++; |
103 | xmc[35] = sr & 0x7; sr >>= 3; |
104 | xmc[36] = sr & 0x7; sr >>= 3; |
105 | sr |= (uword)*c++ << 2; |
106 | xmc[37] = sr & 0x7; sr >>= 3; |
107 | xmc[38] = sr & 0x7; sr >>= 3; |
108 | sr |= (uword)*c++ << 4; |
109 | Nc[3] = sr & 0x7f; sr >>= 7; |
110 | bc[3] = sr & 0x3; sr >>= 2; |
111 | Mc[3] = sr & 0x3; sr >>= 2; |
112 | sr |= (uword)*c++ << 1; |
113 | xmaxc[3] = sr & 0x3f; sr >>= 6; |
114 | xmc[39] = sr & 0x7; sr >>= 3; |
115 | sr = *c++; |
116 | xmc[40] = sr & 0x7; sr >>= 3; |
117 | xmc[41] = sr & 0x7; sr >>= 3; |
118 | sr |= (uword)*c++ << 2; |
119 | xmc[42] = sr & 0x7; sr >>= 3; |
120 | xmc[43] = sr & 0x7; sr >>= 3; |
121 | xmc[44] = sr & 0x7; sr >>= 3; |
122 | sr |= (uword)*c++ << 1; |
123 | xmc[45] = sr & 0x7; sr >>= 3; |
124 | xmc[46] = sr & 0x7; sr >>= 3; |
125 | xmc[47] = sr & 0x7; sr >>= 3; |
126 | sr = *c++; |
127 | xmc[48] = sr & 0x7; sr >>= 3; |
128 | xmc[49] = sr & 0x7; sr >>= 3; |
129 | sr |= (uword)*c++ << 2; |
130 | xmc[50] = sr & 0x7; sr >>= 3; |
131 | xmc[51] = sr & 0x7; sr >>= 3; |
132 | |
133 | s->frame_chain = sr & 0xf; |
134 | } |
135 | else { |
136 | sr = s->frame_chain; |
137 | sr |= (uword)*c++ << 4; |
138 | LARc[0] = sr & 0x3f; sr >>= 6; |
139 | LARc[1] = sr & 0x3f; sr >>= 6; |
140 | sr = *c++; |
141 | LARc[2] = sr & 0x1f; sr >>= 5; |
142 | sr |= (uword)*c++ << 3; |
143 | LARc[3] = sr & 0x1f; sr >>= 5; |
144 | LARc[4] = sr & 0xf; sr >>= 4; |
145 | sr |= (uword)*c++ << 2; |
146 | LARc[5] = sr & 0xf; sr >>= 4; |
147 | LARc[6] = sr & 0x7; sr >>= 3; |
148 | LARc[7] = sr & 0x7; sr >>= 3; |
149 | sr = *c++; |
150 | Nc[0] = sr & 0x7f; sr >>= 7; |
151 | sr |= (uword)*c++ << 1; |
152 | bc[0] = sr & 0x3; sr >>= 2; |
153 | Mc[0] = sr & 0x3; sr >>= 2; |
154 | sr |= (uword)*c++ << 5; |
155 | xmaxc[0] = sr & 0x3f; sr >>= 6; |
156 | xmc[0] = sr & 0x7; sr >>= 3; |
157 | xmc[1] = sr & 0x7; sr >>= 3; |
158 | sr |= (uword)*c++ << 1; |
159 | xmc[2] = sr & 0x7; sr >>= 3; |
160 | xmc[3] = sr & 0x7; sr >>= 3; |
161 | xmc[4] = sr & 0x7; sr >>= 3; |
162 | sr = *c++; |
163 | xmc[5] = sr & 0x7; sr >>= 3; |
164 | xmc[6] = sr & 0x7; sr >>= 3; |
165 | sr |= (uword)*c++ << 2; |
166 | xmc[7] = sr & 0x7; sr >>= 3; |
167 | xmc[8] = sr & 0x7; sr >>= 3; |
168 | xmc[9] = sr & 0x7; sr >>= 3; |
169 | sr |= (uword)*c++ << 1; |
170 | xmc[10] = sr & 0x7; sr >>= 3; |
171 | xmc[11] = sr & 0x7; sr >>= 3; |
172 | xmc[12] = sr & 0x7; sr >>= 3; |
173 | sr = *c++; |
174 | Nc[1] = sr & 0x7f; sr >>= 7; |
175 | sr |= (uword)*c++ << 1; |
176 | bc[1] = sr & 0x3; sr >>= 2; |
177 | Mc[1] = sr & 0x3; sr >>= 2; |
178 | sr |= (uword)*c++ << 5; |
179 | xmaxc[1] = sr & 0x3f; sr >>= 6; |
180 | xmc[13] = sr & 0x7; sr >>= 3; |
181 | xmc[14] = sr & 0x7; sr >>= 3; |
182 | sr |= (uword)*c++ << 1; |
183 | xmc[15] = sr & 0x7; sr >>= 3; |
184 | xmc[16] = sr & 0x7; sr >>= 3; |
185 | xmc[17] = sr & 0x7; sr >>= 3; |
186 | sr = *c++; |
187 | xmc[18] = sr & 0x7; sr >>= 3; |
188 | xmc[19] = sr & 0x7; sr >>= 3; |
189 | sr |= (uword)*c++ << 2; |
190 | xmc[20] = sr & 0x7; sr >>= 3; |
191 | xmc[21] = sr & 0x7; sr >>= 3; |
192 | xmc[22] = sr & 0x7; sr >>= 3; |
193 | sr |= (uword)*c++ << 1; |
194 | xmc[23] = sr & 0x7; sr >>= 3; |
195 | xmc[24] = sr & 0x7; sr >>= 3; |
196 | xmc[25] = sr & 0x7; sr >>= 3; |
197 | sr = *c++; |
198 | Nc[2] = sr & 0x7f; sr >>= 7; |
199 | sr |= (uword)*c++ << 1; |
200 | bc[2] = sr & 0x3; sr >>= 2; |
201 | Mc[2] = sr & 0x3; sr >>= 2; |
202 | sr |= (uword)*c++ << 5; |
203 | xmaxc[2] = sr & 0x3f; sr >>= 6; |
204 | xmc[26] = sr & 0x7; sr >>= 3; |
205 | xmc[27] = sr & 0x7; sr >>= 3; |
206 | sr |= (uword)*c++ << 1; |
207 | xmc[28] = sr & 0x7; sr >>= 3; |
208 | xmc[29] = sr & 0x7; sr >>= 3; |
209 | xmc[30] = sr & 0x7; sr >>= 3; |
210 | sr = *c++; |
211 | xmc[31] = sr & 0x7; sr >>= 3; |
212 | xmc[32] = sr & 0x7; sr >>= 3; |
213 | sr |= (uword)*c++ << 2; |
214 | xmc[33] = sr & 0x7; sr >>= 3; |
215 | xmc[34] = sr & 0x7; sr >>= 3; |
216 | xmc[35] = sr & 0x7; sr >>= 3; |
217 | sr |= (uword)*c++ << 1; |
218 | xmc[36] = sr & 0x7; sr >>= 3; |
219 | xmc[37] = sr & 0x7; sr >>= 3; |
220 | xmc[38] = sr & 0x7; sr >>= 3; |
221 | sr = *c++; |
222 | Nc[3] = sr & 0x7f; sr >>= 7; |
223 | sr |= (uword)*c++ << 1; |
224 | bc[3] = sr & 0x3; sr >>= 2; |
225 | Mc[3] = sr & 0x3; sr >>= 2; |
226 | sr |= (uword)*c++ << 5; |
227 | xmaxc[3] = sr & 0x3f; sr >>= 6; |
228 | xmc[39] = sr & 0x7; sr >>= 3; |
229 | xmc[40] = sr & 0x7; sr >>= 3; |
230 | sr |= (uword)*c++ << 1; |
231 | xmc[41] = sr & 0x7; sr >>= 3; |
232 | xmc[42] = sr & 0x7; sr >>= 3; |
233 | xmc[43] = sr & 0x7; sr >>= 3; |
234 | sr = *c++; |
235 | xmc[44] = sr & 0x7; sr >>= 3; |
236 | xmc[45] = sr & 0x7; sr >>= 3; |
237 | sr |= (uword)*c++ << 2; |
238 | xmc[46] = sr & 0x7; sr >>= 3; |
239 | xmc[47] = sr & 0x7; sr >>= 3; |
240 | xmc[48] = sr & 0x7; sr >>= 3; |
241 | sr |= (uword)*c++ << 1; |
242 | xmc[49] = sr & 0x7; sr >>= 3; |
243 | xmc[50] = sr & 0x7; sr >>= 3; |
244 | xmc[51] = sr & 0x7; sr >>= 3; |
245 | } |
246 | } |
247 | else |
248 | #endif |
249 | { |
250 | |
251 | |
252 | if (((*c >> 4) & 0x0F) != GSM_MAGIC0xD) return -1; |
253 | |
254 | LARc[0] = (*c++ & 0xF) << 2; |
255 | LARc[0] |= (*c >> 6) & 0x3; |
256 | LARc[1] = *c++ & 0x3F; |
257 | LARc[2] = (*c >> 3) & 0x1F; |
258 | LARc[3] = (*c++ & 0x7) << 2; |
259 | LARc[3] |= (*c >> 6) & 0x3; |
260 | LARc[4] = (*c >> 2) & 0xF; |
261 | LARc[5] = (*c++ & 0x3) << 2; |
262 | LARc[5] |= (*c >> 6) & 0x3; |
263 | LARc[6] = (*c >> 3) & 0x7; |
264 | LARc[7] = *c++ & 0x7; |
265 | Nc[0] = (*c >> 1) & 0x7F; |
266 | bc[0] = (*c++ & 0x1) << 1; |
267 | bc[0] |= (*c >> 7) & 0x1; |
268 | Mc[0] = (*c >> 5) & 0x3; |
269 | xmaxc[0] = (*c++ & 0x1F) << 1; |
270 | xmaxc[0] |= (*c >> 7) & 0x1; |
271 | xmc[0] = (*c >> 4) & 0x7; |
272 | xmc[1] = (*c >> 1) & 0x7; |
273 | xmc[2] = (*c++ & 0x1) << 2; |
274 | xmc[2] |= (*c >> 6) & 0x3; |
275 | xmc[3] = (*c >> 3) & 0x7; |
276 | xmc[4] = *c++ & 0x7; |
277 | xmc[5] = (*c >> 5) & 0x7; |
278 | xmc[6] = (*c >> 2) & 0x7; |
279 | xmc[7] = (*c++ & 0x3) << 1; |
280 | xmc[7] |= (*c >> 7) & 0x1; |
281 | xmc[8] = (*c >> 4) & 0x7; |
282 | xmc[9] = (*c >> 1) & 0x7; |
283 | xmc[10] = (*c++ & 0x1) << 2; |
284 | xmc[10] |= (*c >> 6) & 0x3; |
285 | xmc[11] = (*c >> 3) & 0x7; |
286 | xmc[12] = *c++ & 0x7; |
287 | Nc[1] = (*c >> 1) & 0x7F; |
288 | bc[1] = (*c++ & 0x1) << 1; |
289 | bc[1] |= (*c >> 7) & 0x1; |
290 | Mc[1] = (*c >> 5) & 0x3; |
291 | xmaxc[1] = (*c++ & 0x1F) << 1; |
292 | xmaxc[1] |= (*c >> 7) & 0x1; |
293 | xmc[13] = (*c >> 4) & 0x7; |
294 | xmc[14] = (*c >> 1) & 0x7; |
295 | xmc[15] = (*c++ & 0x1) << 2; |
296 | xmc[15] |= (*c >> 6) & 0x3; |
297 | xmc[16] = (*c >> 3) & 0x7; |
298 | xmc[17] = *c++ & 0x7; |
299 | xmc[18] = (*c >> 5) & 0x7; |
300 | xmc[19] = (*c >> 2) & 0x7; |
301 | xmc[20] = (*c++ & 0x3) << 1; |
302 | xmc[20] |= (*c >> 7) & 0x1; |
303 | xmc[21] = (*c >> 4) & 0x7; |
304 | xmc[22] = (*c >> 1) & 0x7; |
305 | xmc[23] = (*c++ & 0x1) << 2; |
306 | xmc[23] |= (*c >> 6) & 0x3; |
307 | xmc[24] = (*c >> 3) & 0x7; |
308 | xmc[25] = *c++ & 0x7; |
309 | Nc[2] = (*c >> 1) & 0x7F; |
310 | bc[2] = (*c++ & 0x1) << 1; |
311 | bc[2] |= (*c >> 7) & 0x1; |
312 | Mc[2] = (*c >> 5) & 0x3; |
313 | xmaxc[2] = (*c++ & 0x1F) << 1; |
314 | xmaxc[2] |= (*c >> 7) & 0x1; |
315 | xmc[26] = (*c >> 4) & 0x7; |
316 | xmc[27] = (*c >> 1) & 0x7; |
317 | xmc[28] = (*c++ & 0x1) << 2; |
318 | xmc[28] |= (*c >> 6) & 0x3; |
319 | xmc[29] = (*c >> 3) & 0x7; |
320 | xmc[30] = *c++ & 0x7; |
321 | xmc[31] = (*c >> 5) & 0x7; |
322 | xmc[32] = (*c >> 2) & 0x7; |
323 | xmc[33] = (*c++ & 0x3) << 1; |
324 | xmc[33] |= (*c >> 7) & 0x1; |
325 | xmc[34] = (*c >> 4) & 0x7; |
326 | xmc[35] = (*c >> 1) & 0x7; |
327 | xmc[36] = (*c++ & 0x1) << 2; |
328 | xmc[36] |= (*c >> 6) & 0x3; |
329 | xmc[37] = (*c >> 3) & 0x7; |
330 | xmc[38] = *c++ & 0x7; |
331 | Nc[3] = (*c >> 1) & 0x7F; |
332 | bc[3] = (*c++ & 0x1) << 1; |
333 | bc[3] |= (*c >> 7) & 0x1; |
334 | Mc[3] = (*c >> 5) & 0x3; |
335 | xmaxc[3] = (*c++ & 0x1F) << 1; |
336 | xmaxc[3] |= (*c >> 7) & 0x1; |
337 | xmc[39] = (*c >> 4) & 0x7; |
338 | xmc[40] = (*c >> 1) & 0x7; |
339 | xmc[41] = (*c++ & 0x1) << 2; |
340 | xmc[41] |= (*c >> 6) & 0x3; |
341 | xmc[42] = (*c >> 3) & 0x7; |
342 | xmc[43] = *c++ & 0x7; |
343 | xmc[44] = (*c >> 5) & 0x7; |
344 | xmc[45] = (*c >> 2) & 0x7; |
345 | xmc[46] = (*c++ & 0x3) << 1; |
346 | xmc[46] |= (*c >> 7) & 0x1; |
347 | xmc[47] = (*c >> 4) & 0x7; |
348 | xmc[48] = (*c >> 1) & 0x7; |
349 | xmc[49] = (*c++ & 0x1) << 2; |
350 | xmc[49] |= (*c >> 6) & 0x3; |
351 | xmc[50] = (*c >> 3) & 0x7; |
352 | xmc[51] = *c & 0x7; |
353 | } |
354 | |
355 | Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target); |
356 | |
357 | return 0; |
358 | } |
359 | |