comparison amrconv/cod-read.c @ 211:78d1a6513393

amrconv: new program amr-cod-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 20 Apr 2023 01:30:46 +0000
parents efrtest/etsi-bit-rd.c@8ed838709897
children 0beafaa0623f
comparison
equal deleted inserted replaced
210:7e490a8efe8a 211:78d1a6513393
1 /*
2 * In this module we implement utility functions for reading ETSI/3GPP
3 * *.cod files (AMR version) in either LE or BE format.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include "amr_defs.h"
10
11 read_cod_bits(inf, big_endian, bitvec, filename_for_errs)
12 FILE *inf;
13 uint8_t *bitvec;
14 char *filename_for_errs;
15 {
16 uint8_t file_bytes[COD_FORMAT_NWORDS * 2], *sp;
17 int cc;
18 unsigned n, upper;
19
20 cc = fread(file_bytes, 2, COD_FORMAT_NWORDS, inf);
21 if (cc == 0)
22 return 0;
23 if (cc != COD_FORMAT_NWORDS) {
24 fprintf(stderr, "error: short read from %s\n",
25 filename_for_errs);
26 exit(1);
27 }
28 sp = file_bytes;
29 for (n = 0; n < COD_FORMAT_NWORDS; n++) {
30 if (big_endian) {
31 upper = sp[0];
32 bitvec[n] = sp[1];
33 } else {
34 bitvec[n] = sp[0];
35 upper = sp[1];
36 }
37 if (upper) {
38 fprintf(stderr,
39 "error in %s: non-zero in what should be %s upper byte\n",
40 filename_for_errs, big_endian ? "BE" : "LE");
41 exit(1);
42 }
43 sp += 2;
44 }
45 return 1;
46 }
47
48 void
49 preen_frame_bits(input_bits, nbits, filename_for_errs, frame_no)
50 uint8_t *input_bits;
51 char *filename_for_errs;
52 unsigned nbits, frame_no;
53 {
54 uint8_t *sp;
55 unsigned nb;
56
57 sp = input_bits;
58 for (nb = 0; nb < nbits; nb++) {
59 if (*sp > 1) {
60 fprintf(stderr, "error in %s frame #%u: data bit > 1\n",
61 filename_for_errs, frame_no);
62 exit(1);
63 }
64 sp++;
65 }
66 }