annotate trau-decode/parse-fr.c @ 2:b2ef2c80fef1

trau-parse: add FR decoding
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 24 May 2024 08:11:25 +0000
parents trau-parse.c@b0dcd48a1c8a
children 64b15810dc4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
2 * This module implements the FR decoding part of trau-parse.
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
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
65 print_fr_frame(d_bits)
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
66 uint8_t d_bits;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 {
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
68 int16_t params[GSMFR_NUM_PARAMS];
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
69 uint8_t rtp_pack[GSMFR_RTP_FRAME_LEN];
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
70 int i, j, n, sid;
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 fputs(" FR frame:\n ", stdout);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
74 n = 0;
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
75 for (i = 0; i < 8; i++)
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
76 printf(" %d", params[n++]);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
77 putchar('\n');
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
78 for (i = 0; i < 4; i++) {
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
79 fputs(" ", stdout);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
80 for (j = 0; j < 17; j++)
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
81 printf(" %d", params[n++]);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
82 putchar('\n');
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
84 gsmfr_pack_from_array(params, rtp_pack);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
85 sid = gsmfr_preproc_sid_classify(rtp_pack);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
86 printf(" SID recompute: %d\n", sid);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
87 if (!bcmp(rtp_pack, gsmfr_decoder_homing_frame, GSMFR_RTP_FRAME_LEN))
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
88 puts(" Matches DHF");
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }