FreeCalypso > hg > gsm-net-reveng
annotate trau-decode/parse-amr.c @ 80:58dfdb2fc6df
trau-parse: AMR 12k2 CRC
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 08 Feb 2025 18:26:48 +0000 |
parents | 8c1f20e845a1 |
children | 9eff2af191d5 |
rev | line source |
---|---|
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
2 * Here we implement parsing/decoding of AMR frames as in 3GPP TS 48.060 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
3 * section 5.5.1.2, striving to decode and display as much as we can. |
0
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 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
11 #include "osmo_bits.h" |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
12 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
13 /* |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
14 * AMR TRAU parity (same as EFR) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
15 * |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
16 * g(x) = x^3 + x^1 + 1 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
17 */ |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
18 static const struct osmo_crc8gen_code gsm0860_amr_crc3 = { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
19 .bits = 3, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
20 .poly = 0x3, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
21 .init = 0x0, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
22 .remainder = 0x7, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
23 }; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
24 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
25 static int saved_mode, saved_mode_valid; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
26 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
27 static char *fclass_names[4] = { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
28 "No_Speech", "Speech_Bad", "Speech_Degraded", "Speech_Good" |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
29 }; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
30 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
31 static char *nospch_class_names[8] = { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
32 "No_Data", "invalid", "invalid", "invalid", |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
33 "Sid_Bad", "Sid_Update", "Onset", "Sid_First" |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
34 }; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 static unsigned |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 bits_to_num(bits, nbits) |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
38 ubit_t *bits; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 unsigned nbits; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 unsigned accum; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 unsigned n; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 accum = 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 for (n = 0; n < nbits; n++) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 accum <<= 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (*bits) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 accum |= 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 bits++; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return accum; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
54 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
55 decode_mode_0(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
56 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
57 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
58 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
59 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
60 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
61 decode_mode_1(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
62 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
63 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
64 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
65 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
66 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
67 decode_mode_2(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
68 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
69 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
70 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
71 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
72 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
73 decode_mode_3(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
74 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
75 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
76 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
77 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
78 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
79 decode_mode_4(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
80 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
81 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
82 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
83 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
84 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
85 decode_mode_5(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
86 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
87 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
88 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
89 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
90 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
91 decode_mode_6(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
92 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
93 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
94 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
95 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
96 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
97 decode_mode_7(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
98 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
99 { |
80
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
100 ubit_t crc_collect[69]; |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
101 int crc1, crc2, crc3, crc4; |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
102 |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
103 bcopy(c_bits, crc_collect, 25); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
104 bcopy(d_bits, crc_collect + 25, 29); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
105 bcopy(d_bits + 38, crc_collect + 54, 12); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
106 bcopy(d_bits + 86, crc_collect + 66, 3); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
107 crc1 = osmo_crc8gen_check_bits(&gsm0860_amr_crc3, crc_collect, 69, |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
108 d_bits + 91); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
109 bcopy(d_bits + 94, crc_collect, 9); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
110 bcopy(d_bits + 139, crc_collect + 9, 3); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
111 crc2 = osmo_crc8gen_check_bits(&gsm0860_amr_crc3, crc_collect, 12, |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
112 d_bits + 144); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
113 bcopy(d_bits + 147, crc_collect, 12); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
114 bcopy(d_bits + 195, crc_collect + 12, 3); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
115 crc3 = osmo_crc8gen_check_bits(&gsm0860_amr_crc3, crc_collect, 15, |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
116 d_bits + 200); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
117 bcopy(d_bits + 203, crc_collect, 5); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
118 bcopy(d_bits + 209, crc_collect + 5, 3); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
119 bcopy(d_bits + 248, crc_collect + 8, 3); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
120 crc4 = osmo_crc8gen_check_bits(&gsm0860_amr_crc3, crc_collect, 11, |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
121 d_bits + 253); |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
122 printf(" CRC %s %s %s %s\n", |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
123 crc1 ? "bad" : "good", crc2 ? "bad" : "good", |
58dfdb2fc6df
trau-parse: AMR 12k2 CRC
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
124 crc3 ? "bad" : "good", crc4 ? "bad" : "good"); |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
125 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
126 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
127 static void (*per_mode_decode[8])() = { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
128 decode_mode_0, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
129 decode_mode_1, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
130 decode_mode_2, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
131 decode_mode_3, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
132 decode_mode_4, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
133 decode_mode_5, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
134 decode_mode_6, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
135 decode_mode_7 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
136 }; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
137 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
138 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
139 decode_speech_frame(c_bits, d_bits, cm_hdr) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
140 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
141 unsigned cm_hdr; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
142 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
143 unsigned mode; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
144 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
145 if (c_bits[11]) { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
146 if (!saved_mode_valid) { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
147 printf(" Mode unknown, cannot decode\n"); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
148 return; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
149 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
150 mode = saved_mode; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
151 saved_mode_valid = 0; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
152 } else { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
153 mode = cm_hdr; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
154 saved_mode = mode; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
155 saved_mode_valid = 1; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
156 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
157 printf(" Decoding per speech mode %u\n", mode); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
158 per_mode_decode[mode](c_bits, d_bits); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
159 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
160 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
161 static void |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
162 decode_nospeech_frame(c_bits, d_bits) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
163 ubit_t *c_bits, *d_bits; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
164 { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
165 ubit_t crc_collect[25 + 61]; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
166 int crc_stat; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
167 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
168 printf(" No_Spch_Class=%u%u%u (%s) CMI=%u CMR=%u\n", |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
169 d_bits[31], d_bits[32], d_bits[33], |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
170 nospch_class_names[bits_to_num(d_bits + 31, 3)], |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
171 bits_to_num(d_bits + 34, 3), bits_to_num(d_bits + 37, 3)); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
172 printf(" PAB=%u TAE=%u%u\n", d_bits[40], d_bits[41], d_bits[42]); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
173 bcopy(c_bits, crc_collect, 25); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
174 bcopy(d_bits + 31, crc_collect + 25, 61); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
175 crc_stat = osmo_crc8gen_check_bits(&gsm0860_amr_crc3, crc_collect, |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
176 25 + 61, d_bits + 92); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
177 printf(" CRC %s\n", crc_stat ? "bad" : "good"); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
178 if (crc_stat) { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
179 saved_mode_valid = 0; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
180 } else { |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
181 saved_mode = bits_to_num(d_bits + 34, 3); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
182 saved_mode_valid = 1; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
183 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
184 } |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
185 |
78
00fd38c7c8fe
trau-decode: factor out parse-amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
186 void |
00fd38c7c8fe
trau-decode: factor out parse-amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
187 print_amr_frame(frame_bits) |
00fd38c7c8fe
trau-decode: factor out parse-amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
188 uint8_t *frame_bits; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 { |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
190 ubit_t c_bits[25], d_bits[256]; |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
191 uint8_t fclass, cm_hdr; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
193 bcopy(frame_bits + 17, c_bits, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
194 bcopy(frame_bits + 33, c_bits + 15, 10); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
195 bcopy(frame_bits + 43, d_bits, 5); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
196 bcopy(frame_bits + 49, d_bits + 5, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
197 bcopy(frame_bits + 65, d_bits + 20, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
198 bcopy(frame_bits + 81, d_bits + 35, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
199 bcopy(frame_bits + 97, d_bits + 50, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
200 bcopy(frame_bits + 113, d_bits + 65, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
201 bcopy(frame_bits + 129, d_bits + 80, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
202 bcopy(frame_bits + 145, d_bits + 95, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
203 bcopy(frame_bits + 161, d_bits + 110, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
204 bcopy(frame_bits + 177, d_bits + 125, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
205 bcopy(frame_bits + 193, d_bits + 140, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
206 bcopy(frame_bits + 209, d_bits + 155, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
207 bcopy(frame_bits + 225, d_bits + 170, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
208 bcopy(frame_bits + 241, d_bits + 185, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
209 bcopy(frame_bits + 257, d_bits + 200, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
210 bcopy(frame_bits + 273, d_bits + 215, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
211 bcopy(frame_bits + 289, d_bits + 230, 15); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
212 bcopy(frame_bits + 305, d_bits + 245, 11); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
213 |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
214 printf(" C6-C11: %u\n", bits_to_num(c_bits + 5, 6)); |
78
00fd38c7c8fe
trau-decode: factor out parse-amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
215 printf(" RIF=%u C13=%u Config_Prot=%u%u%u Msg_No=%u%u\n", |
79
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
216 c_bits[11], c_bits[12], c_bits[13], c_bits[14], c_bits[15], |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
217 c_bits[16], c_bits[17]); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
218 fclass = bits_to_num(c_bits + 20, 2); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
219 cm_hdr = bits_to_num(c_bits + 22, 3); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
220 printf(" DTXd=%u TFOE=%u FClass=%u%u (%s) %s=%u\n", |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
221 c_bits[18], c_bits[19], c_bits[20], c_bits[21], |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
222 fclass_names[fclass], c_bits[11] ? "CMR" : "CMI", cm_hdr); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
223 if (fclass) |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
224 decode_speech_frame(c_bits, d_bits, cm_hdr); |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
225 else |
8c1f20e845a1
trau-parse: more thorough AMR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
78
diff
changeset
|
226 decode_nospeech_frame(c_bits, d_bits); |
78
00fd38c7c8fe
trau-decode: factor out parse-amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
227 printf(" T1=%u T2=%u T3=%u T4=%u\n", frame_bits[316], |
00fd38c7c8fe
trau-decode: factor out parse-amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
228 frame_bits[317], frame_bits[318], frame_bits[319]); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 } |