FreeCalypso > hg > gsm-net-reveng
comparison trau-decode/extr-fr.c @ 9:0565aaa84b17
trau-decode: implement trau-extr program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 24 May 2024 19:44:14 +0000 |
parents | trau-decode/parse-fr.c@64b15810dc4c |
children |
comparison
equal
deleted
inserted
replaced
8:85662304252e | 9:0565aaa84b17 |
---|---|
1 /* | |
2 * This module implements the FR decoding part of trau-extr. | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <stdint.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <tw_gsmfr.h> | |
11 | |
12 /* this corresponds to the bit-lengths of the individual codec | |
13 * parameters as indicated in Table 1.1 of TS 46.010 */ | |
14 static const uint8_t gsm_fr_map[GSMFR_NUM_PARAMS] = { | |
15 6, 6, 5, 5, 4, 4, 3, 3, | |
16 7, 2, 2, 6, 3, 3, 3, 3, | |
17 3, 3, 3, 3, 3, 3, 3, 3, | |
18 3, 7, 2, 2, 6, 3, 3, 3, | |
19 3, 3, 3, 3, 3, 3, 3, 3, | |
20 3, 3, 7, 2, 2, 6, 3, 3, | |
21 3, 3, 3, 3, 3, 3, 3, 3, | |
22 3, 3, 3, 7, 2, 2, 6, 3, | |
23 3, 3, 3, 3, 3, 3, 3, 3, | |
24 3, 3, 3, 3 | |
25 }; | |
26 | |
27 static unsigned | |
28 get_le(bits, nbits) | |
29 uint8_t *bits; | |
30 unsigned nbits; | |
31 { | |
32 unsigned accum, mask; | |
33 unsigned n; | |
34 | |
35 accum = 0; | |
36 mask = 1; | |
37 for (n = 0; n < nbits; n++) { | |
38 if (*bits) | |
39 accum |= mask; | |
40 bits++; | |
41 mask <<= 1; | |
42 } | |
43 return accum; | |
44 } | |
45 | |
46 static void | |
47 dbits_to_params(d_bits, params) | |
48 uint8_t *d_bits; | |
49 int16_t *params; | |
50 { | |
51 unsigned np, len; | |
52 uint8_t *ip; | |
53 int16_t *op; | |
54 | |
55 ip = d_bits; | |
56 op = params; | |
57 for (np = 0; np < GSMFR_NUM_PARAMS; np++) { | |
58 len = gsm_fr_map[np]; | |
59 *op++ = get_le(ip, len); | |
60 ip += len; | |
61 } | |
62 } | |
63 | |
64 void | |
65 convert_fr_frame(d_bits, outf) | |
66 uint8_t *d_bits; | |
67 FILE *outf; | |
68 { | |
69 int16_t params[GSMFR_NUM_PARAMS]; | |
70 uint8_t rtp_pack[GSMFR_RTP_FRAME_LEN]; | |
71 | |
72 dbits_to_params(d_bits, params); | |
73 gsmfr_pack_from_array(params, rtp_pack); | |
74 fwrite(rtp_pack, 1, GSMFR_RTP_FRAME_LEN, outf); | |
75 } |