comparison frtest/cod2std.c @ 283:25649b3a83e9

gsmfr-cod2std: convert to libgsmfr2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 05:51:42 +0000
parents 6de564ef70d3
children
comparison
equal deleted inserted replaced
282:9ee8ad3d4d30 283:25649b3a83e9
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <strings.h> 10 #include <strings.h>
11 #include <gsm.h> 11 #include "../libgsmfr2/tw_gsmfr.h"
12 12
13 static void 13 static void
14 bytes_to_params(bytes, params, big_endian) 14 bytes_to_params(bytes, params, big_endian)
15 uint8_t *bytes; 15 uint8_t *bytes;
16 gsm_signal *params; 16 int16_t *params;
17 { 17 {
18 uint8_t *sp; 18 uint8_t *sp;
19 unsigned n; 19 unsigned n;
20 uint16_t val; 20 uint16_t val;
21 21
33 main(argc, argv) 33 main(argc, argv)
34 char **argv; 34 char **argv;
35 { 35 {
36 char *infname, *outfname; 36 char *infname, *outfname;
37 FILE *inf, *outf; 37 FILE *inf, *outf;
38 gsm dummy_state;
39 int big_endian; 38 int big_endian;
40 unsigned frame_no; 39 unsigned frame_no;
41 uint8_t input_bytes[76*2], frame[33]; 40 uint8_t input_bytes[76*2], frame[33];
42 gsm_signal params[76]; 41 int16_t params[76];
43 int cc; 42 int cc;
44 43
45 if (argc == 3 && argv[1][0] != '-') { 44 if (argc == 3 && argv[1][0] != '-') {
46 big_endian = 0; 45 big_endian = 0;
47 infname = argv[1]; 46 infname = argv[1];
63 outf = fopen(outfname, "w"); 62 outf = fopen(outfname, "w");
64 if (!outf) { 63 if (!outf) {
65 perror(outfname); 64 perror(outfname);
66 exit(1); 65 exit(1);
67 } 66 }
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++) { 67 for (frame_no = 0; ; frame_no++) {
74 cc = fread(input_bytes, 2, 76, inf); 68 cc = fread(input_bytes, 2, 76, inf);
75 if (cc == 0) 69 if (cc == 0)
76 break; 70 break;
77 if (cc != 76) { 71 if (cc != 76) {
78 fprintf(stderr, "error: short read from %s\n", infname); 72 fprintf(stderr, "error: short read from %s\n", infname);
79 exit(1); 73 exit(1);
80 } 74 }
81 bytes_to_params(input_bytes, params, big_endian); 75 bytes_to_params(input_bytes, params, big_endian);
82 gsm_implode(dummy_state, params, frame); 76 gsmfr_pack_from_array(params, frame);
83 fwrite(frame, 1, sizeof frame, outf); 77 fwrite(frame, 1, sizeof frame, outf);
84 } 78 }
85 fclose(outf); 79 fclose(outf);
86 exit(0); 80 exit(0);
87 } 81 }