gsm0808: add function to convert AMR S15-S0 to gsm0408 settings

Add a function to convert S0-S15 bits to struct gsm48_multi_rate_conf,
which hold the codec settings for AMR.

Change-Id: I973736273c236eee84decf15868190e339c3fed4
Related: OS#3548
This commit is contained in:
Philipp Maier 2018-09-25 15:57:49 +02:00 committed by Harald Welte
parent b066305016
commit 8515d035ae
5 changed files with 233 additions and 0 deletions

View File

@ -105,6 +105,7 @@ int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch);
int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc,
uint8_t perm_spch);
uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cfg, bool fr);
void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0);
/*! Return 3GPP TS 48.008 3.2.2.49 Current Channel Type 1 from enum gsm_chan_t. */
static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)

View File

@ -1204,6 +1204,47 @@ uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cf
return s15_s0;
}
/*! Determine a GSM 04.08 AMR configuration struct from a set of speech codec
* configuration bits (S0-S15)
* \param[out] cfg AMR configuration in GSM 04.08 format.
* \param[in] s15_s0 configuration bits (S0-S15). */
void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg,
uint16_t s15_s0)
{
memset(cfg, 0, sizeof(*cfg));
/* Strip option bits */
s15_s0 &= 0x00ff;
/* Rate 5,15k must always be present */
cfg->m5_15 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_4_75 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_4_75 & 0xff))
cfg->m4_75 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_5_90 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_5_90 & 0xff))
cfg->m5_90 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_6_70 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_6_70 & 0xff))
cfg->m6_70 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_7_40 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_7_40 & 0xff))
cfg->m7_40 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_7_95 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_7_95 & 0xff))
cfg->m7_95 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_10_2 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_10_2 & 0xff))
cfg->m10_2 = 1;
if ((s15_s0 & GSM0808_SC_CFG_DEFAULT_AMR_12_2 & 0xff) ==
(GSM0808_SC_CFG_DEFAULT_AMR_12_2 & 0xff))
cfg->m12_2 = 1;
cfg->ver = 1;
cfg->icmi = 1;
}
/*! 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().

View File

@ -206,6 +206,7 @@ gsm0808_cell_id_u_name;
gsm0808_chan_type_to_speech_codec;
gsm0808_speech_codec_from_chan_type;
gsm0808_sc_cfg_from_gsm48_mr_cfg;
gsm48_mr_cfg_from_gsm0808_sc_cfg;
gsm0808_speech_codec_type_names;
gsm0808_permitted_speech_names;
gsm0808_chosen_enc_alg_names;

View File

@ -1640,6 +1640,62 @@ static void test_gsm0808_sc_cfg_from_gsm48_mr_cfg(void)
test_gsm0808_sc_cfg_from_gsm48_mr_cfg_single(&cfg);
}
static void test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single(uint16_t s15_s0)
{
struct gsm48_multi_rate_conf cfg;
printf("Input:\n");
printf(" S15-S0 = %04x = 0b" OSMO_BIN_SPEC OSMO_BIN_SPEC "\n", s15_s0,
OSMO_BIN_PRINT(s15_s0 >> 8), OSMO_BIN_PRINT(s15_s0));
gsm48_mr_cfg_from_gsm0808_sc_cfg(&cfg, s15_s0);
printf("Output:\n");
printf(" m4_75= %u smod= %u\n", cfg.m4_75, cfg.smod);
printf(" m5_15= %u spare= %u\n", cfg.m5_15, cfg.spare);
printf(" m5_90= %u icmi= %u\n", cfg.m5_90, cfg.icmi);
printf(" m6_70= %u nscb= %u\n", cfg.m6_70, cfg.nscb);
printf(" m7_40= %u ver= %u\n", cfg.m7_40, cfg.ver);
printf(" m7_95= %u\n", cfg.m7_95);
printf(" m10_2= %u\n", cfg.m10_2);
printf(" m12_2= %u\n", cfg.m12_2);
printf("\n");
}
void test_gsm48_mr_cfg_from_gsm0808_sc_cfg()
{
printf("Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():\n");
/* Only one codec per setting */
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_4_75);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_5_15);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_5_90);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_6_70);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_7_40);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_7_95);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_10_2);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_12_2);
/* Combinations */
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_4_75 | GSM0808_SC_CFG_DEFAULT_AMR_6_70 |
GSM0808_SC_CFG_DEFAULT_AMR_10_2);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_10_2 | GSM0808_SC_CFG_DEFAULT_AMR_12_2 |
GSM0808_SC_CFG_DEFAULT_AMR_7_40);
test_gsm48_mr_cfg_from_gsm0808_sc_cfg_single
(GSM0808_SC_CFG_DEFAULT_AMR_7_95 | GSM0808_SC_CFG_DEFAULT_AMR_12_2);
}
int main(int argc, char **argv)
{
printf("Testing generation of GSM0808 messages\n");
@ -1692,6 +1748,7 @@ int main(int argc, char **argv)
test_gsm0808_enc_dec_cell_id_global();
test_gsm0808_sc_cfg_from_gsm48_mr_cfg();
test_gsm48_mr_cfg_from_gsm0808_sc_cfg();
printf("Done\n");
return EXIT_SUCCESS;

View File

@ -299,4 +299,137 @@ Result (fr):
Result (hr):
S15-S0 = 073f = 0b0000011100111111
Testing gsm48_mr_cfg_from_gsm0808_sc_cfg():
Input:
S15-S0 = ff03 = 0b1111111100000011
Output:
m4_75= 1 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 0
m12_2= 0
Input:
S15-S0 = 0000 = 0b0000000000000000
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 0
m12_2= 0
Input:
S15-S0 = ff06 = 0b1111111100000110
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 1 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 0
m12_2= 0
Input:
S15-S0 = 3e08 = 0b0011111000001000
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 1 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 0
m12_2= 0
Input:
S15-S0 = 0c12 = 0b0000110000010010
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 1 ver= 1
m7_95= 0
m10_2= 0
m12_2= 0
Input:
S15-S0 = c020 = 0b1100000000100000
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 1
m10_2= 0
m12_2= 0
Input:
S15-S0 = 3040 = 0b0011000001000000
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 1
m12_2= 0
Input:
S15-S0 = c082 = 0b1100000010000010
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 0
m12_2= 1
Input:
S15-S0 = ff4b = 0b1111111101001011
Output:
m4_75= 1 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 1 nscb= 0
m7_40= 0 ver= 1
m7_95= 0
m10_2= 1
m12_2= 0
Input:
S15-S0 = fcd2 = 0b1111110011010010
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 1 ver= 1
m7_95= 0
m10_2= 1
m12_2= 1
Input:
S15-S0 = c0a2 = 0b1100000010100010
Output:
m4_75= 0 smod= 0
m5_15= 1 spare= 0
m5_90= 0 icmi= 1
m6_70= 0 nscb= 0
m7_40= 0 ver= 1
m7_95= 1
m10_2= 0
m12_2= 1
Done