summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-04-06 16:13:00 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-04-12 10:10:44 -0400
commitd8fb14226f798c9daf948d374a982583cd4ee202 (patch)
tree063f7c4d851a1d4d0cf40e0b6b0b47f88c1f1500 /src
parent93bc64f99ddef02a39c03dfd0725bb41dc93e287 (diff)
Add ubit <-> sbit convertors
Move functions for conversion between soft and unpacked bits to main library as they are generally useful.
Diffstat (limited to 'src')
-rw-r--r--src/bits.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/bits.c b/src/bits.c
index a0a9d9e8..48314af4 100644
--- a/src/bits.c
+++ b/src/bits.c
@@ -61,6 +61,30 @@ int osmo_ubit2pbit(pbit_t *out, const ubit_t *in, unsigned int num_bits)
return outptr - out;
}
+/*! \brief convert unpacked bits to soft bits
+ * \param[out] out output buffer of soft bits
+ * \param[in] in input buffer of unpacked bits
+ * \param[in] num_bits number of bits
+ */
+void osmo_ubit2sbit(sbit_t *out, const ubit_t *in, unsigned int num_bits)
+{
+ unsigned int i;
+ for (i = 0; i < num_bits; i++)
+ out[i] = in[i] ? -127 : 127;
+}
+
+/*! \brief convert soft bits to unpacked bits
+ * \param[out] out output buffer of unpacked bits
+ * \param[in] in input buffer of soft bits
+ * \param[in] num_bits number of bits
+ */
+void osmo_sbit2ubit(ubit_t *out, const sbit_t *in, unsigned int num_bits)
+{
+ unsigned int i;
+ for (i = 0; i < num_bits; i++)
+ out[i] = in[i] < 0;
+}
+
/*! \brief convert packed bits to unpacked bits, return length in bytes
* \param[out] out output buffer of unpacked bits
* \param[in] in input buffer of packed bits