FreeCalypso > hg > gsm-codec-lib
annotate hrutil/read-dec.c @ 550:de333989a12b
document gsm[e]fr-decode-tw5[-r] utilities
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Oct 2024 02:16:48 +0000 |
parents | 2d703e1e9107 |
children |
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 |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
3 * GSM-HR *.dec files in either LE or BE format. |
515
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 |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
13 read_dec_frame(inf, big_endian, params, filename_for_errs, frame_no) |
515
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 { |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
19 uint8_t file_bytes[GSMHR_NUM_PARAMS_DEC * 2], *sp; |
515
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 |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
24 cc = fread(file_bytes, 2, GSMHR_NUM_PARAMS_DEC, inf); |
515
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; |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
27 if (cc != GSMHR_NUM_PARAMS_DEC) { |
515
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; |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
33 for (n = 0; n < GSMHR_NUM_PARAMS_DEC; n++) { |
515
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 } |
517
2d703e1e9107
hrutil: implement gsmhr-dec-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
515
diff
changeset
|
41 if (gsmhr_check_decoder_params(params) < 0) { |
515
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 } |