annotate amrconv/cod-read.c @ 384:a8dab7028e4d

libtwamr: integrate lag_wind.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 05:56:50 +0000
parents 0beafaa0623f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
2 * In this module we implement utility functions for reading ETSI/3GPP
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
3 * *.cod files (AMR version) in either LE or BE format.
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
9 #include "amr_defs.h"
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
11 read_cod_bits(inf, big_endian, bitvec, filename_for_errs)
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 FILE *inf;
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 uint8_t *bitvec;
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *filename_for_errs;
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
16 uint8_t file_bytes[COD_FORMAT_NWORDS * 2], *sp;
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int cc;
145
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
18 unsigned n, upper;
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
20 cc = fread(file_bytes, 2, COD_FORMAT_NWORDS, inf);
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (cc == 0)
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return 0;
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
23 if (cc != COD_FORMAT_NWORDS) {
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "error: short read from %s\n",
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 filename_for_errs);
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 sp = file_bytes;
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
29 for (n = 0; n < COD_FORMAT_NWORDS; n++) {
145
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
30 if (big_endian) {
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
31 upper = sp[0];
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
32 bitvec[n] = sp[1];
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
33 } else {
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
34 bitvec[n] = sp[0];
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
35 upper = sp[1];
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
36 }
212
0beafaa0623f amr-cod-parse: handle Mode=-1 in NO_DATA frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
37 if (upper && (sp[0] != 0xFF || sp[1] != 0xFF)) {
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 fprintf(stderr,
145
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
39 "error in %s: non-zero in what should be %s upper byte\n",
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
40 filename_for_errs, big_endian ? "BE" : "LE");
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 exit(1);
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 sp += 2;
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 return 1;
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
145
8ed838709897 efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents: 97
diff changeset
48 void
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
49 preen_frame_bits(input_bits, nbits, filename_for_errs, frame_no)
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
50 uint8_t *input_bits;
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 char *filename_for_errs;
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
52 unsigned nbits, frame_no;
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
54 uint8_t *sp;
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
55 unsigned nb;
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
57 sp = input_bits;
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
58 for (nb = 0; nb < nbits; nb++) {
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
59 if (*sp > 1) {
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
60 fprintf(stderr, "error in %s frame #%u: data bit > 1\n",
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
61 filename_for_errs, frame_no);
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
62 exit(1);
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
211
78d1a6513393 amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
64 sp++;
96
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
9cf1355bc071 gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }