comparison frtest/cod2std.c @ 245:6de564ef70d3

frtest: new program gsmfr-cod2std
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 09 May 2023 22:32:48 +0000
parents
children 25649b3a83e9
comparison
equal deleted inserted replaced
244:fcc0887ff0d0 245:6de564ef70d3
1 /*
2 * This program reads an FR codec parameters file in ETSI *.cod test sequence
3 * format and converts it into classic libgsm 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 <gsm.h>
12
13 static void
14 bytes_to_params(bytes, params, big_endian)
15 uint8_t *bytes;
16 gsm_signal *params;
17 {
18 uint8_t *sp;
19 unsigned n;
20 uint16_t val;
21
22 sp = bytes;
23 for (n = 0; n < 76; n++) {
24 if (big_endian)
25 val = ((uint16_t) sp[0] << 8) | ((uint16_t) sp[1]);
26 else
27 val = ((uint16_t) sp[1] << 8) | ((uint16_t) sp[0]);
28 params[n] = val;
29 sp += 2;
30 }
31 }
32
33 main(argc, argv)
34 char **argv;
35 {
36 char *infname, *outfname;
37 FILE *inf, *outf;
38 gsm dummy_state;
39 int big_endian;
40 unsigned frame_no;
41 uint8_t input_bytes[76*2], frame[33];
42 gsm_signal params[76];
43 int cc;
44
45 if (argc == 3 && argv[1][0] != '-') {
46 big_endian = 0;
47 infname = argv[1];
48 outfname = argv[2];
49 } else if (argc == 4 && !strcmp(argv[1], "-b")) {
50 big_endian = 1;
51 infname = argv[2];
52 outfname = argv[3];
53 } else {
54 fprintf(stderr, "usage: %s [-b] input.cod output.gsm\n",
55 argv[0]);
56 exit(1);
57 }
58 inf = fopen(infname, "r");
59 if (!inf) {
60 perror(infname);
61 exit(1);
62 }
63 outf = fopen(outfname, "w");
64 if (!outf) {
65 perror(outfname);
66 exit(1);
67 }
68 dummy_state = gsm_create();
69 if (!dummy_state) {
70 fprintf(stderr, "gsm_create() failed!\n");
71 exit(1);
72 }
73 for (frame_no = 0; ; frame_no++) {
74 cc = fread(input_bytes, 2, 76, inf);
75 if (cc == 0)
76 break;
77 if (cc != 76) {
78 fprintf(stderr, "error: short read from %s\n", infname);
79 exit(1);
80 }
81 bytes_to_params(input_bytes, params, big_endian);
82 gsm_implode(dummy_state, params, frame);
83 fwrite(frame, 1, sizeof frame, outf);
84 }
85 fclose(outf);
86 exit(0);
87 }