summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2018-09-19 13:40:21 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2018-09-19 14:01:10 +0000
commit5f2eb150742bd793f2f61fb5cfe2b2df707c0093 (patch)
tree08122f798a25f03a2ca29ba001cc25b1534f9bf5 /src
parent28fc078f9cc02b6c731b0d2e5813857d2ec03ea1 (diff)
gsm0808: add function to convert amr gsm0408 setings to gsm0808
Add a function to convert struct gsm48_multi_rate_conf, which holds the codec settings for AMR, to S0-S15 bit representation as defined in 3GPP TS 48.008 3.2.2.49 This resurrects change-id I4e656731b16621736c7a2f4e64d9ce63b1064e98 which was reverted in I9e0d405e303ed86d23703ca6362e958dddb2f861 due to gsm0808_test failing. The test failure is fixed by properly clearing the struct gsm48_multirate_cfg prior to running tests (add memset(0)). Change-Id: Ia782e21c206c15e840226d79b4209d13658ee916 Related: OS#3548
Diffstat (limited to 'src')
-rw-r--r--src/gsm/gsm0808_utils.c43
-rw-r--r--src/gsm/libosmogsm.map1
2 files changed, 44 insertions, 0 deletions
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 73f02341..4b2a5f56 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -1161,6 +1161,49 @@ int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc,
return 0;
}
+/*! Determine a set of AMR speech codec configuration bits (S0-S15) from a
+ * given GSM 04.08 AMR configuration struct.
+ * \param[in] cfg AMR configuration in GSM 04.08 format.
+ * \param[in] hint if the resulting configuration shall be used with a FR or HR TCH.
+ * \returns configuration bits (S0-S15) */
+uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(struct gsm48_multi_rate_conf *cfg,
+ bool fr)
+{
+ uint16_t s15_s0 = 0;
+
+ /* Check each rate bit in the AMR multirate configuration and pick the
+ * matching default configuration as specified in 3GPP TS 28.062,
+ * Table 7.11.3.1.3-2. */
+ if (cfg->m4_75)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_4_75;
+ if (cfg->m5_15)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_5_15;
+ if (cfg->m5_90)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_5_90;
+ if (cfg->m6_70)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_6_70;
+ if (cfg->m7_40)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_7_40;
+ if (cfg->m7_95)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_7_95;
+ if (cfg->m10_2)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_10_2;
+ if (cfg->m12_2)
+ s15_s0 |= GSM0808_SC_CFG_DEFAULT_AMR_12_2;
+
+ /* Note: 3GPP TS 48.008, chapter 3GPP TS 48.008 states that for AMR
+ * some of the configuration bits must be coded as zeros. The applied
+ * bitmask matches the default codec settings. See also the definition
+ * of enum gsm0808_speech_codec_defaults in gsm_08_08.h and
+ * 3GPP TS 28.062, Table 7.11.3.1.3-2. */
+ if (fr)
+ s15_s0 &= GSM0808_SC_CFG_DEFAULT_FR_AMR;
+ else
+ s15_s0 &= GSM0808_SC_CFG_DEFAULT_HR_AMR;
+
+ return s15_s0;
+}
+
/*! Print a human readable name of the cell identifier to the char buffer.
* This is useful both for struct gsm0808_cell_id and struct gsm0808_cell_id_list2.
* See also gsm0808_cell_id_name() and gsm0808_cell_id_list_name().
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 0c40c88c..3d08232c 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -205,6 +205,7 @@ gsm0808_cell_id_discr_names;
gsm0808_cell_id_u_name;
gsm0808_chan_type_to_speech_codec;
gsm0808_speech_codec_from_chan_type;
+gsm0808_sc_cfg_from_gsm48_mr_cfg;
gsm0808_speech_codec_type_names;
gsm0808_permitted_speech_names;
gsm0808_chosen_enc_alg_names;