annotate efrtest/cod-parse.c @ 142:578fdedf4327

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