annotate frtest/dlcap-sync.c @ 478:936a08cc73ce

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