This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/18246 )
Change subject: codec: Add functions for AMR s->d bits and d->s bits
......................................................................
codec: Add functions for AMR s->d bits and d->s bits
These functions implement re-ordering of bits as per TS 06.90 / 26.101
based on the already existing tables we've had in libosmocoding.
Change-Id: Ia4ac2aea2e96f9185f082a07ca64dfc5276efb46
---
M include/osmocom/codec/codec.h
M src/codec/gsm690.c
2 files changed, 100 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/46/18246/1
diff --git a/include/osmocom/codec/codec.h b/include/osmocom/codec/codec.h
index 6a1bf9f..cceedc5 100644
--- a/include/osmocom/codec/codec.h
+++ b/include/osmocom/codec/codec.h
@@ -6,6 +6,7 @@
#include <stdbool.h>
#include <osmocom/core/utils.h>
+#include <osmocom/core/bits.h>
/* TS 101318 Chapter 5.1: 260 bits + 4bit sig */
#define GSM_FR_BYTES 33
@@ -51,6 +52,9 @@
AMR_GOOD = 1
};
+int osmo_amr_s_to_d(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
+int osmo_amr_d_to_s(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode);
+
/*! Check if given AMR Frame Type is a speech frame
* \param[in] ft AMR Frame Type
* \returns true if AMR with given Frame Type contains voice, false otherwise
diff --git a/src/codec/gsm690.c b/src/codec/gsm690.c
index 8ab1df1..c01bd5f 100644
--- a/src/codec/gsm690.c
+++ b/src/codec/gsm690.c
@@ -2,6 +2,7 @@
* GSM 06.90 - GSM AMR Codec. */
/*
* (C) 2010 Sylvain Munaut <tnt at 246tNt.com>
+ * (C) 2020 Harald Welte <laforge at gnumonks.org>
*
* All Rights Reserved
*
@@ -29,6 +30,7 @@
#include <stdlib.h>
#include <osmocom/core/utils.h>
+#include <osmocom/core/bits.h>
#include <osmocom/codec/codec.h>
/*
* These table map between the raw encoder parameter output and
@@ -216,6 +218,100 @@
92, 31, 52, 65, 86,
};
+struct ts26101_reorder_table {
+ /*! Table as per TS 26.101 Annex B to compute d-bits from s-bits */
+ const uint16_t *s_to_d;
+ /*! size of table */
+ uint8_t len;
+};
+
+static const struct ts26101_reorder_table ts26101_reorder_tables[8] = {
+ [AMR_4_75] = {
+ .s_to_d = gsm690_4_75_bitorder,
+ .len = ARRAY_SIZE(gsm690_4_75_bitorder),
+ },
+ [AMR_5_15] = {
+ .s_to_d = gsm690_5_15_bitorder,
+ .len = ARRAY_SIZE(gsm690_5_15_bitorder),
+ },
+ [AMR_5_90] = {
+ .s_to_d = gsm690_5_9_bitorder,
+ .len = ARRAY_SIZE(gsm690_5_9_bitorder),
+ },
+ [AMR_6_70] = {
+ .s_to_d = gsm690_6_7_bitorder,
+ .len = ARRAY_SIZE(gsm690_6_7_bitorder),
+ },
+ [AMR_7_40] = {
+ .s_to_d = gsm690_7_4_bitorder,
+ .len = ARRAY_SIZE(gsm690_7_4_bitorder),
+ },
+ [AMR_7_95] = {
+ .s_to_d = gsm690_7_95_bitorder,
+ .len = ARRAY_SIZE(gsm690_7_95_bitorder),
+ },
+ [AMR_10_2] = {
+ .s_to_d = gsm690_10_2_bitorder,
+ .len = ARRAY_SIZE(gsm690_10_2_bitorder),
+ },
+ [AMR_12_2] = {
+ .s_to_d = gsm690_12_2_bitorder,
+ .len = ARRAY_SIZE(gsm690_12_2_bitorder),
+ },
+};
+
+/*! Convert from S-bits (codec output) to d-bits.
+ * \param[out] out user-provided output buffer for generated unpacked d-bits
+ * \param[in] in input buffer for unpacked s-bits
+ * \param[in] n_bits number of bits (in both in and out)
+ * \param[in] AMR mode (0..7) */
+int osmo_amr_s_to_d(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode)
+{
+ const struct ts26101_reorder_table *tbl;
+ int i;
+
+ if (amr_mode >= ARRAY_SIZE(ts26101_reorder_tables))
+ return -ENODEV;
+
+ tbl = &ts26101_reorder_tables[amr_mode];
+
+ if (n_bits >= tbl->len)
+ return -EINVAL;
+
+ for (i = 0; i < n_bits; i++) {
+ uint16_t n = tbl->s_to_d[i];
+ out[i] = in[n];
+ }
+
+ return n_bits;
+}
+
+/*! Convert from d-bits to s-bits (codec input).
+ * \param[out] out user-provided output buffer for generated unpacked s-bits
+ * \param[in] in input buffer for unpacked d-bits
+ * \param[in] n_bits number of bits (in both in and out)
+ * \param[in] AMR mode (0..7) */
+int osmo_amr_d_to_s(ubit_t *out, const ubit_t *in, uint16_t n_bits, enum osmo_amr_type amr_mode)
+{
+ const struct ts26101_reorder_table *tbl;
+ int i;
+
+ if (amr_mode >= ARRAY_SIZE(ts26101_reorder_tables))
+ return -ENODEV;
+
+ tbl = &ts26101_reorder_tables[amr_mode];
+
+ if (n_bits >= tbl->len)
+ return -EINVAL;
+
+ for (i = 0; i < n_bits; i++) {
+ uint16_t n = tbl->s_to_d[i];
+ out[n] = in[i];
+ }
+
+ return n_bits;
+}
+
/* See also RFC 4867 §3.6, Table 1, Column "Total speech bits" */
static const uint8_t amr_len_by_ft[16] = {
12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/18246
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia4ac2aea2e96f9185f082a07ca64dfc5276efb46
Gerrit-Change-Number: 18246
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200514/129d00ae/attachment.htm>