annotate libtwamr/tseq_in.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 3ce30a95769e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
2 * In this module we implement decoder input conversion from 3GPP
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
3 * test sequence format to our internal struct amr_param_frame.
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdint.h>
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "tw_amr.h"
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "namespace.h"
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "typedef.h"
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "cnst.h"
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
12 #include "bits2prm.h"
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
14 int amr_frame_from_tseq(const uint16_t *cod, int use_rxtype,
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
15 struct amr_param_frame *frame)
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
17 enum RXFrameType rx_type;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
18 int rc;
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
20 if (use_rxtype) {
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
21 if (cod[0] >= RX_N_FRAMETYPES)
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
22 return -1;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
23 rx_type = cod[0];
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
24 } else {
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
25 rc = amr_txtype_to_rxtype(cod[0], &rx_type);
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
26 if (rc < 0)
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
27 return -1;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
28 }
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
29 frame->type = rx_type;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
30 if (rx_type == RX_NO_DATA) {
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
31 frame->mode = 0xFF;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
32 return 0;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
33 }
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
34 if (cod[MAX_SERIAL_SIZE+1] > 7)
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
35 return -2;
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
36 frame->mode = cod[MAX_SERIAL_SIZE+1];
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
37 switch (rx_type) {
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
38 case RX_SPEECH_GOOD:
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
39 case RX_SPEECH_DEGRADED:
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
40 case RX_SPEECH_BAD:
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
41 Bits2prm(frame->mode, cod + 1, frame->param);
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 break;
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
43 case RX_SID_UPDATE:
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
44 case RX_SID_BAD:
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
45 Bits2prm(MRDTX, cod + 1, frame->param);
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 break;
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
429
3ce30a95769e libtwamr: implement test sequence input
Mychaela Falconia <falcon@freecalypso.org>
parents: 420
diff changeset
48 return 0;
420
eced57698c03 libtwamr: implement test sequence output
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }