summaryrefslogtreecommitdiffstats
path: root/src/fmt_ti.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-05-28 10:20:54 +0200
committerHarald Welte <laforge@gnumonks.org>2017-05-28 10:44:06 +0200
commit5912848d2edbf61158ac7edc72c2302649a0d9ed (patch)
treede76a2a48b98730f5cb92af44410e47761d0e61d /src/fmt_ti.c
parent62688b60c29225d557da8844d7259ce3eee962c5 (diff)
prepare gapk for dealing with variable-length frames
The existing architecture was modelled around fixed-length codec frame sizes, which of course fails with multi-rate codecs such as AMR.
Diffstat (limited to 'src/fmt_ti.c')
-rw-r--r--src/fmt_ti.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/fmt_ti.c b/src/fmt_ti.c
index 646c74a..627593c 100644
--- a/src/fmt_ti.c
+++ b/src/fmt_ti.c
@@ -26,6 +26,7 @@
#include <stdint.h>
#include <string.h>
+#include <assert.h>
#include <osmocom/codec/codec.h>
@@ -33,14 +34,17 @@
#include <gapk/formats.h>
#include <gapk/utils.h>
+#define TI_LEN 33
static int
-ti_hr_from_canon(uint8_t *dst, const uint8_t *src)
+ti_hr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
{
int i, voiced;
const uint16_t *bit_mapping;
- memset(dst, 0x00, 33); /* Not even half the bits are written, so we pre-clear */
+ assert(src_len == HR_CANON_LEN);
+
+ memset(dst, 0x00, TI_LEN); /* Not even half the bits are written, so we pre-clear */
voiced = (msb_get_bit(src, 34) << 1) | msb_get_bit(src, 35);
@@ -54,15 +58,17 @@ ti_hr_from_canon(uint8_t *dst, const uint8_t *src)
lsb_put_bit(dst, di, msb_get_bit(src, si));
}
- return 0;
+ return TI_LEN;
}
static int
-ti_hr_to_canon(uint8_t *dst, const uint8_t *src)
+ti_hr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
{
int i, voiced;
const uint16_t *bit_mapping;
+ assert(src_len == TI_LEN);
+
voiced = (msb_get_bit(src, 94) << 1) | msb_get_bit(src, 93);
bit_mapping = voiced ?
@@ -75,7 +81,7 @@ ti_hr_to_canon(uint8_t *dst, const uint8_t *src)
msb_put_bit(dst, di, msb_get_bit(src, si));
}
- return 0;
+ return HR_CANON_LEN;
}
const struct format_desc fmt_ti_hr = {
@@ -84,17 +90,19 @@ const struct format_desc fmt_ti_hr = {
.name = "ti-hr",
.description = "Texas Instrument HR TCH/H buffer format",
- .frame_len = 33,
+ .frame_len = TI_LEN,
.conv_from_canon = ti_hr_from_canon,
.conv_to_canon = ti_hr_to_canon,
};
static int
-ti_fr_from_canon(uint8_t *dst, const uint8_t *src)
+ti_fr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
{
int i;
+ assert(src_len == FR_CANON_LEN);
+
dst[22] = dst[23] = 0x00; /* some bits won't be writter, pre-clear them */
for (i=0; i<260; i++) {
@@ -103,14 +111,16 @@ ti_fr_from_canon(uint8_t *dst, const uint8_t *src)
msb_put_bit(dst, di, msb_get_bit(src, si));
}
- return 0;
+ return TI_LEN;
}
static int
-ti_fr_to_canon(uint8_t *dst, const uint8_t *src)
+ti_fr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
{
int i;
+ assert(src_len == TI_LEN);
+
dst[32] = 0x00; /* last nibble won't written, pre-clear it */
for (i=0; i<260; i++) {
@@ -119,7 +129,7 @@ ti_fr_to_canon(uint8_t *dst, const uint8_t *src)
msb_put_bit(dst, di, msb_get_bit(src, si));
}
- return 0;
+ return FR_CANON_LEN;
}
const struct format_desc fmt_ti_fr = {
@@ -128,17 +138,19 @@ const struct format_desc fmt_ti_fr = {
.name = "ti-fr",
.description = "Texas Instrument FR TCH/F buffer format",
- .frame_len = 33,
+ .frame_len = TI_LEN,
.conv_from_canon = ti_fr_from_canon,
.conv_to_canon = ti_fr_to_canon,
};
static int
-ti_efr_from_canon(uint8_t *dst, const uint8_t *src)
+ti_efr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
{
int i;
+ assert(src_len == EFR_CANON_LEN);
+
memset(dst, 0x00, 33); /* pre-clear */
for (i=0; i<244; i++) {
@@ -169,14 +181,16 @@ ti_efr_from_canon(uint8_t *dst, const uint8_t *src)
msb_put_bit(dst, di, msb_get_bit(src, si));
}
- return 0;
+ return TI_LEN;
}
static int
-ti_efr_to_canon(uint8_t *dst, const uint8_t *src)
+ti_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
{
int i;
+ assert(src_len == TI_LEN);
+
dst[30] = 0x00; /* last nibble won't written, pre-clear it */
for (i=0; i<244; i++) {
@@ -207,7 +221,7 @@ ti_efr_to_canon(uint8_t *dst, const uint8_t *src)
msb_put_bit(dst, di, msb_get_bit(src, si));
}
- return 0;
+ return EFR_CANON_LEN;
}
const struct format_desc fmt_ti_efr = {
@@ -216,7 +230,7 @@ const struct format_desc fmt_ti_efr = {
.name = "ti-efr",
.description = "Texas Instrument EFR TCH/F buffer format",
- .frame_len = 33,
+ .frame_len = TI_LEN,
.conv_from_canon = ti_efr_from_canon,
.conv_to_canon = ti_efr_to_canon,
};