comparison trau-ul-prep/etsi-bit-rd.c @ 22:8957383370c5

trau-ul-prep: implement efrdec2tsrc
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 22:24:39 +0000
parents
children
comparison
equal deleted inserted replaced
21:453461ad9c15 22:8957383370c5
1 /*
2 * In this module we implement utility functions for reading ETSI *.cod
3 * and *.dec files in either LE or BE format.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <gsm_efr.h>
12 #include "etsi.h"
13
14 read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs)
15 FILE *inf;
16 uint8_t *bitvec;
17 unsigned nwords;
18 char *filename_for_errs;
19 {
20 uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp;
21 int cc;
22 unsigned n, upper;
23
24 cc = fread(file_bytes, 2, nwords, inf);
25 if (cc == 0)
26 return 0;
27 if (cc != nwords) {
28 fprintf(stderr, "error: short read from %s\n",
29 filename_for_errs);
30 exit(1);
31 }
32 sp = file_bytes;
33 for (n = 0; n < nwords; n++) {
34 if (big_endian) {
35 upper = sp[0];
36 bitvec[n] = sp[1];
37 } else {
38 bitvec[n] = sp[0];
39 upper = sp[1];
40 }
41 if (upper) {
42 fprintf(stderr,
43 "error in %s: non-zero in what should be %s upper byte\n",
44 filename_for_errs, big_endian ? "BE" : "LE");
45 exit(1);
46 }
47 sp += 2;
48 }
49 return 1;
50 }
51
52 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 }