FreeCalypso > hg > gsm-codec-lib
comparison frtest/tidsp.c @ 19:7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 20 Nov 2022 06:11:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
18:39dbaccc349d | 19:7960744ba19c |
---|---|
1 /* | |
2 * This code (lifted from OsmocomBB) facilitates the conversion of 33-byte | |
3 * GSM 06.10 encoded speech frames between the bit order at the 06.10 interface | |
4 * in the de facto standard libgsm implementation and the bit order at the | |
5 * 05.03 channel encoder interface, as realized in TI's Calypso DSP. | |
6 */ | |
7 | |
8 #include <sys/types.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 | |
12 /* GSM FR - subjective importance bit ordering */ | |
13 /* This array encodes GSM 05.03 Table 2. | |
14 * It's also GSM 06.10 Table A.2.1a | |
15 * | |
16 * It converts between serial parameter output by the encoder and the | |
17 * order needed before channel encoding. | |
18 */ | |
19 const u_short gsm0610_bitorder[260] = { | |
20 0, /* LARc0:5 */ | |
21 47, /* Xmaxc0:5 */ | |
22 103, /* Xmaxc1:5 */ | |
23 159, /* Xmaxc2:5 */ | |
24 215, /* Xmaxc3:5 */ | |
25 1, /* LARc0:4 */ | |
26 6, /* LARc1:5 */ | |
27 12, /* LARc2:4 */ | |
28 2, /* LARc0:3 */ | |
29 7, /* LARc1:4 */ | |
30 13, /* LARc2:3 */ | |
31 17, /* LARc3:4 */ | |
32 36, /* Nc0:6 */ | |
33 92, /* Nc1:6 */ | |
34 148, /* Nc2:6 */ | |
35 204, /* Nc3:6 */ | |
36 48, /* Xmaxc0:4 */ | |
37 104, /* Xmaxc1:4 */ | |
38 160, /* Xmaxc2:4 */ | |
39 216, /* Xmaxc3:4 */ | |
40 8, /* LARc1:3 */ | |
41 22, /* LARc4:3 */ | |
42 26, /* LARc5:3 */ | |
43 37, /* Nc0:5 */ | |
44 93, /* Nc1:5 */ | |
45 149, /* Nc2:5 */ | |
46 205, /* Nc3:5 */ | |
47 38, /* Nc0:4 */ | |
48 94, /* Nc1:4 */ | |
49 150, /* Nc2:4 */ | |
50 206, /* Nc3:4 */ | |
51 39, /* Nc0:3 */ | |
52 95, /* Nc1:3 */ | |
53 151, /* Nc2:3 */ | |
54 207, /* Nc3:3 */ | |
55 40, /* Nc0:2 */ | |
56 96, /* Nc1:2 */ | |
57 152, /* Nc2:2 */ | |
58 208, /* Nc3:2 */ | |
59 49, /* Xmaxc0:3 */ | |
60 105, /* Xmaxc1:3 */ | |
61 161, /* Xmaxc2:3 */ | |
62 217, /* Xmaxc3:3 */ | |
63 3, /* LARc0:2 */ | |
64 18, /* LARc3:3 */ | |
65 30, /* LARc6:2 */ | |
66 41, /* Nc0:1 */ | |
67 97, /* Nc1:1 */ | |
68 153, /* Nc2:1 */ | |
69 209, /* Nc3:1 */ | |
70 23, /* LARc4:2 */ | |
71 27, /* LARc5:2 */ | |
72 43, /* bc0:1 */ | |
73 99, /* bc1:1 */ | |
74 155, /* bc2:1 */ | |
75 211, /* bc3:1 */ | |
76 42, /* Nc0:0 */ | |
77 98, /* Nc1:0 */ | |
78 154, /* Nc2:0 */ | |
79 210, /* Nc3:0 */ | |
80 45, /* Mc0:1 */ | |
81 101, /* Mc1:1 */ | |
82 157, /* Mc2:1 */ | |
83 213, /* Mc3:1 */ | |
84 4, /* LARc0:1 */ | |
85 9, /* LARc1:2 */ | |
86 14, /* LARc2:2 */ | |
87 33, /* LARc7:2 */ | |
88 19, /* LARc3:2 */ | |
89 24, /* LARc4:1 */ | |
90 31, /* LARc6:1 */ | |
91 44, /* bc0:0 */ | |
92 100, /* bc1:0 */ | |
93 156, /* bc2:0 */ | |
94 212, /* bc3:0 */ | |
95 50, /* Xmaxc0:2 */ | |
96 106, /* Xmaxc1:2 */ | |
97 162, /* Xmaxc2:2 */ | |
98 218, /* Xmaxc3:2 */ | |
99 53, /* xmc0_0:2 */ | |
100 56, /* xmc0_1:2 */ | |
101 59, /* xmc0_2:2 */ | |
102 62, /* xmc0_3:2 */ | |
103 65, /* xmc0_4:2 */ | |
104 68, /* xmc0_5:2 */ | |
105 71, /* xmc0_6:2 */ | |
106 74, /* xmc0_7:2 */ | |
107 77, /* xmc0_8:2 */ | |
108 80, /* xmc0_9:2 */ | |
109 83, /* xmc0_10:2 */ | |
110 86, /* xmc0_11:2 */ | |
111 89, /* xmc0_12:2 */ | |
112 109, /* xmc1_0:2 */ | |
113 112, /* xmc1_1:2 */ | |
114 115, /* xmc1_2:2 */ | |
115 118, /* xmc1_3:2 */ | |
116 121, /* xmc1_4:2 */ | |
117 124, /* xmc1_5:2 */ | |
118 127, /* xmc1_6:2 */ | |
119 130, /* xmc1_7:2 */ | |
120 133, /* xmc1_8:2 */ | |
121 136, /* xmc1_9:2 */ | |
122 139, /* xmc1_10:2 */ | |
123 142, /* xmc1_11:2 */ | |
124 145, /* xmc1_12:2 */ | |
125 165, /* xmc2_0:2 */ | |
126 168, /* xmc2_1:2 */ | |
127 171, /* xmc2_2:2 */ | |
128 174, /* xmc2_3:2 */ | |
129 177, /* xmc2_4:2 */ | |
130 180, /* xmc2_5:2 */ | |
131 183, /* xmc2_6:2 */ | |
132 186, /* xmc2_7:2 */ | |
133 189, /* xmc2_8:2 */ | |
134 192, /* xmc2_9:2 */ | |
135 195, /* xmc2_10:2 */ | |
136 198, /* xmc2_11:2 */ | |
137 201, /* xmc2_12:2 */ | |
138 221, /* xmc3_0:2 */ | |
139 224, /* xmc3_1:2 */ | |
140 227, /* xmc3_2:2 */ | |
141 230, /* xmc3_3:2 */ | |
142 233, /* xmc3_4:2 */ | |
143 236, /* xmc3_5:2 */ | |
144 239, /* xmc3_6:2 */ | |
145 242, /* xmc3_7:2 */ | |
146 245, /* xmc3_8:2 */ | |
147 248, /* xmc3_9:2 */ | |
148 251, /* xmc3_10:2 */ | |
149 254, /* xmc3_11:2 */ | |
150 257, /* xmc3_12:2 */ | |
151 46, /* Mc0:0 */ | |
152 102, /* Mc1:0 */ | |
153 158, /* Mc2:0 */ | |
154 214, /* Mc3:0 */ | |
155 51, /* Xmaxc0:1 */ | |
156 107, /* Xmaxc1:1 */ | |
157 163, /* Xmaxc2:1 */ | |
158 219, /* Xmaxc3:1 */ | |
159 54, /* xmc0_0:1 */ | |
160 57, /* xmc0_1:1 */ | |
161 60, /* xmc0_2:1 */ | |
162 63, /* xmc0_3:1 */ | |
163 66, /* xmc0_4:1 */ | |
164 69, /* xmc0_5:1 */ | |
165 72, /* xmc0_6:1 */ | |
166 75, /* xmc0_7:1 */ | |
167 78, /* xmc0_8:1 */ | |
168 81, /* xmc0_9:1 */ | |
169 84, /* xmc0_10:1 */ | |
170 87, /* xmc0_11:1 */ | |
171 90, /* xmc0_12:1 */ | |
172 110, /* xmc1_0:1 */ | |
173 113, /* xmc1_1:1 */ | |
174 116, /* xmc1_2:1 */ | |
175 119, /* xmc1_3:1 */ | |
176 122, /* xmc1_4:1 */ | |
177 125, /* xmc1_5:1 */ | |
178 128, /* xmc1_6:1 */ | |
179 131, /* xmc1_7:1 */ | |
180 134, /* xmc1_8:1 */ | |
181 137, /* xmc1_9:1 */ | |
182 140, /* xmc1_10:1 */ | |
183 143, /* xmc1_11:1 */ | |
184 146, /* xmc1_12:1 */ | |
185 166, /* xmc2_0:1 */ | |
186 169, /* xmc2_1:1 */ | |
187 172, /* xmc2_2:1 */ | |
188 175, /* xmc2_3:1 */ | |
189 178, /* xmc2_4:1 */ | |
190 181, /* xmc2_5:1 */ | |
191 184, /* xmc2_6:1 */ | |
192 187, /* xmc2_7:1 */ | |
193 190, /* xmc2_8:1 */ | |
194 193, /* xmc2_9:1 */ | |
195 196, /* xmc2_10:1 */ | |
196 199, /* xmc2_11:1 */ | |
197 202, /* xmc2_12:1 */ | |
198 222, /* xmc3_0:1 */ | |
199 225, /* xmc3_1:1 */ | |
200 228, /* xmc3_2:1 */ | |
201 231, /* xmc3_3:1 */ | |
202 234, /* xmc3_4:1 */ | |
203 237, /* xmc3_5:1 */ | |
204 240, /* xmc3_6:1 */ | |
205 243, /* xmc3_7:1 */ | |
206 246, /* xmc3_8:1 */ | |
207 249, /* xmc3_9:1 */ | |
208 252, /* xmc3_10:1 */ | |
209 255, /* xmc3_11:1 */ | |
210 258, /* xmc3_12:1 */ | |
211 5, /* LARc0:0 */ | |
212 10, /* LARc1:1 */ | |
213 15, /* LARc2:1 */ | |
214 28, /* LARc5:1 */ | |
215 32, /* LARc6:0 */ | |
216 34, /* LARc7:1 */ | |
217 35, /* LARc7:0 */ | |
218 16, /* LARc2:0 */ | |
219 20, /* LARc3:1 */ | |
220 21, /* LARc3:0 */ | |
221 25, /* LARc4:0 */ | |
222 52, /* Xmaxc0:0 */ | |
223 108, /* Xmaxc1:0 */ | |
224 164, /* Xmaxc2:0 */ | |
225 220, /* Xmaxc3:0 */ | |
226 55, /* xmc0_0:0 */ | |
227 58, /* xmc0_1:0 */ | |
228 61, /* xmc0_2:0 */ | |
229 64, /* xmc0_3:0 */ | |
230 67, /* xmc0_4:0 */ | |
231 70, /* xmc0_5:0 */ | |
232 73, /* xmc0_6:0 */ | |
233 76, /* xmc0_7:0 */ | |
234 79, /* xmc0_8:0 */ | |
235 82, /* xmc0_9:0 */ | |
236 85, /* xmc0_10:0 */ | |
237 88, /* xmc0_11:0 */ | |
238 91, /* xmc0_12:0 */ | |
239 111, /* xmc1_0:0 */ | |
240 114, /* xmc1_1:0 */ | |
241 117, /* xmc1_2:0 */ | |
242 120, /* xmc1_3:0 */ | |
243 123, /* xmc1_4:0 */ | |
244 126, /* xmc1_5:0 */ | |
245 129, /* xmc1_6:0 */ | |
246 132, /* xmc1_7:0 */ | |
247 135, /* xmc1_8:0 */ | |
248 138, /* xmc1_9:0 */ | |
249 141, /* xmc1_10:0 */ | |
250 144, /* xmc1_11:0 */ | |
251 147, /* xmc1_12:0 */ | |
252 167, /* xmc2_0:0 */ | |
253 170, /* xmc2_1:0 */ | |
254 173, /* xmc2_2:0 */ | |
255 176, /* xmc2_3:0 */ | |
256 179, /* xmc2_4:0 */ | |
257 182, /* xmc2_5:0 */ | |
258 185, /* xmc2_6:0 */ | |
259 188, /* xmc2_7:0 */ | |
260 191, /* xmc2_8:0 */ | |
261 194, /* xmc2_9:0 */ | |
262 197, /* xmc2_10:0 */ | |
263 200, /* xmc2_11:0 */ | |
264 203, /* xmc2_12:0 */ | |
265 223, /* xmc3_0:0 */ | |
266 226, /* xmc3_1:0 */ | |
267 229, /* xmc3_2:0 */ | |
268 232, /* xmc3_3:0 */ | |
269 235, /* xmc3_4:0 */ | |
270 238, /* xmc3_5:0 */ | |
271 241, /* xmc3_6:0 */ | |
272 244, /* xmc3_7:0 */ | |
273 247, /* xmc3_8:0 */ | |
274 250, /* xmc3_9:0 */ | |
275 253, /* xmc3_10:0 */ | |
276 256, /* xmc3_11:0 */ | |
277 259, /* xmc3_12:0 */ | |
278 11, /* LARc1:0 */ | |
279 29, /* LARc5:0 */ | |
280 }; | |
281 | |
282 static int | |
283 msb_get_bit(buf, bn) | |
284 u_char *buf; | |
285 { | |
286 int pos_byte = bn >> 3; | |
287 int pos_bit = 7 - (bn & 7); | |
288 | |
289 return (buf[pos_byte] >> pos_bit) & 1; | |
290 } | |
291 | |
292 static void | |
293 msb_set_bit(buf, bn, bit) | |
294 u_char *buf; | |
295 { | |
296 int pos_byte = bn >> 3; | |
297 int pos_bit = 7 - (bn & 7); | |
298 | |
299 buf[pos_byte] |= (bit << pos_bit); | |
300 } | |
301 | |
302 void | |
303 gsm0610_tidsp_to_libgsm(inbytes, outbytes) | |
304 u_char *inbytes, *outbytes; | |
305 { | |
306 int i, di, si; | |
307 | |
308 bzero(outbytes, 33); | |
309 outbytes[0] = 0xD0; | |
310 for (i = 0; i < 260; i++) { | |
311 di = gsm0610_bitorder[i]; | |
312 si = (i > 181) ? i + 4 : i; | |
313 msb_set_bit(outbytes, 4 + di, msb_get_bit(inbytes, si)); | |
314 } | |
315 } | |
316 | |
317 void | |
318 gsm0610_libgsm_to_tidsp(inbytes, outbytes) | |
319 u_char *inbytes, *outbytes; | |
320 { | |
321 int i, di, si; | |
322 | |
323 bzero(outbytes, 33); | |
324 for (i = 0; i < 260; i++) { | |
325 si = gsm0610_bitorder[i]; | |
326 di = (i > 181) ? i + 4 : i; | |
327 msb_set_bit(outbytes, di, msb_get_bit(inbytes, 4 + si)); | |
328 } | |
329 } |