FreeCalypso > hg > gsm-codec-lib
comparison efrtest/etsi-dec.c @ 145:8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Dec 2022 08:02:00 +0000 |
parents | e5ee684c6d29 |
children | da17c7f02c6c |
comparison
equal
deleted
inserted
replaced
144:30c7bc064218 | 145:8ed838709897 |
---|---|
12 #include <stdint.h> | 12 #include <stdint.h> |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <strings.h> | 15 #include <strings.h> |
16 #include "../libgsmefr/gsm_efr.h" | 16 #include "../libgsmefr/gsm_efr.h" |
17 | 17 #include "etsi.h" |
18 #define ETSI_DEC_NWORDS 247 | |
19 | |
20 static int | |
21 read_input(inf, bitvec, filename_for_errs) | |
22 FILE *inf; | |
23 uint8_t *bitvec; | |
24 char *filename_for_errs; | |
25 { | |
26 uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp; | |
27 int cc; | |
28 unsigned n; | |
29 | |
30 cc = fread(file_bytes, 2, ETSI_DEC_NWORDS, inf); | |
31 if (cc == 0) | |
32 return 0; | |
33 if (cc != ETSI_DEC_NWORDS) { | |
34 fprintf(stderr, "error: short read from %s\n", | |
35 filename_for_errs); | |
36 exit(1); | |
37 } | |
38 sp = file_bytes; | |
39 for (n = 0; n < ETSI_DEC_NWORDS; n++) { | |
40 if (sp[1]) { | |
41 fprintf(stderr, | |
42 "error in %s: non-zero in what should be LE upper byte\n", | |
43 filename_for_errs); | |
44 exit(1); | |
45 } | |
46 bitvec[n] = sp[0]; | |
47 sp += 2; | |
48 } | |
49 return 1; | |
50 } | |
51 | |
52 static void | |
53 bits2frame(input_bits, frame, filename_for_errs, frame_no) | |
54 uint8_t *input_bits, *frame; | |
55 char *filename_for_errs; | |
56 unsigned frame_no; | |
57 { | |
58 uint8_t bits[248], *sp, *dp; | |
59 unsigned nb, byte, mask; | |
60 | |
61 bits[0] = 1; | |
62 bits[1] = 1; | |
63 bits[2] = 0; | |
64 bits[3] = 0; | |
65 bcopy(input_bits, bits + 4, 244); | |
66 sp = bits; | |
67 dp = frame; | |
68 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { | |
69 byte = 0; | |
70 for (mask = 0x80; mask; mask >>= 1) { | |
71 if (*sp > 1) { | |
72 fprintf(stderr, | |
73 "error in %s frame #%u: data bit > 1\n", | |
74 filename_for_errs, frame_no); | |
75 exit(1); | |
76 } | |
77 if (*sp) | |
78 byte |= mask; | |
79 sp++; | |
80 } | |
81 *dp++ = byte; | |
82 } | |
83 } | |
84 | 18 |
85 static void | 19 static void |
86 write_pcm_le(outf, pcm) | 20 write_pcm_le(outf, pcm) |
87 FILE *outf; | 21 FILE *outf; |
88 int16_t *pcm; | 22 int16_t *pcm; |
128 if (!state) { | 62 if (!state) { |
129 perror("EFR_decoder_create()"); | 63 perror("EFR_decoder_create()"); |
130 exit(1); | 64 exit(1); |
131 } | 65 } |
132 for (frame_no = 0; ; frame_no++) { | 66 for (frame_no = 0; ; frame_no++) { |
133 rc = read_input(inf, input_bits, argv[1]); | 67 rc = read_etsi_bits(inf, 0, input_bits, ETSI_DEC_NWORDS, |
68 argv[1]); | |
134 if (!rc) | 69 if (!rc) |
135 break; | 70 break; |
136 if (input_bits[0] > 1) { | 71 if (input_bits[0] > 1) { |
137 fprintf(stderr, "error in %s frame #%u: BFI > 1\n", | 72 fprintf(stderr, "error in %s frame #%u: BFI > 1\n", |
138 argv[1], frame_no); | 73 argv[1], frame_no); |