FreeCalypso > hg > gsm-codec-lib
comparison hrutil/hex2dec.c @ 565:ec146b5b9c91
hrutil: new program gsmhr-hex2dec
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Feb 2025 01:12:22 +0000 |
parents | hrutil/tw5b-dump.c@707d6f7a54dc |
children |
comparison
equal
deleted
inserted
replaced
564:30c57cf6e87d | 565:ec146b5b9c91 |
---|---|
1 /* | |
2 * This program reads a TW-TS-005 Annex B hexadecimal file and converts it | |
3 * to ETSI *.dec GSM-HR decoder input format. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <unistd.h> | |
12 #include "../libgsmhr1/tw_gsmhr.h" | |
13 #include "../libtest/tw5reader.h" | |
14 | |
15 main(argc, argv) | |
16 char **argv; | |
17 { | |
18 char *infname, *outfname; | |
19 FILE *inf, *outf; | |
20 int opt, rc, allow_bfi_nodata = 0; | |
21 unsigned lineno; | |
22 uint8_t frame[TWTS005_MAX_FRAME]; | |
23 unsigned frame_len; | |
24 int16_t params[GSMHR_NUM_PARAMS_DEC]; | |
25 extern int optind; | |
26 | |
27 while ((opt = getopt(argc, argv, "f")) != EOF) { | |
28 switch (opt) { | |
29 case 'f': | |
30 allow_bfi_nodata = 1; | |
31 continue; | |
32 default: | |
33 usage: | |
34 fprintf(stderr, "usage: %s [-f] input.hex output.dec\n", | |
35 argv[0]); | |
36 exit(1); | |
37 } | |
38 } | |
39 if (argc != optind + 2) | |
40 goto usage; | |
41 infname = argv[optind]; | |
42 outfname = argv[optind+1]; | |
43 | |
44 inf = fopen(infname, "r"); | |
45 if (!inf) { | |
46 perror(infname); | |
47 exit(1); | |
48 } | |
49 outf = fopen(outfname, "w"); | |
50 if (!outf) { | |
51 perror(outfname); | |
52 exit(1); | |
53 } | |
54 | |
55 lineno = 0; | |
56 for (;;) { | |
57 rc = twts005_read_frame(inf, &lineno, frame, &frame_len); | |
58 if (rc < 0) { | |
59 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
60 infname, lineno); | |
61 exit(1); | |
62 } | |
63 if (!rc) | |
64 break; | |
65 rc = gsmhr_rtp_in_direct(frame, frame_len, params); | |
66 if (rc < 0) { | |
67 fprintf(stderr, | |
68 "%s line %u: not a valid GSM-HR frame\n", | |
69 infname, lineno); | |
70 exit(1); | |
71 } | |
72 if (params[18] == 2 && !allow_bfi_nodata) { | |
73 fprintf(stderr, "%s line %u: BFI-no-data not allowed\n", | |
74 infname, lineno); | |
75 exit(1); | |
76 } | |
77 fwrite(params, 2, GSMHR_NUM_PARAMS_DEC, outf); | |
78 } | |
79 exit(0); | |
80 } |