FreeCalypso > hg > rtp-debug-utils
comparison pcm-study/g711u-grep-gsmout.c @ 11:8b047c9bfe5f
g711u-grep-gsmout program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 15 May 2024 02:31:01 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
10:e686bc92c7d8 | 11:8b047c9bfe5f |
---|---|
1 /* | |
2 * This programs reads a G.711 PCMU sample stream and 'grep's it for | |
3 * particular patterns that result from a GSM-FR or GSM-EFR decoder | |
4 * processing uplink test frames constructed in vband-misc repository, | |
5 * ul-test subdirectory. | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdint.h> | |
10 #include <stdlib.h> | |
11 | |
12 static const uint8_t match_frame_fr[160] = { | |
13 0xFF,0x0F,0x0E,0x1B,0x8D,0x8A,0x9C,0x23,0x1D,0x38,0x1C,0x1B,0x26,0x8A,0x80,0x92, | |
14 0x11,0x06,0x1E,0xA3,0x9B,0xBF,0x9B,0x91,0x9C,0x11,0x06,0x1C,0x98,0x87,0x8D,0xAF, | |
15 0x1D,0x16,0x13,0x1F,0xBE,0x8D,0x88,0x99,0x1D,0x07,0x05,0x12,0xAC,0x8B,0x87,0x95, | |
16 0x25,0x09,0x06,0x14,0xAA,0x8B,0x88,0x97,0x25,0x0A,0x09,0x1A,0xA4,0x8C,0x8A,0x99, | |
17 0x28,0x0C,0x09,0x1B,0xA5,0x8C,0x8B,0x9D,0x23,0x0C,0x0A,0x19,0xA4,0x8C,0x8A,0x9D, | |
18 0x1E,0x0A,0x0A,0x1C,0xA2,0x8C,0x8B,0x9B,0x25,0x0C,0x0A,0x19,0xA7,0x8C,0x8B,0x9B, | |
19 0x26,0x0D,0x0B,0x1A,0xAA,0x8D,0x8A,0x99,0x2A,0x0D,0x0B,0x1A,0xAB,0x8E,0x8C,0x99, | |
20 0x2F,0x0F,0x0B,0x19,0xAE,0x8E,0x8C,0x99,0x34,0x0F,0x0D,0x1A,0xB2,0x91,0x8D,0x99, | |
21 0x3B,0x12,0x0D,0x19,0xBA,0x92,0x8E,0x9B,0x38,0x14,0x0F,0x1B,0xBB,0x94,0x8E,0x9A, | |
22 0x3B,0x13,0x0E,0x1B,0xBA,0x95,0x90,0x9B,0x3F,0x16,0x0F,0x1B,0xBB,0x94,0x8F,0x9C, | |
23 }; | |
24 | |
25 static const uint8_t match_frame_efr_classic[160] = { | |
26 0x6F,0x64,0x63,0x6B,0xE8,0xDA,0xDC,0xEF,0x60,0x5A,0x5D,0x6F,0xE2,0xD8,0xD9,0xEC, | |
27 0x5F,0x58,0x5E,0x7E,0xE2,0xDF,0xE2,0xF0,0x63,0x58,0x59,0x67,0xE0,0xD4,0xD7,0xEC, | |
28 0x5E,0x56,0x5A,0x6D,0xE1,0xD6,0xD7,0xEA,0x4D,0x37,0x2F,0x3A,0xC2,0xA7,0xA3,0xB5, | |
29 0x2F,0x1C,0x1A,0x2D,0xA9,0x96,0x96,0xAE,0x22,0x12,0x14,0x31,0x9E,0x8F,0x94,0xB6, | |
30 0x1B,0x0D,0x0F,0x2C,0x9B,0x8C,0x8E,0xAB,0x17,0x09,0x0C,0x28,0x97,0x88,0x8A,0xA7, | |
31 0x15,0x07,0x0A,0x29,0x95,0x88,0x8B,0xAA,0x15,0x08,0x0B,0x2A,0x96,0x88,0x8B,0xAA, | |
32 0x15,0x09,0x0C,0x2A,0x97,0x89,0x8C,0xAA,0x17,0x0A,0x0D,0x2B,0x98,0x8A,0x8D,0xAB, | |
33 0x18,0x0A,0x0D,0x2A,0x99,0x8A,0x8D,0xAA,0x18,0x0A,0x0D,0x29,0x99,0x8A,0x8D,0xA9, | |
34 0x19,0x0A,0x0D,0x29,0x99,0x8A,0x8D,0xA9,0x19,0x0A,0x0D,0x29,0x99,0x8A,0x8D,0xA9, | |
35 0x19,0x0A,0x0D,0x28,0x99,0x8A,0x8C,0xA8,0x19,0x0A,0x0D,0x27,0x9A,0x8B,0x8D,0xA7, | |
36 }; | |
37 | |
38 static const uint8_t match_frame_amrefr_dec[160] = { | |
39 0x6F,0x66,0x66,0x6E,0xE5,0xDA,0xDD,0xF2,0x5F,0x5A,0x5E,0x76,0xE0,0xD8,0xDA,0xEF, | |
40 0x5E,0x59,0x5F,0xFC,0xE1,0xDF,0xE5,0xF5,0x61,0x59,0x5B,0x6B,0xDE,0xD4,0xD9,0xEF, | |
41 0x5D,0x56,0x5B,0x71,0xDF,0xD6,0xD8,0xEE,0x4D,0x38,0x31,0x3E,0xBD,0xA7,0xA5,0xB9, | |
42 0x2D,0x1C,0x1C,0x35,0xA5,0x96,0x98,0xB4,0x1F,0x12,0x17,0x3D,0x9C,0x90,0x96,0xC1, | |
43 0x1A,0x0E,0x12,0x38,0x98,0x8C,0x8F,0xB4,0x16,0x0A,0x0D,0x32,0x94,0x88,0x8C,0xAE, | |
44 0x13,0x08,0x0C,0x35,0x92,0x88,0x8C,0xB3,0x13,0x08,0x0D,0x35,0x93,0x88,0x8D,0xB3, | |
45 0x13,0x09,0x0D,0x34,0x94,0x89,0x8D,0xB3,0x15,0x0A,0x0E,0x35,0x96,0x8B,0x8E,0xB5, | |
46 0x16,0x0B,0x0E,0x32,0x97,0x8B,0x8E,0xB3,0x16,0x0A,0x0E,0x32,0x96,0x8A,0x8E,0xB1, | |
47 0x16,0x0B,0x0E,0x31,0x96,0x8B,0x8E,0xB1,0x16,0x0B,0x0E,0x31,0x97,0x8B,0x8E,0xB1, | |
48 0x16,0x0A,0x0E,0x30,0x97,0x8A,0x8E,0xAF,0x17,0x0B,0x0E,0x2F,0x97,0x8B,0x8E,0xAE, | |
49 }; | |
50 | |
51 enum state { | |
52 STATE_GROUND = 0, | |
53 STATE_FE, | |
54 STATE_EFR_PRELIM, | |
55 STATE_EFR_CLASSIC, | |
56 STATE_EFR_AMR, | |
57 STATE_FR, | |
58 }; | |
59 | |
60 static enum state state; | |
61 static unsigned fe_byte_count, match_pos; | |
62 | |
63 static void | |
64 report_match(name, offset) | |
65 char *name; | |
66 unsigned offset; | |
67 { | |
68 offset -= 319; | |
69 printf("Matched output of %s decoder\n", name); | |
70 printf("File offset: %u (0x%x), offset % 160 = %u\n", offset, offset, | |
71 offset % 160); | |
72 } | |
73 | |
74 static void | |
75 process_sample(samp, offset) | |
76 unsigned samp, offset; | |
77 { | |
78 if (samp == 0xFE) { | |
79 if (state != STATE_FE) { | |
80 state = STATE_FE; | |
81 fe_byte_count = 1; | |
82 } else if (fe_byte_count < 160) | |
83 fe_byte_count++; | |
84 return; | |
85 } | |
86 switch (state) { | |
87 case STATE_GROUND: | |
88 return; | |
89 case STATE_FE: | |
90 if (fe_byte_count < 160) { | |
91 state = STATE_GROUND; | |
92 return; | |
93 } | |
94 switch (samp) { | |
95 case 0x6F: | |
96 state = STATE_EFR_PRELIM; | |
97 return; | |
98 case 0xFF: | |
99 state = STATE_FR; | |
100 match_pos = 1; | |
101 return; | |
102 default: | |
103 state = STATE_GROUND; | |
104 } | |
105 return; | |
106 case STATE_EFR_PRELIM: | |
107 switch (samp) { | |
108 case 0x64: | |
109 state = STATE_EFR_CLASSIC; | |
110 match_pos = 2; | |
111 return; | |
112 case 0x66: | |
113 state = STATE_EFR_AMR; | |
114 match_pos = 2; | |
115 return; | |
116 default: | |
117 state = STATE_GROUND; | |
118 } | |
119 return; | |
120 case STATE_EFR_CLASSIC: | |
121 if (samp == match_frame_efr_classic[match_pos]) | |
122 match_pos++; | |
123 else { | |
124 state = STATE_GROUND; | |
125 return; | |
126 } | |
127 if (match_pos < 160) | |
128 return; | |
129 report_match("classic EFR", offset); | |
130 state = STATE_GROUND; | |
131 return; | |
132 case STATE_EFR_AMR: | |
133 if (samp == match_frame_amrefr_dec[match_pos]) | |
134 match_pos++; | |
135 else { | |
136 state = STATE_GROUND; | |
137 return; | |
138 } | |
139 if (match_pos < 160) | |
140 return; | |
141 report_match("AMR-EFR", offset); | |
142 state = STATE_GROUND; | |
143 return; | |
144 case STATE_FR: | |
145 if (samp == match_frame_fr[match_pos]) | |
146 match_pos++; | |
147 else { | |
148 state = STATE_GROUND; | |
149 return; | |
150 } | |
151 if (match_pos < 160) | |
152 return; | |
153 report_match("GSM-FR", offset); | |
154 state = STATE_GROUND; | |
155 return; | |
156 default: | |
157 state = STATE_GROUND; | |
158 } | |
159 } | |
160 | |
161 main(argc, argv) | |
162 char **argv; | |
163 { | |
164 FILE *inf; | |
165 unsigned offset; | |
166 int c; | |
167 | |
168 if (argc != 2) { | |
169 fprintf(stderr, "usage: %s pcmu-bin-file\n", argv[0]); | |
170 exit(1); | |
171 } | |
172 inf = fopen(argv[1], "r"); | |
173 if (!inf) { | |
174 perror(argv[1]); | |
175 exit(1); | |
176 } | |
177 for (offset = 0; ; offset++) { | |
178 c = getc(inf); | |
179 if (c < 0) | |
180 break; | |
181 process_sample(c, offset); | |
182 } | |
183 exit(0); | |
184 } |