FreeCalypso > hg > gsm-codec-lib
annotate efrtest/decode-r.c @ 178:5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 27 Dec 2022 06:44:29 +0000 |
parents | 01ce75ea1c8e |
children |
rev | line source |
---|---|
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
2 * gsmefr-decode-r is like gsmefr-decode, but writes the decoded PCM |
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
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> |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
9 #include "../libgsmefr/gsm_efr.h" |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "../libtest/binreader.h" |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
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 { |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
16 FILE *binf, *outf; |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
17 struct EFR_decoder_state *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) { |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
23 fprintf(stderr, "usage: %s input.gsmx 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 } |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
31 outf = fopen(argv[2], "w"); |
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
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 } |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
36 state = EFR_decoder_create(); |
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
37 if (!state) { |
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
38 perror("EFR_decoder_create()"); |
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; |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
52 } else if ((frame[0] & 0xF0) == 0xC0) |
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 { |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
55 fprintf(stderr, |
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
56 "error: %s is not in EFR codec format\n", |
12
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) |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
61 EFR_decode_bfi_nodata(state, taf, pcm); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 else |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
63 EFR_decode_frame(state, frame, 0, 0, pcm); |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
64 write_pcm_to_robe(outf, pcm); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
66 fclose(outf); |
12
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 } |