From 7790459c8e837bfb4f6c505d3d48e7b822d5ebfe Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 19 May 2022 17:43:57 +0300 Subject: [PATCH] coding: fix decoding of AHS_SID_UPDATE frames (BER ~50%) As was demonstrated in [1], there is a TCH/AHS specific problem in libosmocoding causing unexpected BER ~50% in decoded AHS_SID_UPDATE frames. The reason is that A[H]S_SID_UPDATE employs quite tricky interleaving algorithm, which is different from the algorithm used by normal TCH/AHS speech frames or A[F]S_SID_UPDATE frames. An AHS_SID_UPDATE frame consists of two halves (228 bits each): +---------+--------------------|---------+--------------------+ | in-band | SID marker | in-band | coded data | +---------+--------------------|---------+--------------------+ | 16 bits | 212 bits | 16 bits | 212 bits | The first half contains coded in-band signalling data (16 bits) and the identification marker (212 bits), which allows to detect that it's an AHS_SID_UPDATE. This half is carried by even bits of the first two bursts and odd bits of the last two bursts. The other half also contains the in-band data (16 bits), while the remaining 212 bits contain encoded SID_UPDATE (212 bits). This half is carried by even bits of the last two bursts and odd bits of the first two bursts. Current implementation does not use odd bits of the first two bursts at all, so buffer cB[] in gsm0503_tch_ahs_decode_dtx() contains only 114 out of 228 bits. This patch changes the logic, so that gsm0503_tch_ahs_decode_dtx() would not split AHS_SID_UPDATE onto two frames anymore like its TCH/AFS equivalent does, but attempt to deinterleave the second half and attempt to decode the payload immediately. Change-Id: I8686d895e96fa0e606c1898b6574cc80a8f46983 Related: [1] I434157e2091a306c039123cea08d84bd8533c937 Related: SYS#5853 --- src/coding/gsm0503_coding.c | 36 +++++++++++++++++++++++------------ tests/dtx/dtx_gsm0503_test.ok | 6 +++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/coding/gsm0503_coding.c b/src/coding/gsm0503_coding.c index e81bf0261..715a361ad 100644 --- a/src/coding/gsm0503_coding.c +++ b/src/coding/gsm0503_coding.c @@ -2676,25 +2676,38 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd, /* Determine the DTX frame type (SID_UPDATE, ONSET etc...) */ if (dtx) { - const enum gsm0503_amr_dtx_frames dtx_prev = *dtx; + int n_bits_total_sid; + int n_errors_sid; osmo_sbit2ubit(cBd, cB, 456); *dtx = gsm0503_detect_ahs_dtx_frame(n_errors, n_bits_total, cBd); + /* TODO: detect and handle AHS_SID_UPDATE + AHS_SID_UPDATE_INH */ switch (*dtx) { - case AMR_OTHER: - /* NOTE: The AHS_SID_UPDATE frame is splitted into - * two half rate frames. If the id marker frame - * (AHS_SID_UPDATE) is detected the following frame - * contains the actual comfort noised data part of - * (AHS_SID_UPDATE_CN). */ - if (dtx_prev != AHS_SID_UPDATE) - break; + case AHS_SID_UPDATE: + /* cB[] contains 16 bits of coded in-band data and 212 bits containing + * the identification marker. We need to unmap/deinterleave 114 odd + * bits from the last two blocks, 114 even bits from the first two + * blocks and combine them together. */ + gsm0503_tch_burst_unmap(&iB[0 * 114], &bursts[2 * 116], NULL, 0); + gsm0503_tch_burst_unmap(&iB[1 * 114], &bursts[3 * 116], NULL, 0); + gsm0503_tch_burst_unmap(&iB[2 * 114], &bursts[0 * 116], NULL, 1); + gsm0503_tch_burst_unmap(&iB[3 * 114], &bursts[1 * 116], NULL, 1); + gsm0503_tch_hr_deinterleave(cB, iB); + + /* cB[] is expected to contain 16 bits of coded in-band data and + * 212 bits containing the coded data (53 bits coded at 1/4 rate). */ *dtx = AHS_SID_UPDATE_CN; osmo_conv_decode_ber(&gsm0503_tch_axs_sid_update, - cB + 16, conv, n_errors, - n_bits_total); + cB + 16, conv, &n_errors_sid, + &n_bits_total_sid); + /* gsm0503_detect_ahs_dtx_frame() calculates BER for the marker, + * osmo_conv_decode_ber() calculates BER for the coded data. */ + if (n_errors != NULL) + *n_errors += n_errors_sid; + if (n_bits_total != NULL) + *n_bits_total += n_bits_total_sid; rv = osmo_crc16gen_check_bits(&gsm0503_amr_crc14, conv, 35, conv + 35); if (rv != 0) { @@ -2715,7 +2728,6 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd, tch_amr_reassemble(tch_data, sid_first_dummy, 39); len = 5; goto out; - case AHS_SID_UPDATE: case AHS_ONSET: case AHS_SID_FIRST_INH: case AHS_SID_UPDATE_INH: diff --git a/tests/dtx/dtx_gsm0503_test.ok b/tests/dtx/dtx_gsm0503_test.ok index 750b44013..60f38848a 100644 --- a/tests/dtx/dtx_gsm0503_test.ok +++ b/tests/dtx/dtx_gsm0503_test.ok @@ -17,10 +17,10 @@ Running test_gsm0503_tch_afhs_decode_dtx(at offset=464): testing decoding of AFS Running test_gsm0503_tch_afhs_decode_dtx(at offset=0): testing detection/decoding of AHS_SID_UPDATE ==> gsm0503_tch_ahs_decode_dtx() yields 'AMR_OTHER (audio)' (rc=-1, BER 109/212) Running test_gsm0503_tch_afhs_decode_dtx(at offset=232): testing detection/decoding of AHS_SID_UPDATE - ==> gsm0503_tch_ahs_decode_dtx() yields 'AHS_SID_UPDATE (marker)' (rc=0, BER 0/212) -Running test_gsm0503_tch_afhs_decode_dtx(at offset=464): testing detection/decoding of AHS_SID_UPDATE - ==> gsm0503_tch_ahs_decode_dtx() yields 'AHS_SID_UPDATE_CN (audio)' (rc=5, BER 106/212) + ==> gsm0503_tch_ahs_decode_dtx() yields 'AHS_SID_UPDATE_CN (audio)' (rc=5, BER 0/424) ====> tch_data[] = { 6003ccb270 } +Running test_gsm0503_tch_afhs_decode_dtx(at offset=464): testing detection/decoding of AHS_SID_UPDATE + ==> gsm0503_tch_ahs_decode_dtx() yields 'AMR_OTHER (audio)' (rc=-1, BER 111/212) Running test_gsm0503_tch_afhs_decode_dtx(at offset=0): testing tagging of FACCH/F ==> gsm0503_tch_afs_decode_dtx() yields 'AMR_OTHER (audio)' (rc=-1, BER 456/456) Running test_gsm0503_tch_afhs_decode_dtx(at offset=0): testing tagging of FACCH/H