FreeCalypso > hg > gsm-codec-lib
comparison efrtest/dec-parse.c @ 146:0fa0cd251a31
gsmefr-dec-parse: use factored-out ETSI bit reader
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Dec 2022 08:05:08 +0000 |
parents | 615f144b52c6 |
children | 95d47a34070a |
comparison
equal
deleted
inserted
replaced
145:8ed838709897 | 146:0fa0cd251a31 |
---|---|
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include <strings.h> | 11 #include <strings.h> |
12 #include "../libgsmefr/gsm_efr.h" | 12 #include "../libgsmefr/gsm_efr.h" |
13 | 13 #include "etsi.h" |
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 | 14 |
81 main(argc, argv) | 15 main(argc, argv) |
82 char **argv; | 16 char **argv; |
83 { | 17 { |
84 FILE *inf; | 18 FILE *inf; |
95 if (!inf) { | 29 if (!inf) { |
96 perror(argv[1]); | 30 perror(argv[1]); |
97 exit(1); | 31 exit(1); |
98 } | 32 } |
99 for (frame_no = 0; ; frame_no++) { | 33 for (frame_no = 0; ; frame_no++) { |
100 rc = read_input(inf, input_bits, argv[1]); | 34 rc = read_etsi_bits(inf, 0, input_bits, ETSI_DEC_NWORDS, |
35 argv[1]); | |
101 if (!rc) | 36 if (!rc) |
102 break; | 37 break; |
103 bits2frame(input_bits + 1, frame, argv[1], frame_no); | 38 bits2frame(input_bits + 1, frame, argv[1], frame_no); |
104 printf("#%u: BFI=%u SID=%u TAF=%u LPC", frame_no, | 39 printf("#%u: BFI=%u SID=%u TAF=%u LPC", frame_no, |
105 input_bits[0], input_bits[245], input_bits[246]); | 40 input_bits[0], input_bits[245], input_bits[246]); |