comparison hrutil/read-dec.c @ 517:2d703e1e9107

hrutil: implement gsmhr-dec-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 08:27:05 +0000
parents hrutil/read-cod.c@bb36ef735f25
children
comparison
equal deleted inserted replaced
516:5353d7652f65 517:2d703e1e9107
1 /*
2 * In this module we implement the utility function for reading ETSI
3 * GSM-HR *.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 "../libgsmhr1/tw_gsmhr.h"
12
13 read_dec_frame(inf, big_endian, params, filename_for_errs, frame_no)
14 FILE *inf;
15 int16_t *params;
16 char *filename_for_errs;
17 unsigned frame_no;
18 {
19 uint8_t file_bytes[GSMHR_NUM_PARAMS_DEC * 2], *sp;
20 int cc;
21 unsigned n;
22 uint16_t val;
23
24 cc = fread(file_bytes, 2, GSMHR_NUM_PARAMS_DEC, inf);
25 if (cc == 0)
26 return 0;
27 if (cc != GSMHR_NUM_PARAMS_DEC) {
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 < GSMHR_NUM_PARAMS_DEC; n++) {
34 if (big_endian)
35 val = ((uint16_t) sp[0] << 8) | ((uint16_t) sp[1]);
36 else
37 val = ((uint16_t) sp[1] << 8) | ((uint16_t) sp[0]);
38 params[n] = val;
39 sp += 2;
40 }
41 if (gsmhr_check_decoder_params(params) < 0) {
42 fprintf(stderr,
43 "error in %s frame #%u: wrong format or wrong endian\n",
44 filename_for_errs, frame_no);
45 exit(1);
46 }
47 return 1;
48 }