annotate frtest/decode-tw5-r.c @ 538:4d596bfdf8d9

frtest: new program gsmfr-decode-tw5-r
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 21 Sep 2024 23:58:27 +0000
parents frtest/decode-tw5.c@f9eefb61fb2f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
2 * This file is the main module for gsmfr-decode-tw5-r utility. It is just
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
3 * like the original gsmfr-decode-r, but reads the GSM-FR speech recording
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
4 * from TW-TS-005 Annex A hexadecimal format instead of the old gsmx
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
5 * binary format. The output format is robe, as indicated by the -r suffix.
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
11 #include "../libgsmfr2/tw_gsmfr.h"
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
12 #include "../libtest/tw5reader.h"
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
13 #include "../libtest/robewrite.h"
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
18 FILE *hexf, *outf;
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
19 unsigned lineno;
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
20 struct gsmfr_fulldec_state *fd_state;
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
21 uint8_t frame[TWTS005_MAX_FRAME];
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
22 unsigned frame_len;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int16_t pcm[160];
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
24 int rc;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (argc != 3) {
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
27 fprintf(stderr, "usage: %s input.hex output.robe\n", argv[0]);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
30 hexf = fopen(argv[1], "r");
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
31 if (!hexf) {
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 perror(argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
35 lineno = 0;
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
36 outf = fopen(argv[2], "w");
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
37 if (!outf) {
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 perror(argv[2]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
41 fd_state = gsmfr_fulldec_create();
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
42 if (!fd_state) {
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
43 fprintf(stderr, "gsmfr_fulldec_create() failed!\n");
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 for (;;) {
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
47 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (rc < 0) {
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
49 fprintf(stderr, "%s line %u: not valid TW-TS-005\n",
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
50 argv[1], lineno);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (!rc)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 break;
537
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
55 rc = gsmfr_fulldec_rtp_in(fd_state, frame, frame_len, pcm);
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
56 if (rc < 0) {
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
57 fprintf(stderr,
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
58 "%s line %u: not a valid GSM-FR frame\n",
f9eefb61fb2f frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 284
diff changeset
59 argv[1], lineno);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
62 write_pcm_to_robe(outf, pcm);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
538
4d596bfdf8d9 frtest: new program gsmfr-decode-tw5-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
64 fclose(outf);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(0);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }