annotate frtest/decode-r.c @ 490:4d80730683d4

libgsmhr1: implement TS 101 318 packing and unpacking
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 15 Jun 2024 05:33:35 +0000
parents cfa3006a66da
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
2 * gsmfr-decode-r is like gsmfr-decode, but writes the decoded PCM
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
3 * output in our "robe" format instead of WAV.
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
285
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
9 #include "../libgsmfr2/tw_gsmfr.h"
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "../libtest/binreader.h"
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
11 #include "../libtest/robewrite.h"
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 main(argc, argv)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
16 FILE *binf, *outf;
285
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
17 struct gsmfr_fulldec_state *fd_state;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 uint8_t frame[BINFILE_MAX_FRAME];
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int16_t pcm[160];
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int rc, bfi, taf;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (argc != 3) {
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
23 fprintf(stderr, "usage: %s input.gsm output.robe\n", argv[0]);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 binf = fopen(argv[1], "r");
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!binf) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 perror(argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
31 outf = fopen(argv[2], "w");
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
32 if (!outf) {
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 perror(argv[2]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
285
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
36 fd_state = gsmfr_fulldec_create();
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
37 if (!fd_state) {
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
38 fprintf(stderr, "gsmfr_fulldec_create() failed!\n");
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 for (;;) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 rc = binfile_read_frame(binf, frame);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc < 0) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr, "error: garbage in %s\n", argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!rc)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 break;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (frame[0] == 0xBF) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 bfi = 1;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 taf = frame[1] & 1;
16
b9a842775f40 gsmfr-decode: trivial bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
52 } else if ((frame[0] & 0xF0) == 0xD0)
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 bfi = 0;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 else {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 fprintf(stderr, "error: %s is not in FR codec format\n",
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (bfi)
285
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
60 gsmfr_fulldec_bfi(fd_state, taf, pcm);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 else
285
cfa3006a66da gsmfr-decode-r: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 153
diff changeset
62 gsmfr_fulldec_good_frame(fd_state, frame, pcm);
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
63 write_pcm_to_robe(outf, pcm);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
153
14b627682458 gsmfr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
65 fclose(outf);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(0);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }