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