FreeCalypso > hg > ice1-trau-tester
diff ater8/out_frame.c @ 42:ff94d7fc5891
new program itt-ater-8
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 19:02:42 +0000 |
parents | ater/out_frame.c@bacc590ec839 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ater8/out_frame.c Fri Aug 30 19:02:42 2024 +0000 @@ -0,0 +1,80 @@ +/* + * Here we implement our TRAU-UL bit filling function for HRv1 8 kbit/s format. + * + * This code is based (very loosely) on trau_rtp_conv.c in libosmo-abis. + */ + +#include <stdint.h> +#include <stdbool.h> +#include <string.h> + +#include <osmocom/core/bits.h> +#include <osmocom/core/crc8gen.h> +#include <osmocom/core/utils.h> +#include <osmocom/trau/trau_frame.h> +#include "../libhr/tw_gsmhr.h" + +#include "out_frame.h" + +/* + * EFR TRAU parity (also used for HR) + * + * g(x) = x^3 + x^1 + 1 + */ +static const struct osmo_crc8gen_code gsm0860_efr_crc3 = { + .bits = 3, + .poly = 0x3, + .init = 0x0, + .remainder = 0x7, +}; + +void trau_frame_from_record(const int16_t *rec, struct osmo_trau_frame *tf, + bool *has_taf) +{ + uint8_t ts101318[GSMHR_FRAME_LEN_RPF]; + int16_t bfi, sid; + + /* payload transformation is straightforward */ + gsmhr_pack_ts101318(rec, ts101318); + osmo_pbit2ubit(tf->d_bits, ts101318, 14 * 8); + osmo_crc8gen_set_bits(&gsm0860_efr_crc3, tf->d_bits, 44, tf->crc_bits); + + /* transformation of metadata flags is the messy part */ + bfi = rec[18]; + sid = rec[20]; + switch (sid) { + case 0: + if (bfi) { + tf->xc_bits[1] = 1; + tf->xc_bits[2] = 1; + *has_taf = true; + } else { + tf->xc_bits[1] = 0; + tf->xc_bits[2] = 0; + tf->xc_bits[3] = 0; + *has_taf = false; + } + break; + case 1: + tf->xc_bits[1] = 1; + tf->xc_bits[2] = 0; + *has_taf = true; + break; + case 2: + if (bfi) { + tf->xc_bits[1] = 1; + tf->xc_bits[2] = 0; + *has_taf = true; + } else { + tf->xc_bits[1] = 0; + tf->xc_bits[2] = 0; + tf->xc_bits[3] = 1; + *has_taf = false; + } + break; + default: + OSMO_ASSERT(0); + } + /* XC5 is always UFI */ + tf->xc_bits[4] = rec[19]; +}