comparison frtest/decode-r.c @ 153:14b627682458

gsmfr-decode-r utility put together
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Dec 2022 23:11:20 +0000
parents frtest/decode.c@b9a842775f40
children cfa3006a66da
comparison
equal deleted inserted replaced
152:a217a6eacbad 153:14b627682458
1 /*
2 * gsmfr-decode-r is like gsmfr-decode, but writes the decoded PCM
3 * output in our "robe" format instead of WAV.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <gsm.h>
10 #include "../libgsmfrp/gsm_fr_preproc.h"
11 #include "../libtest/binreader.h"
12 #include "../libtest/robewrite.h"
13
14 main(argc, argv)
15 char **argv;
16 {
17 FILE *binf, *outf;
18 gsm dec_state;
19 struct gsmfr_preproc_state *pp_state;
20 uint8_t frame[BINFILE_MAX_FRAME];
21 int16_t pcm[160];
22 int rc, bfi, taf;
23
24 if (argc != 3) {
25 fprintf(stderr, "usage: %s input.gsm output.robe\n", argv[0]);
26 exit(1);
27 }
28 binf = fopen(argv[1], "r");
29 if (!binf) {
30 perror(argv[1]);
31 exit(1);
32 }
33 outf = fopen(argv[2], "w");
34 if (!outf) {
35 perror(argv[2]);
36 exit(1);
37 }
38 dec_state = gsm_create();
39 if (!dec_state) {
40 fprintf(stderr, "gsm_create() failed!\n");
41 exit(1);
42 }
43 pp_state = gsmfr_preproc_create();
44 if (!pp_state) {
45 fprintf(stderr, "gsmfr_preproc_create() failed!\n");
46 exit(1);
47 }
48 for (;;) {
49 rc = binfile_read_frame(binf, frame);
50 if (rc < 0) {
51 fprintf(stderr, "error: garbage in %s\n", argv[1]);
52 exit(1);
53 }
54 if (!rc)
55 break;
56 if (frame[0] == 0xBF) {
57 bfi = 1;
58 taf = frame[1] & 1;
59 } else if ((frame[0] & 0xF0) == 0xD0)
60 bfi = 0;
61 else {
62 fprintf(stderr, "error: %s is not in FR codec format\n",
63 argv[1]);
64 exit(1);
65 }
66 if (bfi)
67 gsmfr_preproc_bfi(pp_state, taf, frame);
68 else
69 gsmfr_preproc_good_frame(pp_state, frame);
70 gsm_decode(dec_state, frame, pcm);
71 write_pcm_to_robe(outf, pcm);
72 }
73 fclose(outf);
74 exit(0);
75 }