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