aboutsummaryrefslogtreecommitdiffstats
path: root/src/gsm/gsm0808_utils.c
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2018-09-14 09:13:36 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2018-09-14 16:24:10 +0200
commit2fd4fe6aa109c8df50baac465f0393a303a64dd2 (patch)
treebe28676b87da9447921c15b56f23597584ef389f /src/gsm/gsm0808_utils.c
parent4b081b1d8862114f59af433b943dea86ce47ac71 (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 Change-Id: I4e656731b16621736c7a2f4e64d9ce63b1064e98 Related: OS#3548
Diffstat (limited to 'src/gsm/gsm0808_utils.c')
-rw-r--r--src/gsm/gsm0808_utils.c43
1 files changed, 43 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().