view libgsmfr2/pack_frame2.c @ 542:f2d0f2f15d5f

libgsmefr: add wrapper for TW-TS-001 RTP input
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 28 Sep 2024 06:38:08 +0000
parents bebae251e5ee
children
line wrap: on
line source

/*
 * This module holds our gsmfr_pack_from_array() function: a drop-in
 * replacement for gsm_implode() from classic libgsm.
 */

#include <stdint.h>
#include "tw_gsmfr.h"

#define	GSM_FR_MAGIC	0xD

void gsmfr_pack_from_array(const int16_t *params, uint8_t *frame)
{
	uint8_t *c = frame;
	unsigned sub;

	*c++ =   (GSM_FR_MAGIC << 4)
	       | ((params[0] >> 2) & 0xF);
	*c++ =   ((params[0] & 0x3) << 6)
	       | (params[1] & 0x3F);
	*c++ =   ((params[2] & 0x1F) << 3)
	       | ((params[3] >> 2) & 0x7);
	*c++ =   ((params[3] & 0x3) << 6)
	       | ((params[4] & 0xF) << 2)
	       | ((params[5] >> 2) & 0x3);
	*c++ =   ((params[5] & 0x3) << 6)
	       | ((params[6] & 0x7) << 3)
	       | (params[7] & 0x7);
	params += 8;
	for (sub = 0; sub < 4; sub++) {
		*c++ =   ((params[0] & 0x7F) << 1)
		       | ((params[1] >> 1) & 0x1);
		*c++ =   ((params[1] & 0x1) << 7)
		       | ((params[2] & 0x3) << 5)
		       | ((params[3] >> 1) & 0x1F);
		*c++ =   ((params[3] & 0x1) << 7)
		       | ((params[4] & 0x7) << 4)
		       | ((params[5] & 0x7) << 1)
		       | ((params[6] >> 2) & 0x1);
		*c++ =   ((params[6] & 0x3) << 6)
		       | ((params[7] & 0x7) << 3)
		       | (params[8] & 0x7);
		*c++ =   ((params[9] & 0x7) << 5)
		       | ((params[10] & 0x7) << 2)
		       | ((params[11] >> 1) & 0x3);
		*c++ =   ((params[11] & 0x1) << 7)
		       | ((params[12] & 0x7) << 4)
		       | ((params[13] & 0x7) << 1)
		       | ((params[14] >> 2) & 0x1);
		*c++ =   ((params[14] & 0x3) << 6)
		       | ((params[15] & 0x7) << 3)
		       | (params[16] & 0x7);
		params += 17;
	}
}