annotate hrutil/read-cod.c @ 517:2d703e1e9107

hrutil: implement gsmhr-dec-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 08:27:05 +0000
parents bb36ef735f25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
515
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement the utility function for reading ETSI
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * GSM-HR *.cod files in either LE or BE format.
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libgsmhr1/tw_gsmhr.h"
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 read_cod_frame(inf, big_endian, params, filename_for_errs, frame_no)
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 FILE *inf;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int16_t *params;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char *filename_for_errs;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned frame_no;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 uint8_t file_bytes[GSMHR_NUM_PARAMS_ENC * 2], *sp;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int cc;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned n;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 uint16_t val;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cc = fread(file_bytes, 2, GSMHR_NUM_PARAMS_ENC, inf);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (cc == 0)
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return 0;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (cc != GSMHR_NUM_PARAMS_ENC) {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, "error: short read from %s\n",
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 filename_for_errs);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sp = file_bytes;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (n = 0; n < GSMHR_NUM_PARAMS_ENC; n++) {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (big_endian)
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 val = ((uint16_t) sp[0] << 8) | ((uint16_t) sp[1]);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 else
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 val = ((uint16_t) sp[1] << 8) | ((uint16_t) sp[0]);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 params[n] = val;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 sp += 2;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (gsmhr_check_encoder_params(params) < 0) {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr,
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 "error in %s frame #%u: wrong format or wrong endian\n",
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 filename_for_errs, frame_no);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return 1;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }