view libgsmhr1/paramval_common.c @ 522:4d2cccaeb4a7

libtest: implement TW-TS-005 reader function Spec reference: https://www.freecalypso.org/specs/tw-ts-005-v010002.txt
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 03:08:47 +0000
parents 4f0ab833bec0
children
line wrap: on
line source

/*
 * The function implemented in this module examines an array of 18 codec
 * parameters in the int16_t representation used in this library, and checks
 * if the unused upper bits of each int16_t word are cleared as they should be.
 * This function, or higher-level wrappers around it, should be used when
 * reading from ETSI-format *.cod and *.dec files, to guard against reading
 * garbage or wrong endian.
 */

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

int gsmhr_check_common_params(const int16_t *params)
{
	/* common parameters for all modes */
	if (params[0] & 0xFFE0)
		return -1;
	if (params[1] & 0xF800)
		return -1;
	if (params[2] & 0xFE00)
		return -1;
	if (params[3] & 0xFF00)
		return -1;
	if (params[4] & 0xFFFE)
		return -1;
	if (params[5] & 0xFFFC)
		return -1;
	if (params[5]) {
		/* voiced modes */
		/* subframe 1 */
		if (params[6] & 0xFF00)
			return -1;
		if (params[7] & 0xFE00)
			return -1;
		if (params[8] & 0xFFE0)
			return -1;
		/* subframe 2 */
		if (params[9] & 0xFFF0)
			return -1;
		if (params[10] & 0xFE00)
			return -1;
		if (params[11] & 0xFFE0)
			return -1;
		/* subframe 3 */
		if (params[12] & 0xFFF0)
			return -1;
		if (params[13] & 0xFE00)
			return -1;
		if (params[14] & 0xFFE0)
			return -1;
		/* subframe 4 */
		if (params[15] & 0xFFF0)
			return -1;
		if (params[16] & 0xFE00)
			return -1;
		if (params[17] & 0xFFE0)
			return -1;
	} else {
		/* unvoiced mode */
		/* subframe 1 */
		if (params[6] & 0xFF80)
			return -1;
		if (params[7] & 0xFF80)
			return -1;
		if (params[8] & 0xFFE0)
			return -1;
		/* subframe 2 */
		if (params[9] & 0xFF80)
			return -1;
		if (params[10] & 0xFF80)
			return -1;
		if (params[11] & 0xFFE0)
			return -1;
		/* subframe 3 */
		if (params[12] & 0xFF80)
			return -1;
		if (params[13] & 0xFF80)
			return -1;
		if (params[14] & 0xFFE0)
			return -1;
		/* subframe 4 */
		if (params[15] & 0xFF80)
			return -1;
		if (params[16] & 0xFF80)
			return -1;
		if (params[17] & 0xFFE0)
			return -1;
	}
	return 0;
}