annotate hrutil/read-dec.c @ 581:e2d5cad04cbf

libgsmhr1 RxFE: store CN R0+LPC separately from speech In the original GSM 06.06 code the ECU for speech mode is entirely separate from the CN generator, maintaining separate state. (The main intertie between them is the speech vs CN state variable, distinguishing between speech and CN BFIs, in addition to the CN-specific function of distinguishing between initial and update SIDs.) In the present RxFE implementation I initially thought that we could use the same saved_frame buffer for both ECU and CN, overwriting just the first 4 params (R0 and LPC) when a valid SID comes in. However, I now realize it was a bad idea: the original code has a corner case (long sequence of speech-mode BFIs to put the ECU in state 6, then SID and CN-mode BFIs, then a good speech frame) that would be broken by that buffer reuse approach. We could eliminate this corner case by resetting the ECU state when passing through a CN insertion period, but doing so would needlessly increase the behavioral diffs between GSM 06.06 and our version. Solution: use a separate CN-specific buffer for CN R0+LPC parameters, and match the behavior of GSM 06.06 code in this regard.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Feb 2025 10:02:45 +0000
parents 2d703e1e9107
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
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 }