comparison efrtest/dec-parse.c @ 131:615f144b52c6

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