comparison 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
comparison
equal deleted inserted replaced
1:b0dcd48a1c8a 2:b2ef2c80fef1
1 /*
2 * This module implements the FR decoding part of trau-parse.
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 print_fr_frame(d_bits)
66 uint8_t d_bits;
67 {
68 int16_t params[GSMFR_NUM_PARAMS];
69 uint8_t rtp_pack[GSMFR_RTP_FRAME_LEN];
70 int i, j, n, sid;
71
72 dbits_to_params(d_bits, params);
73 fputs(" FR frame:\n ", stdout);
74 n = 0;
75 for (i = 0; i < 8; i++)
76 printf(" %d", params[n++]);
77 putchar('\n');
78 for (i = 0; i < 4; i++) {
79 fputs(" ", stdout);
80 for (j = 0; j < 17; j++)
81 printf(" %d", params[n++]);
82 putchar('\n');
83 }
84 gsmfr_pack_from_array(params, rtp_pack);
85 sid = gsmfr_preproc_sid_classify(rtp_pack);
86 printf(" SID recompute: %d\n", sid);
87 if (!bcmp(rtp_pack, gsmfr_decoder_homing_frame, GSMFR_RTP_FRAME_LEN))
88 puts(" Matches DHF");
89 }