comparison test-voice/pcmu_catcher.c @ 16:4f81b959a5f5

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