annotate amrefr/encode-r.c @ 477:4c9222d95647

libtwamr encoder: always emit frame->mode = mode; In the original implementation of amr_encode_frame(), the 'mode' member of the output struct was set to 0xFF if the output frame type is TX_NO_DATA. This design was made to mimic the mode field (16-bit word) being set to 0xFFFF (or -1) in 3GPP test sequence format - but nothing actually depends on this struct member being set in any way, and amr_frame_to_tseq() generates the needed 0xFFFF on its own, based on frame->type being equal to TX_NO_DATA. It is simpler and more efficient to always set frame->mode to the actual encoding mode in amr_encode_frame(), and this new behavior has already been documented in doc/AMR-library-API description in anticipation of the present change.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 May 2024 22:30:42 +0000
parents 0c4e1bc06740
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
2 * amrefr-encode-r is a counterpart to gsmefr-encode-r, implementing
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
3 * "alternative EFR" by way of libtwamr. Unlike standard gsmefr-encode-r,
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
4 * there is no -d option and no DTX support in this version.
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
121
b51295fcbbae gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
10 #include <string.h>
b51295fcbbae gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
11 #include <strings.h>
b51295fcbbae gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
12 #include "../libgsmefr/gsm_efr.h"
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
13 #include "../libtwamr/tw_amr.h"
156
3f3674c27840 gsmefr-encode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
14 #include "../libtest/roberead.h"
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 main(argc, argv)
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char **argv;
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
156
3f3674c27840 gsmefr-encode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
19 FILE *inf, *binf;
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
20 struct amr_encoder_state *state;
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int16_t pcm[160];
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
22 struct amr_param_frame amr_frame;
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
23 uint8_t efr_frame[EFR_RTP_FRAME_LEN];
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
24 int rc;
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
26 if (argc != 3) {
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
27 fprintf(stderr, "usage: %s input.robe output.gsmx\n", argv[0]);
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
30 inf = fopen(argv[1], "r");
156
3f3674c27840 gsmefr-encode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
31 if (!inf) {
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
32 perror(argv[1]);
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
35 binf = fopen(argv[2], "w");
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (!binf) {
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
37 perror(argv[2]);
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
40 state = amr_encoder_create(0, 0);
121
b51295fcbbae gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
41 if (!state) {
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
42 perror("amr_encoder_create()");
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 exit(1);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 for (;;) {
156
3f3674c27840 gsmefr-encode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
46 rc = robe_get_pcm_block(inf, pcm);
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!rc)
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 break;
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
49 amr_encode_frame(state, MR122, pcm, &amr_frame);
466
0c4e1bc06740 amrefr-encode-r: use the new DHF xform that matches T-Mobile
Mychaela Falconia <falcon@freecalypso.org>
parents: 438
diff changeset
50 amr_dhf_subst_efr2(&amr_frame, pcm);
438
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
51 EFR_params2frame(amr_frame.param, efr_frame);
1bf1bbcef763 amrefr: implement amrefr-encode-r utility
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
52 fwrite(efr_frame, 1, sizeof efr_frame, binf);
14
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fclose(binf);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 exit(0);
69ed7af28473 gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }