annotate frtest/decode.c @ 539:0daaae66b3f6

libtest: add TW-TS-005 write helper function
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 22 Sep 2024 00:21:16 +0000
parents 8d3cfa65a6c2
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 /*
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This file is the main module for gsmfr-decode utility.
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
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 #include <stdio.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdint.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
8 #include "../libgsmfr2/tw_gsmfr.h"
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "../libtest/binreader.h"
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "../libtest/wavwriter.h"
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libtest/pcmwrite.h"
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 {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *binf;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 void *wav;
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
18 struct gsmfr_fulldec_state *fd_state;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 uint8_t frame[BINFILE_MAX_FRAME];
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int16_t pcm[160];
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int rc, bfi, taf;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (argc != 3) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "usage: %s input.gsm output.wav\n", argv[0]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 binf = fopen(argv[1], "r");
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!binf) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 perror(argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 wav = wav_write_open(argv[2], 8000, 16, 1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!wav) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 perror(argv[2]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
37 fd_state = gsmfr_fulldec_create();
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
38 if (!fd_state) {
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
39 fprintf(stderr, "gsmfr_fulldec_create() failed!\n");
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 for (;;) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 rc = binfile_read_frame(binf, frame);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (rc < 0) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr, "error: garbage in %s\n", argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!rc)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 break;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (frame[0] == 0xBF) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 bfi = 1;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 taf = frame[1] & 1;
16
b9a842775f40 gsmfr-decode: trivial bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 12
diff changeset
53 } else if ((frame[0] & 0xF0) == 0xD0)
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 bfi = 0;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 else {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 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
57 argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (bfi)
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
61 gsmfr_fulldec_bfi(fd_state, taf, pcm);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 else
284
8d3cfa65a6c2 gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
63 gsmfr_fulldec_good_frame(fd_state, frame, pcm);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 write_pcm_to_wav(wav, pcm);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 wav_write_close(wav);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 exit(0);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }