comparison frtest/dlcap-sync.c @ 474:285381a001fc

new program gsmfr-dlcap-sync
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 15 May 2024 06:20:59 +0000
parents efrtest/dlcap-sync.c@d80ccb3c3970
children
comparison
equal deleted inserted replaced
473:2d46abdfbe91 474:285381a001fc
1 /*
2 * This program reads a TCH/FS downlink capture file from a FreeCalypso GSM MS
3 * that was produced in a session in which seqsync PCMA or PCMU input
4 * (seqsyn_[au].inp) was fed into the test call from IP-PSTN side. It looks
5 * for FRv1 DHF followed by specific frame patterns given by ETSI in
6 * syn???_[au].cod files, and reports what it finds. Matches indicate
7 * a particular alignment between the input sequence and encoder frame
8 * boundaries, if the network speech transcoder implements the encoder
9 * homing feature which is optional for FRv1.
10 */
11
12 #include <ctype.h>
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <strings.h>
18 #include "../libgsmfr2/tw_gsmfr.h"
19
20 extern const uint8_t sync_from_pcma[160*33];
21 extern const uint8_t sync_from_pcmu[160*33];
22
23 static int
24 check_for_match(input, table)
25 const uint8_t *input, *table;
26 {
27 unsigned n;
28
29 for (n = 0; n < 160; n++) {
30 if (!bcmp(input, table + n * 33, 33))
31 return n;
32 }
33 return -1;
34 }
35
36 main(argc, argv)
37 char **argv;
38 {
39 FILE *inf;
40 char linebuf[128];
41 int lineno, rc;
42 uint16_t status_words[3];
43 uint8_t tidsp_bytes[33], libgsm_bytes[33];
44 const uint8_t *match_table;
45 int dhf_state;
46
47 if (argc != 3) {
48 usage: fprintf(stderr, "usage: %s dlcap-file alaw|ulaw\n", argv[0]);
49 exit(1);
50 }
51 inf = fopen(argv[1], "r");
52 if (!inf) {
53 perror(argv[1]);
54 exit(1);
55 }
56 if (!strcmp(argv[2], "alaw"))
57 match_table = sync_from_pcma;
58 else if (!strcmp(argv[2], "ulaw"))
59 match_table = sync_from_pcmu;
60 else
61 goto usage;
62 dhf_state = 0;
63 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
64 /* support both old and new formats */
65 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) &&
66 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) {
67 rc = parse_dlcap_common(linebuf, status_words,
68 tidsp_bytes);
69 if (rc < 0) {
70 invalid: fprintf(stderr,
71 "error: %s is not in the expected format\n",
72 argv[1]);
73 exit(1);
74 }
75 } else if (!strncmp(linebuf, "FR ", 3)) {
76 rc = parse_dlcap_common(linebuf + 3, status_words,
77 tidsp_bytes);
78 if (rc < 0)
79 goto invalid;
80 if (linebuf[84] != ' ')
81 goto invalid;
82 if (!isdigit(linebuf[85]))
83 goto invalid;
84 } else
85 goto invalid;
86 if ((status_words[0] & 0xC004) != 0xC000) {
87 dhf_state = 0;
88 continue;
89 }
90 gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes);
91 if (!bcmp(libgsm_bytes, gsmfr_decoder_homing_frame, 33)) {
92 dhf_state = 1;
93 continue;
94 }
95 if (!dhf_state)
96 continue;
97 rc = check_for_match(libgsm_bytes, match_table);
98 if (rc >= 0 && rc <= 159) {
99 printf(
100 "line %d: match to expected sync frame for offset %d\n",
101 lineno, rc);
102 }
103 dhf_state = 0;
104 }
105 exit(0);
106 }