annotate trau-ul-prep/efrdec2tsrc.c @ 41:b5feb04b212c

top Makefile: add v110 subdir
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Sep 2024 21:56:29 +0000
parents 8957383370c5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads an EFR *.dec file in ETSI test sequence format
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and converts it into ASCII source for TRAU-UL construction.
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <unistd.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <gsm_efr.h>
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "etsi.h"
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *infname, *outfname;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 FILE *inf, *outf;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int big_endian = 0;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned frame_no;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 uint8_t input_bits[ETSI_DEC_NWORDS], frame[EFR_RTP_FRAME_LEN];
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int16_t params[EFR_NUM_PARAMS];
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int rc, i, j, n;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern int optind;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 while ((rc = getopt(argc, argv, "b")) != EOF) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 switch (rc) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 case 'b':
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 big_endian = 1;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 continue;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 default:
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 usage:
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr,
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 "usage: %s [-b] input.dec [output.tsrc]\n",
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 argv[0]);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (argc < optind + 1 || argc > optind + 2)
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 goto usage;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 infname = argv[optind];
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 outfname = argv[optind+1];
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 inf = fopen(infname, "r");
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!inf) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 perror(infname);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(1);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (outfname) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 outf = fopen(outfname, "w");
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!outf) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 perror(outfname);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(1);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 } else
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 outf = stdout;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 for (frame_no = 0; ; frame_no++) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 rc = read_etsi_bits(inf, big_endian, input_bits,
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 ETSI_DEC_NWORDS, infname);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!rc)
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 break;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 bits2frame(input_bits + 1, frame, infname, frame_no);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 fprintf(outf, "# input frame %u\nFrame_EFR {\n", frame_no);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (input_bits[246])
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 fputs("\t# TAF position\n", outf);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(outf, "\tBFI %u\n", input_bits[0]);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 EFR_frame2params(frame, params);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 n = 0;
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 fputs("\tLPC", outf);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 for (i = 0; i < 5; i++)
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 fprintf(outf, " %d", params[n++]);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 putc('\n', outf);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 for (i = 0; i < 4; i++) {
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fputs("\tsf", outf);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 for (j = 0; j < 13; j++)
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(outf, " %d", params[n++]);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 putc('\n', outf);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(outf, "\tSID %u\n", input_bits[245]);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 fputs("}\n\n", outf);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exit(0);
8957383370c5 trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }