annotate amrdiff/etsi-bit-rd.c @ 25:1f58ba0d79a4

pcmu2efr: brown paper bag
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 May 2024 04:34:15 +0000
parents a03c87a2abc6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The utility function in this module reads the bits from ETSI *.cod
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * files, both AMR and EFR versions, either LE or BE.
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "etsi.h"
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "amr_defs.h"
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs)
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 FILE *inf;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 uint8_t *bitvec;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned nwords;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *filename_for_errs;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 uint8_t file_bytes[COD_FORMAT_NWORDS * 2], *sp;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int cc;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 unsigned n, upper;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cc = fread(file_bytes, 2, nwords, inf);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (cc == 0)
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return 0;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (cc != nwords) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, "error: short read from %s\n",
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 filename_for_errs);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sp = file_bytes;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (n = 0; n < nwords; n++) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (big_endian) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 upper = sp[0];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 bitvec[n] = sp[1];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 } else {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 bitvec[n] = sp[0];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 upper = sp[1];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (upper && (sp[0] != 0xFF || sp[1] != 0xFF)) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 "error in %s: non-zero in what should be %s upper byte\n",
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 filename_for_errs, big_endian ? "BE" : "LE");
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 sp += 2;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return 1;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }