comparison efrtest/cod-parse.c @ 115:5a63294fa321

gsmefr-cod-parse test program written
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 29 Nov 2022 22:18:33 +0000
parents
children a5ffec18e4cd
comparison
equal deleted inserted replaced
114:ff0372186b59 115:5a63294fa321
1 /*
2 * This program reads an EFR *.cod file in ETSI test sequence format
3 * (output from either ETSI's official coder program or our gsmefr-etsi-enc)
4 * and converts it into human-readable format, similar to what one would get
5 * from our gsmrec-dump utility.
6 */
7
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include "../libgsmefr/gsm_efr.h"
14
15 #define ETSI_ENC_NWORDS 246
16
17 static int
18 read_input(inf, bitvec, filename_for_errs)
19 FILE *inf;
20 uint8_t *bitvec;
21 char *filename_for_errs;
22 {
23 uint8_t file_bytes[ETSI_ENC_NWORDS * 2], *sp;
24 int cc;
25 unsigned n;
26
27 cc = fread(file_bytes, 2, ETSI_ENC_NWORDS, inf);
28 if (cc == 0)
29 return 0;
30 if (cc != ETSI_ENC_NWORDS) {
31 fprintf(stderr, "error: short read from %s\n",
32 filename_for_errs);
33 exit(1);
34 }
35 sp = file_bytes;
36 for (n = 0; n < ETSI_ENC_NWORDS; n++) {
37 if (sp[1]) {
38 fprintf(stderr,
39 "error in %s: non-zero in what should be LE upper byte\n",
40 filename_for_errs);
41 exit(1);
42 }
43 bitvec[n] = sp[0];
44 sp += 2;
45 }
46 return 1;
47 }
48
49 static void
50 bits2frame(input_bits, frame, filename_for_errs, frame_no)
51 uint8_t *input_bits, *frame;
52 char *filename_for_errs;
53 unsigned frame_no;
54 {
55 uint8_t bits[248], *sp, *dp;
56 unsigned nb, byte, mask;
57
58 bits[0] = 1;
59 bits[1] = 1;
60 bits[2] = 0;
61 bits[3] = 0;
62 bcopy(input_bits, bits + 4, 244);
63 sp = bits;
64 dp = frame;
65 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) {
66 byte = 0;
67 for (mask = 0x80; mask; mask >>= 1) {
68 if (*sp > 1) {
69 fprintf(stderr,
70 "error in %s frame #%u: data bit > 1\n",
71 filename_for_errs, frame_no);
72 exit(1);
73 }
74 if (*sp)
75 byte |= mask;
76 sp++;
77 }
78 *dp++ = byte;
79 }
80 }
81
82 main(argc, argv)
83 char **argv;
84 {
85 FILE *inf;
86 unsigned frame_no;
87 uint8_t input_bits[ETSI_ENC_NWORDS], frame[EFR_RTP_FRAME_LEN];
88 int16_t params[EFR_NUM_PARAMS];
89 int rc, i, j, n;
90
91 if (argc != 2) {
92 fprintf(stderr, "usage: %s file.cod\n", argv[0]);
93 exit(1);
94 }
95 inf = fopen(argv[1], "r");
96 if (!inf) {
97 perror(argv[1]);
98 exit(1);
99 }
100 for (frame_no = 0; ; frame_no++) {
101 rc = read_input(inf, input_bits, argv[1]);
102 if (!rc)
103 break;
104 bits2frame(input_bits, frame, argv[1], frame_no);
105 printf("#%u: VAD=%u SP=%u SID=%d LPC", frame_no,
106 input_bits[244], input_bits[245],
107 EFR_sid_classify(frame));
108 EFR_frame2params(frame, params);
109 n = 0;
110 for (i = 0; i < 5; i++)
111 printf(" %u", params[n++]);
112 putchar('\n');
113 for (i = 0; i < 4; i++) {
114 putchar(' ');
115 for (j = 0; j < 13; j++)
116 printf(" %u", params[n++]);
117 putchar('\n');
118 }
119 }
120 }