annotate amrefr/decode-r.c @ 496:af70bf42eb1b

libgsmhr1: implement DHF const array
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 18 Jun 2024 00:15:46 +0000
parents 65d20172e92a
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 /*
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
2 * amrefr-decode-r is a counterpart to gsmefr-decode-r, implementing
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
3 * "alternative EFR" by way of libtwamr. Unlike standard gsmefr-decode-r,
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
4 * this version cannot handle SID frames in input: they are not explicitly
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
5 * checked for, but an input containing SIDs will not be decoded correctly.
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
100
d5bab777865a gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
11 #include "../libgsmefr/gsm_efr.h"
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
12 #include "../libtwamr/tw_amr.h"
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../libtest/binreader.h"
154
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
14 #include "../libtest/robewrite.h"
12
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 main(argc, argv)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char **argv;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
154
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
19 FILE *binf, *outf;
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
20 struct amr_decoder_state *state;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 uint8_t frame[BINFILE_MAX_FRAME];
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
22 struct amr_param_frame amr_frame;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int16_t pcm[160];
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
24 int rc, bfi;
12
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 if (argc != 3) {
154
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
27 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
28 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 binf = fopen(argv[1], "r");
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (!binf) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 perror(argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
154
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
35 outf = fopen(argv[2], "w");
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
36 if (!outf) {
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 perror(argv[2]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
40 state = amr_decoder_create();
100
d5bab777865a gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
41 if (!state) {
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
42 perror("amr_decoder_create()");
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
45 amr_frame.mode = 0x87;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 for (;;) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rc = binfile_read_frame(binf, frame);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (rc < 0) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "error: garbage in %s\n", argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!rc)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
54 if (frame[0] == 0xBF)
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 bfi = 1;
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
56 else if ((frame[0] & 0xF0) == 0xC0)
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 bfi = 0;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 else {
100
d5bab777865a gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
59 fprintf(stderr,
d5bab777865a gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
60 "error: %s is not in EFR codec format\n",
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (bfi)
439
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
65 amr_frame.type = RX_NO_DATA;
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
66 else {
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
67 amr_frame.type = RX_SPEECH_GOOD;
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
68 EFR_frame2params(frame, amr_frame.param);
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
69 }
65d20172e92a amrefr: implement amrefr-decode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
70 amr_decode_frame(state, &amr_frame, pcm);
154
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
71 write_pcm_to_robe(outf, pcm);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
154
01ce75ea1c8e gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
73 fclose(outf);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 exit(0);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }