aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2020-02-06 14:25:01 +0100
committerlaforge <laforge@osmocom.org>2020-04-14 13:22:44 +0000
commit898c9c6af8f55f7c042812255c87223754c4a5ff (patch)
treefad28d0946c7968ddd8dced06d0082f7e90d66ae
parent099c8340edbae163205461f0d8c775dd8c225c69 (diff)
dtx: add decoding for AMR-DTX frames
gsm0503_coding contains AMR decoder functions for HR and FR. Those can only decode AMR payload frames but not amr DTX frames. Lets add functionality to detect DTX frames. Also lets add decoding for SID_UPDATE frames as well as error checking for the SID frame recognition patterns. Related: OS#2978 Change-Id: I2bbdb39ea20461ca08b2e6f1a33532cb55cd5195
-rw-r--r--include/Makefile.am1
-rw-r--r--include/osmocom/coding/gsm0503_amr_dtx.h40
-rw-r--r--include/osmocom/coding/gsm0503_coding.h6
-rw-r--r--src/coding/Makefile.am3
-rw-r--r--src/coding/gsm0503_amr_dtx.c314
-rw-r--r--src/coding/gsm0503_coding.c180
-rw-r--r--src/coding/libosmocoding.map6
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/dtx/dtx_gsm0503_test.c130
-rw-r--r--tests/dtx/dtx_gsm0503_test.ok11
-rw-r--r--tests/testsuite.at6
11 files changed, 702 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index b341ee3c..572c880f 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -90,6 +90,7 @@ nobase_include_HEADERS = \
osmocom/coding/gsm0503_mapping.h \
osmocom/coding/gsm0503_interleaving.h \
osmocom/coding/gsm0503_coding.h \
+ osmocom/coding/gsm0503_amr_dtx.h \
osmocom/gsm/gsm0808.h \
osmocom/gsm/gsm29205.h \
osmocom/gsm/gsm0808_utils.h \
diff --git a/include/osmocom/coding/gsm0503_amr_dtx.h b/include/osmocom/coding/gsm0503_amr_dtx.h
new file mode 100644
index 00000000..f048a6e3
--- /dev/null
+++ b/include/osmocom/coding/gsm0503_amr_dtx.h
@@ -0,0 +1,40 @@
+/*! \file gsm0503_amr_dtx.h
+ * GSM TS 05.03 coding
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include <osmocom/core/defs.h>
+#include <osmocom/core/bits.h>
+
+/*! \addtogroup coding
+ * @{
+ * \file gsm0503_amr_dtx.h */
+
+enum gsm0503_amr_dtx_frames {
+ AMR_OTHER,
+ AFS_SID_FIRST,
+ AFS_SID_UPDATE,
+ AFS_SID_UPDATE_CN,
+ AFS_ONSET,
+ AHS_SID_UPDATE,
+ AHS_SID_UPDATE_CN,
+ AHS_SID_FIRST_P1,
+ AHS_SID_FIRST_P2,
+ AHS_ONSET,
+ AHS_SID_FIRST_INH,
+ AHS_SID_UPDATE_INH,
+};
+
+extern const struct value_string gsm0503_amr_dtx_frame_names[];
+static inline const char *gsm0503_amr_dtx_frame_name(enum gsm0503_amr_dtx_frames frame)
+{
+ return get_value_string(gsm0503_amr_dtx_frame_names, frame);
+}
+
+enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t *ubits);
+enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t *ubits);
+
+/*! @} */
diff --git a/include/osmocom/coding/gsm0503_coding.h b/include/osmocom/coding/gsm0503_coding.h
index 98038f8f..2afa049b 100644
--- a/include/osmocom/coding/gsm0503_coding.h
+++ b/include/osmocom/coding/gsm0503_coding.h
@@ -58,12 +58,18 @@ int gsm0503_tch_afs_encode(ubit_t *bursts, const uint8_t *tch_data, int len,
int gsm0503_tch_afs_decode(uint8_t *tch_data, const sbit_t *bursts,
int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
uint8_t *cmr, int *n_errors, int *n_bits_total);
+int gsm0503_tch_afs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
+ uint8_t *cmr, int *n_errors, int *n_bits_total, uint8_t *dtx);
int gsm0503_tch_ahs_encode(ubit_t *bursts, const uint8_t *tch_data, int len,
int codec_mode_req, uint8_t *codec, int codecs, uint8_t ft, uint8_t cmr);
int gsm0503_tch_ahs_decode(uint8_t *tch_data, const sbit_t *bursts, int odd,
int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
uint8_t *cmr, int *n_errors, int *n_bits_total);
+int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
+ uint8_t *cmr, int *n_errors, int *n_bits_total, uint8_t *dtx);
int gsm0503_rach_ext_encode(ubit_t *burst, uint16_t ra, uint8_t bsic, bool is_11bit);
int gsm0503_rach_encode(ubit_t *burst, const uint8_t *ra, uint8_t bsic) OSMO_DEPRECATED("Use gsm0503_rach_ext_encode() instead");
diff --git a/src/coding/Makefile.am b/src/coding/Makefile.am
index f47fe457..b023668e 100644
--- a/src/coding/Makefile.am
+++ b/src/coding/Makefile.am
@@ -20,7 +20,8 @@ libosmocoding_la_SOURCES = \
gsm0503_mapping.c \
gsm0503_tables.c \
gsm0503_parity.c \
- gsm0503_coding.c
+ gsm0503_coding.c \
+ gsm0503_amr_dtx.c
libosmocoding_la_LDFLAGS = \
$(LTLDFLAGS_OSMOCODING) \
-version-info \
diff --git a/src/coding/gsm0503_amr_dtx.c b/src/coding/gsm0503_amr_dtx.c
new file mode 100644
index 00000000..724cf091
--- /dev/null
+++ b/src/coding/gsm0503_amr_dtx.c
@@ -0,0 +1,314 @@
+/*
+ * (C) 2020 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/conv.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/coding/gsm0503_amr_dtx.h>
+#include <osmocom/coding/gsm0503_parity.h>
+#include <osmocom/gsm/gsm0503.h>
+
+/* See also: 3GPP TS 05.03, chapter 3.10.1.3, 3.10.5.2 Identification marker */
+static const ubit_t id_marker_1[] = { 1, 0, 1, 1, 0, 0, 0, 0, 1 };
+
+/* See also: 3GPP TS 05.03, chapter 3.9.1.3, 3.10.2.2, 3.10.2.2 Identification marker */
+static const ubit_t id_marker_0[] = { 0, 1, 0, 0, 1, 1, 1, 1, 0 };
+
+/* See also: 3GPP TS 05.03, chapter 3.9 Adaptive multi rate speech channel at full rate (TCH/AFS) */
+static const ubit_t codec_mode_1_sid[] = { 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0 };
+static const ubit_t codec_mode_2_sid[] = { 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0 };
+static const ubit_t codec_mode_3_sid[] = { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
+static const ubit_t codec_mode_4_sid[] = { 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1 };
+
+const struct value_string gsm0503_amr_dtx_frame_names[] = {
+ { AFS_SID_FIRST, "AFS_SID_FIRST" },
+ { AFS_SID_UPDATE, "AFS_SID_UPDATE" },
+ { AFS_ONSET, "AFS_ONSET" },
+ { AHS_SID_UPDATE, "AHS_SID_UPDATE" },
+ { AHS_SID_FIRST_P1, "AHS_SID_FIRST_P1" },
+ { AHS_SID_FIRST_P2, "AHS_SID_FIRST_P2" },
+ { AHS_ONSET, "AHS_ONSET" },
+ { AHS_SID_FIRST_INH, "AHS_SID_FIRST_INH" },
+ { AHS_SID_UPDATE_INH, "AHS_SID_UPDATE_INH" },
+ { AMR_OTHER, "NON DTX FRAME (OTHER)" },
+ { 0, NULL }
+};
+
+static bool detect_afs_id_marker(int *n_errors, int *n_bits_total, const ubit_t * ubits, uint8_t offset, uint8_t count,
+ const ubit_t * id_marker, uint8_t id_marker_len)
+{
+ unsigned int i, k;
+ unsigned int id_bit_nr = 0;
+ int errors = 0;
+ int bits = 0;
+
+ /* Override coded in-band data */
+ ubits += offset;
+
+ /* Check for identification marker bits */
+ for (i = 0; i < count; i++) {
+ for (k = 0; k < 4; k++) {
+ if (id_marker[id_bit_nr % id_marker_len] != *ubits)
+ errors++;
+ id_bit_nr++;
+ ubits++;
+ bits++;
+ }
+
+ /* Jump to the next block of 4 bits */
+ ubits += 4;
+ }
+
+ *n_errors = errors;
+ *n_bits_total = bits;
+
+ /* Tolerate up to 1/8 errornous bits */
+ return *n_errors < *n_bits_total / 8;
+}
+
+static bool detect_ahs_id_marker(int *n_errors, int *n_bits_total, const ubit_t * ubits, const ubit_t * id_marker)
+{
+ unsigned int i, k;
+ int errors = 0;
+ int bits = 0;
+
+ /* Override coded in-band data */
+ ubits += 16;
+
+ /* Check first identification marker bits (23*9 bits) */
+ for (i = 0; i < 23; i++) {
+ for (k = 0; k < 9; k++) {
+ if (id_marker[k] != *ubits)
+ errors++;
+ ubits++;
+ bits++;
+ }
+ }
+
+ /* Check remaining identification marker bits (5 bits) */
+ for (k = 0; k < 5; k++) {
+ if (id_marker[k] != *ubits)
+ errors++;
+ ubits++;
+ bits++;
+ }
+
+ *n_errors = errors;
+ *n_bits_total = bits;
+
+ /* Tolerate up to 1/8 errornous bits */
+ return *n_errors < *n_bits_total / 8;
+}
+
+static bool detect_interleaved_ahs_id_marker(int *n_errors, int *n_bits_total, const ubit_t * ubits, uint8_t offset,
+ uint8_t n_bits, const ubit_t * id_marker, uint8_t id_marker_len)
+{
+ unsigned int i, k;
+ int errors = 0;
+ int bits = 0;
+ uint8_t full_rounds = n_bits / id_marker_len;
+ uint8_t remainder = n_bits % id_marker_len;
+
+ /* Override coded in-band data */
+ ubits += offset;
+
+ /* Check first identification marker bits (23*9 bits) */
+ for (i = 0; i < full_rounds; i++) {
+ for (k = 0; k < id_marker_len; k++) {
+ if (id_marker[k] != *ubits)
+ errors++;
+ ubits += 2;
+ bits++;
+ }
+ }
+
+ /* Check remaining identification marker bits (5 bits) */
+ for (k = 0; k < remainder; k++) {
+ if (id_marker[k] != *ubits)
+ errors++;
+ ubits += 2;
+ bits++;
+ }
+
+ *n_errors = errors;
+ *n_bits_total = bits;
+
+ /* Tolerate up to 1/8 errornous bits */
+ return *n_errors < *n_bits_total / 8;
+}
+
+/* Detect a an FR AMR SID_FIRST frame by its identifcation marker */
+static bool detect_afs_sid_first(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ return detect_afs_id_marker(n_errors, n_bits_total, ubits, 32, 53, id_marker_0, 9);
+}
+
+/* Detect an FR AMR SID_FIRST frame by its identification marker */
+static bool detect_afs_sid_update(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ return detect_afs_id_marker(n_errors, n_bits_total, ubits, 36, 53, id_marker_0, 9);
+}
+
+/* Detect an FR AMR SID_FIRST frame by its repeating coded inband data */
+static bool detect_afs_onset(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ bool rc;
+
+ rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_1_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_2_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_3_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_4_sid, 16);
+ if (rc)
+ return true;
+
+ return false;
+}
+
+/* Detect an HR AMR SID UPDATE frame by its identification marker */
+static bool detect_ahs_sid_update(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ return detect_ahs_id_marker(n_errors, n_bits_total, ubits, id_marker_1);
+}
+
+/* Detect an HR AMR SID FIRST (part 1) frame by its identification marker */
+static bool detect_ahs_sid_first_p1(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ return detect_ahs_id_marker(n_errors, n_bits_total, ubits, id_marker_0);
+}
+
+/* Detect an HR AMR SID FIRST (part 2) frame by its repeating coded inband data */
+static bool detect_ahs_sid_first_p2(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ bool rc;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_1_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_2_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_3_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_4_sid, 16);
+ if (rc)
+ return true;
+
+ return false;
+}
+
+/* Detect an HR AMR ONSET frame by its repeating coded inband data */
+static bool detect_ahs_onset(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ bool rc;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_1_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_2_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_3_sid, 16);
+ if (rc)
+ return true;
+
+ rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_4_sid, 16);
+ if (rc)
+ return true;
+
+ return false;
+}
+
+/* Detect an HR AMR SID FIRST INHIBIT frame by its identification marker */
+static bool detect_ahs_sid_first_inh(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ return detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 33, 212, id_marker_1, 9);
+}
+
+/* Detect an HR AMR SID UPDATE INHIBIT frame by its identification marker */
+static bool detect_ahs_sid_update_inh(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ return detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 33, 212, id_marker_0, 9);
+}
+
+/*! Detect FR AMR DTX frame in unmapped, deinterleaved frame bits.
+ * \param[in] ubits input bits (456 bit).
+ * \param[out] n_errors number of errornous bits.
+ * \param[out] n_bits_total number of checked bits.
+ * \returns dtx frame type. */
+enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ if (detect_afs_sid_first(n_errors, n_bits_total, ubits))
+ return AFS_SID_FIRST;
+ if (detect_afs_sid_update(n_errors, n_bits_total, ubits))
+ return AFS_SID_UPDATE;
+ if (detect_afs_onset(n_errors, n_bits_total, ubits))
+ return AFS_ONSET;
+
+ *n_errors = 0;
+ *n_bits_total = 0;
+ return AMR_OTHER;
+}
+
+/*! Detect HR AMR DTX frame in unmapped, deinterleaved frame bits.
+ * \param[in] ubits input bits (456 bit).
+ * \param[out] n_errors number of errornous bits.
+ * \param[out] n_bits_total number of checked bits.
+ * \returns dtx frame type, */
+enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t * ubits)
+{
+ if (detect_ahs_sid_update(n_errors, n_bits_total, ubits))
+ return AHS_SID_UPDATE;
+ if (detect_ahs_sid_first_inh(n_errors, n_bits_total, ubits))
+ return AHS_SID_FIRST_INH;
+ if (detect_ahs_sid_update_inh(n_errors, n_bits_total, ubits))
+ return AHS_SID_UPDATE_INH;
+ if (detect_ahs_sid_first_p1(n_errors, n_bits_total, ubits))
+ return AHS_SID_FIRST_P1;
+ if (detect_ahs_sid_first_p2(n_errors, n_bits_total, ubits))
+ return AHS_SID_FIRST_P2;
+ if (detect_ahs_onset(n_errors, n_bits_total, ubits))
+ return AHS_ONSET;
+
+ *n_errors = 0;
+ *n_bits_total = 0;
+ return AMR_OTHER;
+}
diff --git a/src/coding/gsm0503_coding.c b/src/coding/gsm0503_coding.c
index 55924330..1bec56ea 100644
--- a/src/coding/gsm0503_coding.c
+++ b/src/coding/gsm0503_coding.c
@@ -47,6 +47,7 @@
#include <osmocom/coding/gsm0503_tables.h>
#include <osmocom/coding/gsm0503_coding.h>
#include <osmocom/coding/gsm0503_parity.h>
+#include <osmocom/coding/gsm0503_amr_dtx.h>
/*! \mainpage libosmocoding Documentation
*
@@ -1635,6 +1636,39 @@ static void tch_amr_disassemble(ubit_t *d_bits, const uint8_t *tch_data, int len
d_bits[i] = (tch_data[j >> 3] >> (7 - (j & 7))) & 1;
}
+/* Append STI and MI bits to the SID_UPDATE frame, see also
+ * 3GPP TS 26.101, chapter 4.2.3 AMR Core Frame with comfort noise bits */
+static void tch_amr_sid_update_append(ubit_t *sid_update, uint8_t sti, uint8_t mi)
+{
+ /* Zero out the space that had been used by the CRC14 */
+ memset(sid_update + 35, 0, 14);
+
+ /* Append STI and MI parameters */
+ sid_update[35] = sti & 1;
+ sid_update[36] = mi & 1;
+ sid_update[37] = mi >> 1 & 1;
+ sid_update[38] = mi >> 2 & 1;
+}
+
+/* Extract a SID UPDATE fram the sbits of an FR AMR frame */
+static void extract_afs_sid_update(sbit_t *sid_update, const sbit_t *sbits)
+{
+
+ unsigned int i;
+
+ sbits += 32;
+
+ for (i = 0; i < 53; i++) {
+ sid_update[0] = sbits[0];
+ sid_update[1] = sbits[1];
+ sid_update[2] = sbits[2];
+ sid_update[3] = sbits[3];
+ sid_update += 4;
+ sbits += 8;
+ }
+
+}
+
/* re-arrange according to TS 05.03 Table 2 (receiver) */
static void tch_fr_d_to_b(ubit_t *b_bits, const ubit_t *d_bits)
{
@@ -2101,10 +2135,37 @@ int gsm0503_tch_afs_decode(uint8_t *tch_data, const sbit_t *bursts,
int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
uint8_t *cmr, int *n_errors, int *n_bits_total)
{
+ return gsm0503_tch_afs_decode_dtx(tch_data, bursts, codec_mode_req,
+ codec, codecs, ft, cmr, n_errors,
+ n_bits_total, NULL);
+}
+
+/*! Perform channel decoding of a TCH/AFS channel according TS 05.03
+ * \param[out] tch_data Codec frame in RTP payload format
+ * \param[in] bursts buffer containing the symbols of 8 bursts
+ * \param[in] codec_mode_req is this CMR (1) or CMC (0)
+ * \param[in] codec array of active codecs (active codec set)
+ * \param[in] codecs number of codecs in \a codec
+ * \param ft Frame Type; Input if \a codec_mode_req = 1, Output * otherwise
+ * \param[out] cmr Output in \a codec_mode_req = 1
+ * \param[out] n_errors Number of detected bit errors
+ * \param[out] n_bits_total Total number of bits
+ * \param[inout] dtx DTX frame type output, previous DTX frame type input
+ * \returns (>=4) length of bytes used in \a tch_data output buffer; ([0,3])
+ * codec out of range; negative on error
+ */
+int gsm0503_tch_afs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
+ uint8_t *cmr, int *n_errors, int *n_bits_total, uint8_t *dtx)
+{
sbit_t iB[912], cB[456], h;
ubit_t d[244], p[6], conv[250];
int i, j, k, best = 0, rv, len, steal = 0, id = 0;
+ ubit_t cBd[456];
*n_errors = 0; *n_bits_total = 0;
+ static ubit_t sid_first_dummy[64] = { 0 };
+ sbit_t sid_update_enc[256];
+ uint8_t dtx_prev;
for (i=0; i<8; i++) {
gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116], &h, i >> 2);
@@ -2123,6 +2184,50 @@ int gsm0503_tch_afs_decode(uint8_t *tch_data, const sbit_t *bursts,
return GSM_MACBLOCK_LEN;
}
+ /* Determine the DTX frame type (SID_UPDATE, ONSET etc...) */
+ if (dtx) {
+ osmo_sbit2ubit(cBd, cB, 456);
+ dtx_prev = *dtx;
+ *dtx = gsm0503_detect_afs_dtx_frame(n_errors, n_bits_total, cBd);
+
+ if (dtx_prev == AFS_SID_UPDATE && *dtx == AMR_OTHER) {
+ /* NOTE: The AFS_SID_UPDATE frame is splitted into
+ * two half rate frames. If the id marker frame
+ * (AFS_SID_UPDATE) is detected the following frame
+ * contains the actual comfort noised data part of
+ * (AFS_SID_UPDATE_CN). */
+ *dtx = AFS_SID_UPDATE_CN;
+
+ extract_afs_sid_update(sid_update_enc, cB);
+ osmo_conv_decode_ber(&gsm0503_tch_axs_sid_update,
+ sid_update_enc, conv, n_errors,
+ n_bits_total);
+ rv = osmo_crc16gen_check_bits(&gsm0503_amr_crc14, conv,
+ 35, conv + 35);
+ if (rv != 0) {
+ /* Error checking CRC14 for an AMR SID_UPDATE frame */
+ return -1;
+ }
+
+ tch_amr_sid_update_append(conv, 1,
+ (codec_mode_req) ? codec[*ft]
+ : codec[id]);
+ tch_amr_reassemble(tch_data, conv, 39);
+ len = 5;
+ goto out;
+ } else if (*dtx == AFS_SID_FIRST) {
+ tch_amr_sid_update_append(sid_first_dummy, 0,
+ (codec_mode_req) ? codec[*ft]
+ : codec[id]);
+ tch_amr_reassemble(tch_data, conv, 39);
+ len = 5;
+ goto out;
+ } else if (*dtx == AFS_ONSET) {
+ len = 0;
+ goto out;
+ }
+ }
+
for (i = 0; i < 4; i++) {
for (j = 0, k = 0; j < 8; j++)
k += abs(((int)gsm0503_afs_ic_sbit[i][j]) - ((int)cB[j]));
@@ -2283,6 +2388,7 @@ int gsm0503_tch_afs_decode(uint8_t *tch_data, const sbit_t *bursts,
return -1;
}
+out:
/* Change codec request / indication, if frame is valid */
if (codec_mode_req)
*cmr = id;
@@ -2480,9 +2586,36 @@ int gsm0503_tch_ahs_decode(uint8_t *tch_data, const sbit_t *bursts, int odd,
int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
uint8_t *cmr, int *n_errors, int *n_bits_total)
{
+ return gsm0503_tch_ahs_decode_dtx(tch_data, bursts, odd, codec_mode_req,
+ codec, codecs, ft, cmr, n_errors,
+ n_bits_total, NULL);
+}
+
+/*! Perform channel decoding of a TCH/AFS channel according TS 05.03
+ * \param[out] tch_data Codec frame in RTP payload format
+ * \param[in] bursts buffer containing the symbols of 8 bursts
+ * \param[in] odd Is this an odd (1) or even (0) frame number?
+ * \param[in] codec_mode_req is this CMR (1) or CMC (0)
+ * \param[in] codec array of active codecs (active codec set)
+ * \param[in] codecs number of codecs in \a codec
+ * \param ft Frame Type; Input if \a codec_mode_req = 1, Output * otherwise
+ * \param[out] cmr Output in \a codec_mode_req = 1
+ * \param[out] n_errors Number of detected bit errors
+ * \param[out] n_bits_total Total number of bits
+ * \param[inout] dtx DTX frame type output, previous DTX frame type input
+ * \returns (>=4) length of bytes used in \a tch_data output buffer; ([0,3])
+ * codec out of range; negative on error
+ */
+int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
+ uint8_t *cmr, int *n_errors, int *n_bits_total, uint8_t *dtx)
+{
sbit_t iB[912], cB[456], h;
ubit_t d[244], p[6], conv[135];
int i, j, k, best = 0, rv, len, steal = 0, id = 0;
+ ubit_t cBd[456];
+ static ubit_t sid_first_dummy[64] = { 0 };
+ uint8_t dtx_prev;
/* only unmap the stealing bits */
if (!odd) {
@@ -2526,6 +2659,52 @@ int gsm0503_tch_ahs_decode(uint8_t *tch_data, const sbit_t *bursts, int odd,
gsm0503_tch_hr_deinterleave(cB, iB);
+ /* Determine the DTX frame type (SID_UPDATE, ONSET etc...) */
+ if (dtx) {
+ osmo_sbit2ubit(cBd, cB, 456);
+ dtx_prev = *dtx;
+ *dtx = gsm0503_detect_ahs_dtx_frame(n_errors, n_bits_total, cBd);
+
+ if (dtx_prev == AHS_SID_UPDATE && *dtx == 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). */
+ *dtx = AHS_SID_UPDATE_CN;
+
+ osmo_conv_decode_ber(&gsm0503_tch_axs_sid_update,
+ cB + 16, conv, n_errors,
+ n_bits_total);
+ rv = osmo_crc16gen_check_bits(&gsm0503_amr_crc14, conv,
+ 35, conv + 35);
+ if (rv != 0) {
+ /* Error checking CRC14 for an AMR SID_UPDATE frame */
+ return -1;
+ }
+
+ tch_amr_sid_update_append(conv, 1,
+ (codec_mode_req) ? codec[*ft]
+ : codec[id]);
+ tch_amr_reassemble(tch_data, conv, 39);
+ len = 5;
+ goto out;
+ } else if (*dtx == AHS_SID_FIRST_P2) {
+ tch_amr_sid_update_append(sid_first_dummy, 0,
+ (codec_mode_req) ? codec[*ft]
+ : codec[id]);
+ tch_amr_reassemble(tch_data, sid_first_dummy, 39);
+ len = 5;
+ goto out;
+ } else if (*dtx == AHS_SID_UPDATE || *dtx == AHS_ONSET
+ || *dtx == AHS_SID_FIRST_INH
+ || *dtx == AHS_SID_UPDATE_INH
+ || *dtx == AHS_SID_FIRST_P1) {
+ len = 0;
+ goto out;
+ }
+ }
+
for (i = 0; i < 4; i++) {
for (j = 0, k = 0; j < 4; j++)
k += abs(((int)gsm0503_ahs_ic_sbit[i][j]) - ((int)cB[j]));
@@ -2670,6 +2849,7 @@ int gsm0503_tch_ahs_decode(uint8_t *tch_data, const sbit_t *bursts, int odd,
return -1;
}
+out:
/* Change codec request / indication, if frame is valid */
if (codec_mode_req)
*cmr = id;
diff --git a/src/coding/libosmocoding.map b/src/coding/libosmocoding.map
index 7f88111f..325b6d80 100644
--- a/src/coding/libosmocoding.map
+++ b/src/coding/libosmocoding.map
@@ -107,8 +107,10 @@ gsm0503_tch_hr_encode;
gsm0503_tch_hr_decode;
gsm0503_tch_afs_encode;
gsm0503_tch_afs_decode;
+gsm0503_tch_afs_decode_dtx;
gsm0503_tch_ahs_encode;
gsm0503_tch_ahs_decode;
+gsm0503_tch_ahs_decode_dtx;
gsm0503_rach_ext_encode;
gsm0503_rach_ext_decode;
gsm0503_rach_ext_decode_ber;
@@ -117,6 +119,10 @@ gsm0503_rach_decode;
gsm0503_rach_decode_ber;
gsm0503_sch_encode;
gsm0503_sch_decode;
+gsm0503_amr_dtx_frame_names;
+gsm0503_amr_dtx_frame_name;
+gsm0503_detect_afs_dtx_frame;
+gsm0503_detect_ahs_dtx_frame;
local: *;
};
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bf7017b1..0d0327a3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -34,6 +34,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
use_count/use_count_test \
context/context_test \
gsm0502/gsm0502_test \
+ dtx/dtx_gsm0503_test \
$(NULL)
if ENABLE_MSGFILE
@@ -114,6 +115,10 @@ conv_conv_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libgsmint.la
gsm0502_gsm0502_test_SOURCES = gsm0502/gsm0502_test.c
gsm0502_gsm0502_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la
+dtx_dtx_gsm0503_test_SOURCES = dtx/dtx_gsm0503_test.c
+dtx_dtx_gsm0503_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la \
+ $(top_builddir)/src/coding/libosmocoding.la
+
conv_conv_gsm0503_test_SOURCES = conv/conv_gsm0503_test.c conv/conv.c conv/gsm0503_test_vectors.c
conv_conv_gsm0503_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libgsmint.la
conv_conv_gsm0503_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tests/conv
@@ -339,6 +344,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
use_count/use_count_test.ok use_count/use_count_test.err \
context/context_test.ok \
gsm0502/gsm0502_test.ok \
+ dtx/dtx_gsm0503_test.ok \
exec/exec_test.ok exec/exec_test.err \
$(NULL)
diff --git a/tests/dtx/dtx_gsm0503_test.c b/tests/dtx/dtx_gsm0503_test.c
new file mode 100644
index 00000000..f3003133
--- /dev/null
+++ b/tests/dtx/dtx_gsm0503_test.c
@@ -0,0 +1,130 @@
+/*
+ * (C) 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * Author: Philipp Maier <pmaier@sysmocom.de>
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/coding/gsm0503_amr_dtx.h>
+
+char sample_afs_sid_frame[] =
+ {
+"111111110000000011001100101010100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001"
+};
+
+char sample_afs_sid_update_frame[] =
+ {
+"111111110000000011001100101010100000010000001111111100101011011110001001000000110111110000001001011111101111010011001111100000101000011111001001111100110111110011111001001111101100010001001111000000100100011100111001100000111000110000111001010011101111010011111111010000101100011100111001111100110111110011111001110011101000010010001111110000100000011111001001011100110011110010111001101111100011010001111111001100100100011111111001000000110000110000001001"
+};
+
+char sample_afs_onset_frame[] =
+ {
+"111111110000000011001100101010100000111100000000111111000100101000111111100000000111110010001010001111110100000011111100111110100100111111000000110011001011101001001111011100001011110000001010010011111100000000111100111110101000111110110000111111000000101011111111010000001100110000111010111111111000000010111100000010100100111100110000100011001000101000111111101100001011110000111010011111110011000010111100101110101100111111000000010011001111101000001111"
+};
+
+char sample_ahs_sid_update_frame[] =
+ {
+"111100001100101010110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110100011001000011010000000000000001111010010000000000001000000000010110000000011001000000000000000100000101000000000000000001010100000010010000000000010000111110001110110110011001101000000000100100011001000001010000100100000000011"
+};
+
+char sample_ahs_sid_first_p1_frame[] =
+ {
+"111100001100101001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001001011010110001101100101001110001111001110100110010000111101110110110000100100011111001001110000011110110001010010101100001010100000111101110110001010000111110001110110110011001101001111000011101001010011100011000111010110000011"
+};
+
+char sample_ahs_sid_first_p2_frame[] =
+ {
+"111110100100000010100000110111001110101100000100101001011101100011101010010000001010010010001100101010100100010111110101110011011110101000010100111000001001110111101110010101001110000010001101101011110000000011100100110110011111100011001000001101100101001110001111001110100110010000111101110110110000100100011111001001110000011110110001010010101100001010100000111101110110001010000111110001110110110011001101001111000011101001010011100011000111010110000011"
+};
+
+char sample_ahs_onset_frame[] =
+ {
+"111101011000101001010000111001000111011110000000011110001110010011011111100000101101101001101110011111010000000001010010110001101101110100000010011110101100010001011101101010000111100011101100111101011010100011110010110001001111100011001000011010000000000000001010010010000000000001000000000000100000000011001000000000000000100000101000000000000000010010000101010010000000000010101100111110101000110110011001000000000100100011001000001010000100100000001100"
+};
+
+char sample_sid_first_inh_frame[] =
+ {
+"xBxBxBxBxBxBxBxBxBxBxBxBxBxBxBxBx1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0"
+};
+
+char sample_sid_update_inh_frame[] =
+ {
+"xBxBxBxBxBxBxBxBxBxBxBxBxBxBxBxBx0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1"
+};
+
+unsigned int string_to_ubit(ubit_t * ubits, char *string)
+{
+ unsigned int len;
+ unsigned int i;
+
+ len = strlen(string);
+
+ for (i = 0; i < len; i++) {
+ ubits[i] = string[i] & 1;
+ }
+
+ return len;
+}
+
+void test_gsm0503_detect_afs_dtx_frame(char *string)
+{
+ ubit_t ubits[512];
+ uint8_t dtx_frame_type;
+ int n_errors;
+ int n_bits_total;
+
+ string_to_ubit(ubits, string);
+ dtx_frame_type = gsm0503_detect_afs_dtx_frame(&n_errors, &n_bits_total, ubits);
+ printf(" ==> %s, n_errors=%i, n_bits_total=%i\n", gsm0503_amr_dtx_frame_name(dtx_frame_type),
+ n_errors, n_bits_total);
+}
+
+void test_gsm0503_detect_ahs_dtx_frame(char *string)
+{
+ ubit_t ubits[512];
+ uint8_t dtx_frame_type;
+ int n_errors;
+ int n_bits_total;
+
+ string_to_ubit(ubits, string);
+ dtx_frame_type = gsm0503_detect_ahs_dtx_frame(&n_errors, &n_bits_total, ubits);
+ printf(" ==> %s, n_errors=%i, n_bits_total=%i\n", gsm0503_amr_dtx_frame_name(dtx_frame_type),
+ n_errors, n_bits_total);
+}
+
+int main(int argc, char **argv)
+{
+ printf("FR AMR DTX FRAMES:\n");
+ test_gsm0503_detect_afs_dtx_frame(sample_afs_sid_frame);
+ test_gsm0503_detect_afs_dtx_frame(sample_afs_sid_update_frame);
+ test_gsm0503_detect_afs_dtx_frame(sample_afs_onset_frame);
+ printf("HR AMR DTX FRAMES:\n");
+ test_gsm0503_detect_ahs_dtx_frame(sample_ahs_sid_update_frame);
+ test_gsm0503_detect_ahs_dtx_frame(sample_ahs_sid_first_p1_frame);
+ test_gsm0503_detect_ahs_dtx_frame(sample_ahs_sid_first_p2_frame);
+ test_gsm0503_detect_ahs_dtx_frame(sample_ahs_onset_frame);
+ test_gsm0503_detect_ahs_dtx_frame(sample_sid_first_inh_frame);
+ test_gsm0503_detect_ahs_dtx_frame(sample_sid_update_inh_frame);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/dtx/dtx_gsm0503_test.ok b/tests/dtx/dtx_gsm0503_test.ok
new file mode 100644
index 00000000..a95a18bb
--- /dev/null
+++ b/tests/dtx/dtx_gsm0503_test.ok
@@ -0,0 +1,11 @@
+FR AMR DTX FRAMES:
+ ==> AFS_SID_FIRST, n_errors=0, n_bits_total=212
+ ==> AFS_SID_UPDATE, n_errors=0, n_bits_total=212
+ ==> AFS_ONSET, n_errors=0, n_bits_total=228
+HR AMR DTX FRAMES:
+ ==> AHS_SID_UPDATE, n_errors=0, n_bits_total=212
+ ==> AHS_SID_FIRST_P1, n_errors=0, n_bits_total=212
+ ==> AHS_SID_FIRST_P2, n_errors=0, n_bits_total=114
+ ==> AHS_ONSET, n_errors=0, n_bits_total=114
+ ==> AHS_SID_FIRST_INH, n_errors=0, n_bits_total=212
+ ==> AHS_SID_UPDATE_INH, n_errors=0, n_bits_total=212
diff --git a/tests/testsuite.at b/tests/testsuite.at
index cb83ab91..bab57309 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -132,6 +132,12 @@ cat $abs_srcdir/gsm0502/gsm0502_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/gsm0502/gsm0502_test], [0], [expout], [ignore])
AT_CLEANUP
+AT_SETUP([dtx])
+AT_KEYWORDS([dtx])
+cat $abs_srcdir/dtx/dtx_gsm0503_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/dtx/dtx_gsm0503_test], [0], [expout], [ignore])
+AT_CLEANUP
+
AT_SETUP([gsm0808])
AT_KEYWORDS([gsm0808])
cat $abs_srcdir/gsm0808/gsm0808_test.ok > expout