view ater8/out_frame.c @ 51:db39e8855f3d

ater: implement play-d144
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 05:53:38 +0000
parents ff94d7fc5891
children
line wrap: on
line source

/*
 * 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];
}