# HG changeset patch # User Mychaela Falconia # Date 1739440965 0 # Node ID e2d5cad04cbf6ff50acbb898741bccc8504d76d8 # Parent d4979cdbc081c0edb01dff0fceca1eff2b7d0b36 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. diff -r d4979cdbc081 -r e2d5cad04cbf libgsmhr1/rxfe.c --- a/libgsmhr1/rxfe.c Thu Feb 13 09:21:02 2025 +0000 +++ b/libgsmhr1/rxfe.c Thu Feb 13 10:02:45 2025 +0000 @@ -222,7 +222,7 @@ { int i; - memcpy(prm_out, st->saved_frame, sizeof(Shortword) * 4); + memcpy(prm_out, st->cn_r0_lpc, sizeof(Shortword) * 4); prm_out[4] = 1; /* soft interpolation */ prm_out[5] = 0; /* unvoiced mode */ for (i = 0; i < N_SUB; i++) { @@ -276,7 +276,10 @@ if (dtxd_sp) *dtxd_sp = 0; if (frame_class == VALIDSID) - memcpy(st->saved_frame, prm_in, sizeof(Shortword) * 4); + memcpy(st->cn_r0_lpc, prm_in, sizeof(Shortword) * 4); + else + memcpy(st->cn_r0_lpc, st->saved_frame, + sizeof(Shortword) * 4); init_cn_gen(st); cn_output(st, prm_out); break; @@ -284,7 +287,7 @@ if (dtxd_sp) *dtxd_sp = 0; if (frame_class == VALIDSID) - memcpy(st->saved_frame, prm_in, sizeof(Shortword) * 4); + memcpy(st->cn_r0_lpc, prm_in, sizeof(Shortword) * 4); else deco_mode = CNIBFI; /* for interpolation */ st->dtx_bfi_count = 0; @@ -296,11 +299,11 @@ *dtxd_sp = 0; if (st->dtx_muting) { if (fast_cn_muting) - st->saved_frame[0] = 0; + st->cn_r0_lpc[0] = 0; else { - st->saved_frame[0] -= 2; - if (st->saved_frame[0] < 0) - st->saved_frame[0] = 0; + st->cn_r0_lpc[0] -= 2; + if (st->cn_r0_lpc[0] < 0) + st->cn_r0_lpc[0] = 0; } } st->dtx_bfi_count++; diff -r d4979cdbc081 -r e2d5cad04cbf libgsmhr1/rxfe.h --- a/libgsmhr1/rxfe.h Thu Feb 13 09:21:02 2025 +0000 +++ b/libgsmhr1/rxfe.h Thu Feb 13 10:02:45 2025 +0000 @@ -19,6 +19,7 @@ struct gsmhr_rxfe_state { Shortword saved_frame[GSMHR_NUM_PARAMS]; Longword gs_history[GS_HISTORY_SIZE]; + Shortword cn_r0_lpc[4]; Longword cn_prng; Shortword gs_cn_out; uint8_t in_dtx;