view libgsmhr1/pack_frame.c @ 545:b07dba7b8a4f

doc/EFR-library-API: document RTP input wrapper
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 03 Oct 2024 09:26:04 +0000
parents c275e57132f8
children
line wrap: on
line source

/*
 * This module holds our gsmhr_pack_ts101318() function: packing a single
 * GSM-HR codec frame from an array of broken-down parameters into TS 101 318
 * format.
 */

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

void gsmhr_pack_ts101318(const int16_t *params, uint8_t *payload)
{
	uint8_t *c = payload;

	if (params[5]) {
		/* voiced modes */
		*c++ =   ((params[0] & 0x1F) << 3)
		       | ((params[1] >> 8) & 0x7);
		*c++ =   params[1] & 0xFF;
		*c++ =   ((params[2] >> 1) & 0xFF);
		*c++ =   ((params[2] & 0x1) << 7)
		       | ((params[3] >> 1) & 0x7F);
		*c++ =   ((params[3] & 0x1) << 7)
		       | ((params[4] & 0x1) << 6)
		       | ((params[5] & 0x3) << 4)
		       | ((params[6] >> 4) & 0xF);
		*c++ =   ((params[6] & 0xF) << 4)
		       | ((params[7] >> 5) & 0xF);
		*c++ =   ((params[7] & 0x1F) << 3)
		       | ((params[8] >> 2) & 0x7);
		*c++ =   ((params[8] & 0x3) << 6)
		       | ((params[9] & 0xF) << 2)
		       | ((params[10] >> 7) & 0x3);
		*c++ =   ((params[10] & 0x7F) << 1)
		       | ((params[11] >> 4) & 0x1);
		*c++ =   ((params[11] & 0xF) << 4)
		       | (params[12] & 0xF);
		*c++ =   ((params[13] >> 1) & 0xFF);
		*c++ =   ((params[13] & 0x1) << 7)
		       | ((params[14] & 0x1F) << 2)
		       | ((params[15] >> 2) & 0x3);
		*c++ =   ((params[15] & 0x3) << 6)
		       | ((params[16] >> 3) & 0x3F);
		*c++ =   ((params[16] & 0x7) << 5)
		       | (params[17] & 0x1F);
	} else {
		/* unvoiced mode */
		*c++ =   ((params[0] & 0x1F) << 3)
		       | ((params[1] >> 8) & 0x7);
		*c++ =   params[1] & 0xFF;
		*c++ =   ((params[2] >> 1) & 0xFF);
		*c++ =   ((params[2] & 0x1) << 7)
		       | ((params[3] >> 1) & 0x7F);
		*c++ =   ((params[3] & 0x1) << 7)
		       | ((params[4] & 0x1) << 6)
		       | ((params[5] & 0x3) << 4)
		       | ((params[6] >> 3) & 0xF);
		*c++ =   ((params[6] & 0x7) << 5)
		       | ((params[7] >> 2) & 0x1F);
		*c++ =   ((params[7] & 0x3) << 6)
		       | ((params[8] & 0x1F) << 1)
		       | ((params[9] >> 6) & 0x1);
		*c++ =   ((params[9] & 0x3F) << 2)
		       | ((params[10] >> 5) & 0x3);
		*c++ =   ((params[10] & 0x1F) << 3)
		       | ((params[11] >> 2) & 0x7);
		*c++ =   ((params[11] & 0x3) << 6)
		       | ((params[12] >> 1) & 0x3F);
		*c++ =   ((params[12] & 0x1) << 7)
		       | (params[13] & 0x7F);
		*c++ =   ((params[14] & 0x1F) << 3)
		       | ((params[15] >> 4) & 0x7);
		*c++ =   ((params[15] & 0xF) << 4)
		       | ((params[16] >> 3) & 0xF);
		*c++ =   ((params[16] & 0x7) << 5)
		       | (params[17] & 0x1F);
	}
}