FreeCalypso > hg > gsm-codec-lib
annotate efrtest/etsi-bit-rd.c @ 491:45bf34451dd7
libgsmhr1: implement TW-TS-002 input
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 15 Jun 2024 06:22:21 +0000 |
parents | 8ed838709897 |
children |
rev | line source |
---|---|
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
2 * In this module we implement utility functions for reading ETSI *.cod |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
3 * and *.dec files 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> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "../libgsmefr/gsm_efr.h" |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
12 #include "etsi.h" |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
14 read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs) |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 FILE *inf; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 uint8_t *bitvec; |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
17 unsigned nwords; |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *filename_for_errs; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int cc; |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
22 unsigned n, upper; |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
24 cc = fread(file_bytes, 2, nwords, inf); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (cc == 0) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return 0; |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
27 if (cc != nwords) { |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error: short read from %s\n", |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 filename_for_errs); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 sp = file_bytes; |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
33 for (n = 0; n < nwords; n++) { |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
34 if (big_endian) { |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
35 upper = sp[0]; |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
36 bitvec[n] = sp[1]; |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
37 } else { |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
38 bitvec[n] = sp[0]; |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
39 upper = sp[1]; |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
40 } |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
41 if (upper) { |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 fprintf(stderr, |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
43 "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
|
44 filename_for_errs, big_endian ? "BE" : "LE"); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 exit(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 sp += 2; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return 1; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
52 void |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 bits2frame(input_bits, frame, filename_for_errs, frame_no) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 uint8_t *input_bits, *frame; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 char *filename_for_errs; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 unsigned frame_no; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 uint8_t bits[248], *sp, *dp; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 unsigned nb, byte, mask; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 bits[0] = 1; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 bits[1] = 1; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 bits[2] = 0; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 bits[3] = 0; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 bcopy(input_bits, bits + 4, 244); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 sp = bits; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 dp = frame; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 byte = 0; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 for (mask = 0x80; mask; mask >>= 1) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (*sp > 1) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fprintf(stderr, |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 "error in %s frame #%u: data bit > 1\n", |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 filename_for_errs, frame_no); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (*sp) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 byte |= mask; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 sp++; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 *dp++ = byte; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |