comparison frtest/preproc.c @ 24:94f18b720f1e

new debug utility gsmfr-preproc
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 20 Nov 2022 08:30:07 +0000
parents frtest/decode.c@b9a842775f40
children b722fcb52926
comparison
equal deleted inserted replaced
23:baadb1cb744d 24:94f18b720f1e
1 /*
2 * This utility reads an extended-libgsm file that may contain SID frames
3 * and BFI markers, passes it through our preprocessor and writes out
4 * pure libgsm frames.
5 */
6
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include "../libgsmfrp/gsm_fr_preproc.h"
11 #include "../libtest/binreader.h"
12
13 main(argc, argv)
14 char **argv;
15 {
16 FILE *bini, *bino;
17 struct gsmfr_preproc_state *pp_state;
18 uint8_t frame[BINFILE_MAX_FRAME];
19 int rc, bfi, taf;
20
21 if (argc != 3) {
22 fprintf(stderr, "usage: %s input.gsm output.gsm\n", argv[0]);
23 exit(1);
24 }
25 bini = fopen(argv[1], "r");
26 if (!bini) {
27 perror(argv[1]);
28 exit(1);
29 }
30 bino = fopen(argv[2], "w");
31 if (!bino) {
32 perror(argv[2]);
33 exit(1);
34 }
35 pp_state = gsmfr_preproc_create();
36 if (!pp_state) {
37 fprintf(stderr, "gsmfr_preproc_create() failed!\n");
38 exit(1);
39 }
40 for (;;) {
41 rc = binfile_read_frame(bini, frame);
42 if (rc < 0) {
43 fprintf(stderr, "error: garbage in %s\n", argv[1]);
44 exit(1);
45 }
46 if (!rc)
47 break;
48 if (frame[0] == 0xBF) {
49 bfi = 1;
50 taf = frame[1] & 1;
51 } else if ((frame[0] & 0xF0) == 0xD0)
52 bfi = 0;
53 else {
54 fprintf(stderr, "error: %s is not in FR codec format\n",
55 argv[1]);
56 exit(1);
57 }
58 if (bfi)
59 gsmfr_preproc_bfi(pp_state, taf, frame);
60 else
61 gsmfr_preproc_good_frame(pp_state, frame);
62 fwrite(frame, 1, 33, bino);
63 }
64 fclose(bino);
65 exit(0);
66 }