From 2fd4fe6aa109c8df50baac465f0393a303a64dd2 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 14 Sep 2018 09:13:36 +0200 Subject: 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 --- src/gsm/gsm0808_utils.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/gsm/libosmogsm.map | 1 + 2 files changed, 44 insertions(+) (limited to 'src') 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; -- cgit v1.2.3