annotate miscutil/gsmrec-dump.c @ 42:ba044871c9dd

libgsmefr: beginning of encoder and decoder state structures
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 01:43:16 +0000
parents baadb1cb744d
children edd2e20e7090
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a binary file in our extended-libgsm format
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and dumps all frames in human-readable form.
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <gsm.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "../libtest/binreader.h"
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 main(argc, argv)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char **argv;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 FILE *binf;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 gsm dummy_state;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned frame_index;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 uint8_t frame[BINFILE_MAX_FRAME];
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 gsm_signal fr_params[76];
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int rc, i, j, n;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (argc != 2) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 fprintf(stderr, "usage: %s bin-stream-file\n", argv[0]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 binf = fopen(argv[1], "r");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!binf) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 perror(argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 dummy_state = gsm_create();
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!dummy_state) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr, "gsm_create() failed!\n");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 for (frame_index = 0; ; frame_index++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 rc = binfile_read_frame(binf, frame);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (rc < 0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fprintf(stderr, "error: garbage in %s\n", argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (!rc)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 printf("#%u: ", frame_index);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 switch (frame[0] & 0xF0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 case 0xB0:
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 printf("BFI TAF=%u\n", frame[1] & 1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 case 0xC0:
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 puts("EFR (decoding not implemented)");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 case 0xD0:
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fputs("FR", stdout);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 gsm_explode(dummy_state, frame, fr_params);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 n = 0;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 for (i = 0; i < 8; i++)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 printf(" %u", fr_params[n++]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 putchar('\n');
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 for (i = 0; i < 4; i++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 putchar(' ');
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 for (j = 0; j < 17; j++)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 printf(" %u", fr_params[n++]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 putchar('\n');
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 exit(0);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }